Handling Function returns from variational equations

Any reason you can’t use something like

x = ufl.SpatialCoordinate(mesh)
rot = np.pi / 2
mat_x = ufl.cos(rot) * x[0]
mat_y = ufl.sin(rot) * x[1]
mat_z = x[2]
mat = ufl.as_vector((mat_x, mat_y, mat_z))

?

If you can’t use it, please post a complete code (ref Read before posting: How do I get my question answered?), because no-one can run what you wrote, and thus I couldn’t even test the snippet that I sent you.