Postprocessing Nedelec element solution

Hi,

I am calculating magnetic vector potential in a 3D problem and struggling to obtain the magnetic flux density by doing a simple curl of the solution. I looked around the electromagnetics tutorial but with a possible difference of dimensions I could not spot any difference. Below is a simple MWE that shows what I am trying to do. I am working with dolfixn 0.6.0 installed through conda.

import dolfinx, mpi4py, ufl

mesh = dolfinx.mesh.create_box(mpi4py.MPI.COMM_WORLD, [(0,0,0), (1,1,1)], (20,20,20))

curl_el = ufl.FiniteElement("N1curl", mesh.ufl_cell(), degree=2)
Omega = dolfinx.fem.FunctionSpace(mesh, curl_el)

A_sol = dolfinx.fem.Function(Omega) # imagine this represents the solution

B_sol = dolfinx.fem.Function(Omega)
try:
    B_sol.interpolate(ufl.curl(A_sol)) # does not work
    print("Success!")
except:
    print("Could not calculate the curl")

# interpolate A_sol to a DG space
Omega_dg = dolfinx.fem.VectorFunctionSpace(mesh, ("DG", 2))
B_sol_dg = dolfinx.fem.Function(Omega_dg)
try:
    B_sol_dg.interpolate(ufl.curl(A_sol)) # does not work either
    print("Success!")
except:
    print("Could not calculate the curl")

A_sol_dg = dolfinx.fem.Function(Omega_dg)
A_sol_dg.interpolate(A_sol)
try:
    B_sol_dg.interpolate(ufl.curl(A_sol)) # does not work either
    print("Success!")
except:
    print("Could not calculate the curl")

Your syntax doesn’t make much sense since you’re not compiling the UFL formulation into an Expression. See for example https://github.com/FEniCS/dolfinx/blob/main/python/demo/demo_elasticity.py#L219-L232.

1 Like