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

Specifying initial values for mixed vector and scalar fields

0 votes

If I have a mixed problem with a vector (3D) and a scalar field like shown below:

# Define function space for system
mesh = BoxMesh(Point(0.0,0.0,0.0), Point(l,l,l), numElems,numElems,numElems)
P1 = VectorElement('Lagrange', tetrahedron, 1)
P2 = FiniteElement('Lagrange', tetrahedron, 1)
element = MixedElement([P1, P2])
V = FunctionSpace(mesh, element)

# Define test functions
v_1, v_2 = TestFunctions(V)

# Define initial conditions
w   = Function(V)
w_0 = Expression((('0.2','0.3','0.4'),'0.01'), degree=1)
w_n = project(w_0, V)

How do I declare w_0? I get an error on that line

asked Apr 19, 2017 by alexmm FEniCS User (4,240 points)

Why don't you create the expressions separately? It would still work for the (bi)linear forms. Maybe some extra info would help.

The equation I'm trying to solve is 2 nonlinear coupled Euler like equations with a velocity field and density like field. I would like to solve them as a mixed formulation. The question is, how do I initialize a scalar and a vector field like in the w_0 line above when using a mixed element?

1 Answer

+1 vote
 
Best answer

Create the components of w0 separately and use assign (or FunctionAssigner) to join the components into the mixed function:

# Define initial conditions
e_u0 = Expression(('0.2', '0.3', '0.4'), degree=1)
e_p0 = Expression('0.1', degree=1)

u0 = interpolate(e_u0, V.sub(0).collapse())
p0 = interpolate(e_p0, V.sub(1).collapse())

w = Function(V)
assign(w, [u0, p0])
answered Apr 19, 2017 by dajuno FEniCS User (4,140 points)
selected Apr 21, 2017 by alexmm
...