Dear community,
I would like to solve the problem to find \mathbf{u}\in \Omega \subset \mathbb{R}^2, s.t.
for a given \mathbf{B} that is normal to \Omega. So I multiply with a testfunction, integrate and get
The UFL cross operator is only defined for 3D vectors, so I tried to implement my own 2D version:
and in 2D this is just
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?