Error for more or less standard variational formulation using two cross products

For a toy problem on a way to a more complicated system of PDEs, I tried to solve a variational problem of the form
a(u,v) = \int (u \times v, u \times v) dx.
Edit: the above formulation is not well defined in the sense of FEM. What I rather meant was
a(u,v) = \int (u \times g, u \times v) dx.
for some function g.

However I do end up with the Error, when I try to solve the variational problem with a non-linear solver,

UFLException: Index out of bounds.

which seems to happen in the UFL package.

My code is

from fenics import *
mesh = UnitSquareMesh(2, 2)
deg = 1

V=VectorFunctionSpace(mesh, "P",deg, dim=2)

u = Function(V)
v = TestFunction(V)

L = inner(cross(u, v) , cross(u, v) )*dx
solve(L==0, u)

I have to say I am quite overwhelmed with the error message because it does not really hint where I might have made a mistake. To me the variational problem seems well defined with a trivial solution, therefore the issue must occur during the assembly.
Would be very happy about every hint for my problem :slight_smile:

Hi sorry, but I don’t think that you have a properly defined variational formulation. Either you should have a bilinear form a and a linear form L such as a(u, v)==L(v) for all v or a non-linear form F(u, v) == 0 for all v with F being non-linear with respect to the unknown function u but still being linear with respect to the test function v. Your a(u, v) makes no sense as it depends non-linearly on the test function v…

1 Like

Oh gosh, you are absolutely right. I made that rookie mistake when abstracting from my original problem.
Changed the code slightly, but I still run into the same Error.
Now it should (hopefully) really be well-defined…

from fenics import *
mesh = UnitSquareMesh(2, 2)
deg = 1

V=VectorFunctionSpace(mesh, "P",deg, dim=2)

u = Function(V)
v = TestFunction(V)
g = interpolate(Expression(("sin(x[0])","1"),degree=2),V)

L = inner(cross(u, g) , cross(u, v) )*dx
solve(L==0, u)

From the ufl documentation: Form language β€” Unified Form Language (UFL) 2019.2.0.dev0 documentation

The operator cross accepts as arguments two logically vector-valued expressions and returns a vector which is the cross product (vector product) of the two vectors:

πšŒπš›πš˜πšœπšœ(𝚟,𝚠)↔vΓ—w=(v1w2βˆ’v2w1,v2w0βˆ’v0w2,v0w1βˆ’v1w0)

Note that this operator is only defined for vectors of length three.

1 Like

That I should have noticed… Thanks for the quick reply!