Using position-dependent body forces

DOLFIN (and DOLFINx) has the function

x = SpatialCoordinate(mesh)
f = as_vector((x[0], x[1], cos(x[2]))

It has for instance been done for cylindrical coordinates by @CastriMik in Scattering from a sphere in the axisymmetric formulation — GSoC 2022 - Expanding FEniCSx electromagnetic demos

or
https://fenicsproject.org/qa/10476/the-weak-formulation-of-spherical-coordinates/
or