DirichletBC does not support changes in meshfunction

Issue #584 wontfix
Øyvind Evju created an issue

Consider the following test case:

from dolfin import *
mesh = UnitSquareMesh(4,4)
V = FunctionSpace(mesh, "CG", 1)

mf = FacetFunction("size_t", mesh)
mf.set_all(0)

CompiledSubDomain("x[0]<1e-12").mark(mf,1)
bc = DirichletBC(V, Constant(1), mf, 1)

u = Function(V)
bc.apply(u.vector())
print assemble(u*dx)

mf.set_all(1)
bc.apply(u.vector()) 
print assemble(u*dx) # Should be 1

bc = DirichletBC(V, Constant(1), mf, 1)
bc.apply(u.vector())
print assemble(u*dx) 

DirichletBC does not capture the changes in the meshfunction (or any other mode of setting subdomains), because DirichletBC::init_facets are only computed once. Re-computing facets is of course costly, so I suggest perhaps exposing a parameter allowing for dynamic domains (e.g. recompute_facets)?

Comments (6)

  1. Prof Garth Wells

    Is there a benefit to allowing the facets to be re-computed over creating a new DirichletBC object if the bc facets change?

  2. Øyvind Evju reporter

    I'm not sure of the benefits, but I found the behaviour counter-intuitive. You can change the subdomain data until you call apply, but not after. Perhaps the facets should be computed in the constructor?

  3. Jan Blechta

    The current behaviour is now documented. Feel free to implement a method for clearing DOF index cache. Closing this due to inactivity,

  4. Log in to comment