Cross product in 2D

Dear community,

I would like to solve the problem to find \mathbf{u}\in \Omega \subset \mathbb{R}^2, s.t.

\mathbf{u} \times \mathbf{B} = \mathbf{f}

for a given \mathbf{B} that is normal to \Omega. So I multiply with a testfunction, integrate and get

\int_{\Omega}( \mathbf{u} \times \mathbf{B}) \cdot \mathbf{v} \text{ dx}= \int_{\Omega} \mathbf{f}\cdot \mathbf{v} \text{ dx}.

The UFL cross operator is only defined for 3D vectors, so I tried to implement my own 2D version:

\quad \mathbf{u}: = \begin{bmatrix} u_1\\u_2\\ u_3 \end{bmatrix}, \quad \mathbf{B} := \begin{bmatrix} 0 \\ 0 \\B \end{bmatrix} \quad \Longrightarrow \mathbf{u} \times \mathbf{B} =\begin{bmatrix} u_2B \\ -u_1B \\0 \end{bmatrix}

and in 2D this is just

\mathbf{u} \times \mathbf{B} := \begin{bmatrix} u_2B \\ -u_1B \end{bmatrix}.

I tried to implement that as follows

# mesh and spaces
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'Lagrange', 2)
u = TrialFunction(V)
v = TestFunction(V)

# BCs
u_D = Constant('0')
def boundary(x, on_boundary):
    return on_boundary
bc = DirichletBC(V, u_D, boundary)

# equations
f = Constant('-10')
B = Constant(('0','0','10'))
uxB = ((u[1]*B[2],-u[0]*B[2]))
a = (dot(uxB,v))*dx
L = f*v*dx
u = Function(V)
solve (a==L, u, bc)

plot(mesh)
plot(u)

which results in

---> 17 uxB = ((u[1]*B[2],-u[0]*B[2]))

....

IndexError: tuple index out of range

So apparently, u as a FEniCS trialfunction object is not really a 2D array, or I can not access it as such.
I tried to define uxB as

uxB = ((u[1]*B[2],-u[0]*B[2])).vector()

or as

uxB = as_vector((u[1]*B[2],-u[0]*B[2]))

but still get the same error.

Could someone explain to me, how can one implement such a problem in 2D?

This should be a VectorFunctionSpace if you want u to have an x and y component.

1 Like

Many many thanks, that helped!

But the simple Poisson equation \Delta\mathbf{u} = -\mathbf{f} is also a vector-valued function, for \mathbf{u}, \mathbf{f} \in \Omega \subset \mathbb{R}^2.
Why does one not have to use V = VectorFunctionSpace(...) in this example?

The standard Poisson equation does not require a vector valued solution. We typically would refer to \Delta \vec{u} = \vec{0} as the vector Laplace problem or the vector Poisson problem in the inhomogeneous case.

The vector calculus operations, e.g., \nabla \cdot (\cdot), \nabla (\cdot) and \nabla \times (\cdot) are implicitly defined by their argument. Assuming a Cartesian coordinate system, this is the same with ufl's symbolic algebra via ufl.div, ufl.grad and ufl.curl, respectively. So whether you use a scalar or vector definition for your solution approximation, u_h, ufl will interpret the vector calculus operations implicitly.

1 Like

Thanks, that makes sense!