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

3d Vectors on a 2d Mesh

0 votes

I am trying to analyze a vector function and a scalar function on a 2D mesh; however, the vector function needs to have 3 components since I am dealing with cross products. The following code spits out an error, "Dimension 0 of a function (4) does not match dimension 0 of function space (3)." If I adjust the InitialConditions class such that

def value_shape(self):
    return (3,)

I get the error, "index out of bounds"

Any suggestions? Do I have to make a 3D mesh or can I stick with 2D?

from dolfin import *
import numpy as np
import random

mesh=CircleMesh(Point(0.0,0.0), 1, 0.1)
Q = VectorFunctionSpace(mesh, "Lagrange", 1)
F = FunctionSpace(mesh, "Lagrange", 1)
FQ = F*Q
fq = Function(FQ)
fq0= Function(FQ)
dfq = TrialFunction(FQ)
df, dq = split(dfq)
f, q = split(fq)
r, p = TestFunctions(FQ)

class InitialConditions(Expression):
def eval(self, values, x):
#scalar conditions
values[0]=0.0
#vector condition
values[1]=1.0
values[2]=1.0
values[3]=0.0
def value_shape(self):
return (4,)

fq_init = InitialConditions()
f_1, q_1 = split(fq0)
fq0.interpolate(fq_init)

asked May 15, 2015 by aldenpack FEniCS User (1,450 points)

1 Answer

+1 vote
 
Best answer

Do you really need cross products? If your vectors are in-plane, then the result will only have a z-component, which you can calculate as a[0]*b[1]-a[1]*b[0]...

answered May 15, 2015 by chris_richardson FEniCS Expert (31,740 points)
selected Jun 27, 2016 by aldenpack
...