That depends how did you generated the file. For example your mesh generator can produce some cell or facet markers according to its input. Then dolfin-convert
script may or may not succeed converting all these markers to XML. They're then stored within XML mesh file or in separate XML. You can then use them as FacetFunction
# if stored within mesh
facet_domains = mesh.domains().facet_domains(mesh) # older versions of DOLFIN
facet_domains = mesh.domains().facet_domains() # newer versions of DOLFIN
# if stored separately
facet_domains = MeshFunction('uint', mesh, file) # older versions of DOLFIN
facet_domains = MeshFunction('size_t', mesh, file) # newer versions of DOLFIN
# now define homogenous Dirichlet BC where facet_domains is equal to 42
bc42 = DirichletBC(V, 0.0, facet_domains, 42)
# now integrate over interior facets where facet_domains equals 43
dS = Measure('dS')[facet_domains]
dS43 = dS(43)
integral43 = foo*dS43
If your mesh generator does not supply you with markers you need, you can produce first these markers using EntityIterators
, for example
facet_domains = FacetFunction('size_t', mesh, 0)
for c in cells(mesh):
# here some conditions on c
for f in facets(c):
# here some conditions on f
facet_domains[f] = some_computed_value
Then you can use these facet_domains
as suggested above.
Application of DirichletBC
at one particular vertex
Defining DirichletBC
in one vertex is not possible through MeshFunction
s as DirichletBC
only supports FacetFunction
s. But you can take advantage of DirichletBC(..., method='pointwise')
and do something like:
import numpy as np
class Pinpoint(SubDomain):
TOL = 1e-3
def __init__(self, coords):
self.coords = np.array(coords)
SubDomain.__init__(self)
def move(self, coords):
self.coords[:] = np.array(coords)
def inside(self, x, on_boundary):
return np.linalg.norm(x-self.coords) < TOL
pinpoint = Pinpoint([0.,0.,0.])
V = VectorFunctionSpace(mesh, "Lagrange", 1)
bc = DirichletBC(V.sub(0), 0.0, pinpoint, 'pointwise')
Note that this has only meaning for V
being continuous piecewise linear functions. Constructor Pinpoint.__init__
takes an coords
argument (of type tuple
, list
or np.array
) allowing of specification of coordinates where you want to apply BC. Also method Pinpoint.move
can be useful to change this point without a need of creating new DirichletBC
instance - especially when mesh
moves.
Another possibility is to directly fiddle with Tensor
s' entries.