Import a Function and a mesh, and derive corresponding vector-field

I am quite new with FEniCS so probably my problem is standard but I did not find a solution anywhere else. I am working on a tetrahedral mesh which is stored as a dolfin mesh file mesh.xml.gz. I have another file potential.xml.gz with the dof values derived from a “previous solution” and externally processed, defined on the mesh from a “CR” function space. These are scalar values defined at the barycenter of each facet of the tetrahedron. I would like to visualize the corresponding “gradient” as vector field defined in each Tet in Paraview. I am stuck with the following:

  1. How to import potential.xml.gz? Do I need to create a Function and map the corresponding values per dof? (something like vertex_to_dof_map)
  2. How to derive the corresponding gradient vector field?

Exporting the mesh with the vector field to ParaView is fine. Any help will be welcome

Thank you very much

Allright, so finally I found how to do it. It was not so complicated. I needed just to find the correct function spaces. This is my code to solve the problem

mesh = Mesh("mesh.xml.gz")
F = FunctionSpace(mesh,'CR',1)
f = Function(F,"potential.xml.gz")

G = VectorFunctionSpace(mesh,'DG',0)
g = Function(G)

vf = project(grad(f),g.function_space())

File("vector_field.pvd")<<vf

Thanks again

@Ra_Faniry

first of all hello,
I think i got the same problem as you but i don’t know how to fix it. Do you think you can help me?

Best regards