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

Subspace extraction for boundary conditions

0 votes

On a 2D domain, I've got a variable with three components (representing a velocity $u$). I'd like to solve a PDE for $u$ and to this end would like to make sure that the first and the third component of $u$ are 0 at the boundary. The .sub() notation seems to be somewhat buggy here: W.sub(0) doesn't seem to return a one-dimensional subspace at all, W.sub(2) doesn't seem to exist.

The following code highlights what I'm talking about:

from dolfin import *

mesh = UnitSquareMesh(20, 20)

V = FunctionSpace(mesh, 'CG', 1)
W = V*V*V

bcs = DirichletBC(W.sub(0), 0.0, 'on_boundary')
bcs = DirichletBC(W.sub(1), 0.0, 'on_boundary')
bcs = DirichletBC(W.sub(2), 0.0, 'on_boundary')
asked Jul 18, 2013 by nschloe FEniCS User (7,120 points)

1 Answer

+3 votes
 
Best answer

'*' is a binary operator, hence your function space has the structure

W = [[V, V], V]

You need to use

W = MixedFunctionSpace([V, V, V])
answered Jul 18, 2013 by Garth N. Wells FEniCS Expert (35,930 points)
selected Jul 18, 2013 by nschloe

Is there a way to determine of how many Vs W is composed of other than len(W.split())?

Yes, there is: W.num_sub_spaces().

Update question: The API seems to have changed quite significantly in FEniCS 2016.2. Does this still apply?
Because to me

Hcurl = FiniteElement("N1curl", mesh.ufl_cell(), 1)
Hdiv = FiniteElement("CG", mesh.ufl_cell(), 1)
vector_space = FunctionSpace(mesh, Hcurl*Hdiv*Hcurl*Hdiv)

seems to do it... (here I want to have a mixed function space of two curl and two div fields, the order is quite random...).

...