Having used FEniCSx to compute a potential field uh
-throughout a 3D mesh, I would like to compute the resulting E-field. Unfortunately, I have not managed to find out how to compute that using DOLFINx v0.9.0. I have used the following code.
from dolfinx import fem
from ufl import grad, dot, dx, TrialFunction, TestFunction
# Load the 3D mesh
msh = get_mesh()
# Define & solve the problem
V = fem.functionspace(msh, ("Lagrange", 1))
u = TrialFunction(V)
v = TestFunction(V)
rho = fem.Constant(msh, default_scalar_type(0))
a = dot(grad(u), grad(v)) * dx
L = rho * v * dx
problem = LinearProblem(a, L, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()
# TODO: The E-field E = -grad(uh) should be computed here
# TODO: Visualize the E-field
I have two questions:
- How to compute the resulting electric field?
- How to visualize it, using e.g. field lines and/or a magnitude visualization, in 3D?
Thanks in advance for your answer.