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

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