Is there a way to calculate grad(u), where u is numpy array

Hello,
I am new to using Fenics.
For my work,
I get the dispalcement using
u_ver = u.compute_vertex_values(mesh)
And I also get u_ver_ref from a different software as numpy array
and I want to calculate
grad(u_ver_ref)
How do I convert u_ver_ref a numpy array to be used in grad(u) ?
Thanks

Please note that to do this you must consider multiple things.
If u is not a CG-1 space, there is no map from the mesh-vertices to the degrees of freedom, you then need to go go through the following steps:

  1. Use vertex_to_dof_map to move your input data array into a CG-1 space.
  2. Interpolate/project the data in the CG-1 space into the suitable space (for instance CG-2).
  3. Compute grad(u).

You basically need an inverse process of what is described in: VectorFunctionSpace solution corresponding to mesh - #2 by dokken
(which links to for instance Bitbucket)

1 Like