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

boundary conditions in product space

+1 vote

I've got boundary conditions of the form

bc0 = DirichletBC(V, something, somewhere)
bc1 = DirichletBC(V.sub(0), something_else, somewhere_else)
bc2 = DirichletBC(Q, something_else, somewhere_else)

I now construct a linear system in the product space W=V*Q. Is there a way to apply the above boundary conditions in the new system?

One possible solution would be to extract the arguments something* and somewhere* from bc*, and create new DirichletBC instances with W.sub(0), W.sub(1), but I don't know if/how this is possible.

asked Jul 24, 2013 by nschloe FEniCS User (7,120 points)
edited Jul 24, 2013 by nschloe

2 Answers

+2 votes
 
Best answer

Do

bc0.function_space().assign(W.sub(0))
bc1.function_space().assign(W.sub(0).sub(0))
bc2.function_space().assign(W.sub(1))

to replace function space.

answered Jul 24, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Sep 7, 2013 by nschloe

This doesn't seem to work:

from dolfin import *

mesh = UnitSquareMesh(20, 20)

V = FunctionSpace(mesh, 'CG', 2)
W = MixedFunctionSpace([V, V])

uu = TrialFunctions(W)
vv = TestFunctions(W)

a = dot(grad(uu[0]), grad(vv[0])) * dx \
  + dot(grad(uu[1]), grad(vv[1])) * dx
L = 1.0 * vv[0] * dx \
  + 1.0 * vv[1] * dx

## This works.
#b0 = DirichletBC(W.sub(0), 0.0, 'on_boundary')
#b1 = DirichletBC(W.sub(1), 1.0, 'on_boundary')

# This doesn't.
b0 = DirichletBC(V, 0.0, 'on_boundary')
b1 = DirichletBC(V, 1.0, 'on_boundary')
b0.function_space().assign(W.sub(0))
b1.function_space().assign(W.sub(1))

sol = Function(W)
solve(a == L, sol,
      bcs = [b0, b1]
      )

sol0, sol1 = sol.split()

plot(sol0, title='sol0')
plot(sol1, title='sol1')
interactive()

Try this

b0 = DirichletBC(V, 0.0, 'on_boundary')
b1 = DirichletBC(V, 1.0, 'on_boundary')
b0 = DirichletBC(W.sub(0), b0.value(), b0.user_sub_domain())
b1 = DirichletBC(W.sub(1), b1.value(), b1.user_sub_domain())

Previous solution is not correct as something within DirichletBC object needs to be recomputed when function space gets changed.

Also

b0 = DirichletBC(W.sub(0), b0.value(), b0.markers())
b1 = DirichletBC(W.sub(1), b1.value(), b1.markers())

can be used to save a computation of DirichletBC::_facets iff b0, b1 have already been applied so that b0/b1.markers() are not empty. This should also work for FacetFunction initialized BCs.

0 votes

Hi,

In mixed space I believe the correct syntax would be

bc0 = DirichletBC(W.sub(0), something, somewhere)
bc1 = DirichletBC(W.sub(1), something_else, somewhere_else)

Mikael

answered Jul 24, 2013 by mikael-mortensen FEniCS Expert (29,340 points)

That's right. The problem is that I only have the DirichletBCs with V, Q available.

...