Updating tensors for each element by deformation gradient

In a dynamic transversely isotropic material problem, I have defined a rotation matrix for each element. I suppose the rotation matrices need to be updated after each time step. But I have problems in doing so. I have defined the matrices like below:

el_r = ufl.TensorElement("DG", mesh.ufl_cell(), 0, shape=(3, 3))
Q_r = fe.fem.FunctionSpace(mesh, el_r)
bs_r = Q_r.dofmap.bs
rotation_matrix = fe.fem.Function(Q_r)

def get_rotation_matrix(x):
    values = np.random((bs_r, x.shape[1]), dtype=np.float64)
    return values


Later for solving I use the function below to update the rotation matrix:

F = ufl.variable(I + ufl.grad(u))             # Deformation gradient
def update_rotation(R, F):  
    new_rotation = ufl.dot(F,R)
    return new_rotation  

But now there are a few problems. Whenever I try to access the matrices with rotation_matrix.x.array[:] I get this error:
AttributeError: ‘Dot’ object has no attribute ‘x’. Did you mean: ‘dx’?
Also, I need to make sure that the new rotation_matrix is orthogonal. So I guess I need to convert the matrices to np.array for that.

I will appreciate any clarification of the procedure here.

Hi Jorosh
The expression ufl.dot(F,R) is a UFL (Unified Form Language) expression and therefore does not possess an attribute .x.array. If you wish to obtain such a vector, it would be necessary to first declare something like,

new_rotation_expression = dolfinx.fem.Expression(new_rotation, Q_r.element.interpolation_points())

then interpolate this expression into a Function from which you can subsequently retrieve the coordinates.

new_rotation_Function = dolfinx.fem.Function(Q_r)

Hi Paul
Thank you for your attention. I’ve got your point, but there is still a problem with the interpolation. It throws:
RuntimeError: Cannot interpolate Expression with Argument.
I searched in UFL documents and there is an ufl.Argument object which is a basis function! I think the fact that I am using deformation gradient in update_rotation function causes this problem. How can I interpolate such an Expression?