This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

H(curl), extract the component of u, u is in H(curl)

+1 vote

If u is in H(curl) in 3D, u is a 3D vector?
If so, how to extract the 3 components of u?
I tried the below method:

u.sub(o), u.sub(1), u.sub(2).

But it's not right.

I will appreciate your any help. Thanks!!!

asked Nov 21, 2016 by fanronghong FEniCS User (1,680 points)

3 Answers

0 votes
 
Best answer

Hi,

I know this problem (u.sub() does not work in Nedlec Space) very well. It results from the definition of the N1curl elements, you have only 6 DOFS per tetrahedral element which belong to magnitudes on the edges, the direction is stored implicitly. My good working workaround is just interpolating on a Lagrange-Space:

mesh = UnitCubeMesh(10, 10, 10)
V_ned = FunctionSpace(mesh, 'N1curl', 1)
V_cg = VectorFunctionSpace(mesh, 'CG', 1)

... solve e.g. "E_ned" on "V_ned" and interpolate afterwards

E_cg = interpolate(E_ned, V_cg)

Now you can use u.sub() to extract single components

E_x = E_cg.sub(0)
E_y = E_cg.sub(1) 
E_Z = E_cg_sub(2)

Hope it is still helpful. If you have further questions about Curl-problems, just write me a PM

answered Dec 12, 2016 by RR FEniCS User (3,330 points)
selected Mar 24, 2017 by fanronghong

Thank you very much! This idea is very good, but it cannot solve my problem, I think.
Actually, my question is how to implement the boundary condition of Maxwell equation, like
n x u = 0, i.e., curl u = 0, in 3D space.
In others example, like finite element function space V = H(curl, 0), somebody implements boundary condition by bc = DirichletBC(V, Constant(0,0,0), boundary). Is this right?

+1 vote

Hi, consider

from dolfin import *
import sys

n = int(sys.argv[1])
mesh = UnitSquareMesh(n, n)
# V = VectorFunctionSpace(mesh, 'CG', 1)
V = FunctionSpace(mesh, 'N1curl', 2)

f = Expression(('x[1]', '-x[0]'), degree=1)
f_e0 = Expression(('x[1]', '0'), degree=1)

u = interpolate(f, V)
e0 = interpolate(Constant((1, 0)), V)

u_e0 = (dot(u, e0)/dot(e0, e0))*e0
u_e0 = project(u_e0, V)

print errornorm(f_e0, u_e0, 'L2') 
answered Nov 22, 2016 by MiroK FEniCS Expert (80,920 points)

Thanks for your help.

I don't understand your code.

How do I get the three components of u, if u is in H(curl) in 3D space?

+1 vote

How about just using u[0], u[1], u[2]? For instance:

from dolfin import *
mesh = UnitCubeMesh(2, 2, 2)
V = FunctionSpace(mesh, 'N1curl', 2)
v = Function(V)
print v[0]
answered Dec 12, 2016 by Marie E. Rognes FEniCS User (5,380 points)
how to implement the boundary condition of Maxwell equation?
...