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)