NGSolve Technical Note 2026-06 \(\bullet\) version 2026-11-17
The elements of a Netgen/NGSolve mesh [1, 2] carry a region index: volume elements a material,
surface elements a boundary condition, segments an edge region, point
elements a vertex region. A Region is a subset of the
regions of one of these four lists, identified by the
codimension VorB \(\in\{\)VOL, BND,
BBND, BBBND\(\}\), and stored as a bit mask:
mesh.Materials("iron|air") mesh.Boundaries("outer")
mesh.BBoundaries("rail") mesh.BBBoundaries("pin")
Many tasks need regions of several codimensions at once.
Essential boundary conditions. A structure is
clamped on a face, supported on an edge, and pinned in one point against
a rigid body motion. So far this needed the three flags
dirichlet, dirichlet_bbnd and
dirichlet_bbbnd.
Mixed-dimensional models. A solid with a shell on a part of its surface and a beam along an edge; a multiplier on an interface; a coefficient with one value in a domain and another one on a boundary.
Topology. Which faces, edges and points belong to the boundary of a domain? What is the interface of two domains, including its rim? Where do two boundary conditions meet? The answers are sets of regions of different codimension.
The MixedRegion is one object for such a selection. With
the region incidence of the mesh it also provides closure, boundary and
star. This note describes the semantics, the data structures, and where
a MixedRegion is accepted.
A MixedRegion consists of a mesh and four bit masks, one
for each VorB. It is created by the operator |
between regions of different codimension, by regular expressions for the
single codimensions, or from one Region. Wherever a
MixedRegion is expected, a Region is converted
automatically.
clamp = mesh.Boundaries("bot") | mesh.BBoundaries("rail") | mesh.BBBoundaries("pin")
clamp = mesh.MixedRegion(BND="bot", BBND="rail", BBBND="pin") # the same
print (clamp) # MixedRegion(BND: [bot], BBND: [rail], BBBND: [pin])
The operations are those of sets, applied to each mask (Table 1). Operands must belong to the same mesh object.
| operation | result | remark |
|---|---|---|
a | b, a & b, a - b, ~a |
MixedRegion |
set operations in each codimension |
a[VOL], a[BND],
… |
Region |
the part of one codimension |
a.Closure() |
MixedRegion |
a and all lower-dimensional
regions it touches |
a.Boundary() |
MixedRegion |
the regions one dimension lower which
a touches |
a.Star() |
MixedRegion |
a and all higher-dimensional
regions touching it |
a.IsClosed(),
a.Empty(), a == b |
bool |
|
a.IndicatorCF() |
CoefficientFunction |
\(1\) on
the elements of a, else \(0\) |
Open sets. A MixedRegion contains
exactly the regions which were given. A face does not bring its edges
along. The closure is an operation of its own, and every function which
takes a MixedRegion documents whether it adds
lower-dimensional parts. The reason is that there is no single right
answer: the dofs of a continuous space on a face include those on its
edges, the dofs of a discontinuous or a facet space do not.
Two types. The operators of Region are
unchanged: +, -, * combine
regions of the same codimension and return a Region; for
regions of different codimension or of different meshes they now throw
an exception (before, the masks of two unrelated lists were combined
silently). The operator | returns a Region for
two regions of the same codimension, and a MixedRegion
otherwise. A Region and a MixedRegion never
compare equal.
Descriptors without a mesh.
VOL("ball"), BND("bot"),
BBND("rail"), BBBND("pin") name regions of one
codimension, and | combines them into a
MixedRegionDescriptor: names per codimension, regular
expressions as before, no mesh. The mesh resolves it,
descr[BND] gives the part, and descriptors pickle.
descr = BND("bot") | BBND("rail") | BBBND("pin") # BND(bot) | BBND(rail) | BBBND(pin)
mr = mesh[descr] # MixedRegion; equals the union of the three
descr[BND], descr[VOL] # BND(bot), None
A descriptor is accepted by the functions of Table 2
(dirichlet, definedon, keys of
RegionCF, u[...] == g,
gf[...] = cf). Two descriptors of the same codimension give
a plain region descriptor.
Let \(\mathcal R_d\) be the set of regions of entity dimension \(d\in\{0,1,2,3\}\), i.e. vertex, edge, face and volume regions. In a mesh of dimension \(D\) the codimension \(v\) corresponds to \(d = D-v\). For \(r\in\mathcal R_d\) and \(s\in\mathcal R_{d'}\) with \(d<d'\) we write \[r \prec s \quad :\Longleftrightarrow\quad \text{an element of }r\text{ is a vertex, edge or face of an element of }s.\] For a set \(M\) of regions \[\operatorname{cl}M = M\cup\{r: r\prec s,\ s\in M\},\qquad \operatorname{st}M = M\cup\{s: r\prec s,\ r\in M\},\qquad \partial M = \{r\in\mathcal R_{d-1}: r\prec s,\ s\in M\cap\mathcal R_d\}.\]
Direct tables. The relation is stored for all six pairs \(d<d'\), in both directions, and not composed from the pairs of neighbouring dimensions. An edge region inside of a volume (a wire, a beam, a line source) or a point region inside of a face touches the higher-dimensional region without lying on a region of the dimension in between; a composition \(\mathcal R_3\to\mathcal R_2\to\mathcal R_1\) would miss it (Figure 1).
Computation. The tables are computed in Netgen,
Mesh::GetRegionIncidence(), indexed by the entity dimension
like the region descriptors Region<D> of the mesh.
With the topology of the mesh, three maps are built: vertex \(\to\) regions of its point elements, edge
\(\to\) regions of its segments, face
\(\to\) regions of its surface
elements. An entity may belong to several regions. One loop over the
segments, the surface elements and the volume elements then looks up
their vertices, edges and faces in these maps. The cost is one pass over
the elements. Netgen computes the tables at each call, from the current
elements; nothing is cached there. NGSolve fetches them once after each
update of the mesh (MeshAccess::BuildNeighbours); the
existing functions Region.Neighbours(vb) and
Region.Boundaries() use the same tables. In Python the
tables are available as
mesh.ngmesh.RegionIncidence(d1,d2).
What the closure sees. The relation is defined by elements. An edge of the geometry without segments in the mesh is not a region and not seen by the closure. Meshes from OCC geometries have segments for all edges and point elements for all vertices of the geometry.
Limits. The incidence is not stored in the mesh and
not written to the .vol file; it is computed from the
elements at each call and needs valid edge and face tables. Regions
exist only where the mesh has elements of that dimension. Two regions
are incident if one pair of elements touches, which equals the B-rep
topology for OCC meshes. It is known per MPI rank only. Hand-made meshes
work.
One step. \(\operatorname{cl}\) adds the regions
directly below \(M\). If every region
is one entity of a boundary representation (one face, one edge, one
vertex, as for OCC geometries), then \(r\prec
s\prec t\) implies \(r\prec t\),
and \(\operatorname{cl}\operatorname{cl}M =
\operatorname{cl}M\). For regions which are unions of unrelated
pieces (one boundary condition number for several patches of an imported
mesh) this need not hold: \(r\) may
touch \(s\) in one place and \(s\) touch \(t\) in another one. IsClosed()
tests \(\operatorname{cl}M = M\).
| function | meaning for a
MixedRegion |
adds lower dimensions? |
|---|---|---|
FESpace(..., dirichlet=mr) |
constrain the dofs of the
BND, BBND, BBBND parts |
as the space does for elements |
FESpace(..., definedon=mr) |
like the dict
{VOL: ..., BND: ...} |
yes, all sub-entities (Sec. 5) |
fes.GetDofs(mr),
u.GetDofs(mr) |
union of the dofs of the elements of all parts | no |
mesh.RegionCF({mr: value}) |
value in all non-empty parts of
mr |
no |
mr.IndicatorCF() |
see Table 1 | no |
u[mr] == g in
Solve |
Dirichlet condition on all parts | as dirichlet |
gf[mr] = cf |
set the dofs of the parts to
cf |
see example |
Dirichlet. The parts are combined by or
with the flags dirichlet_bbnd and
dirichlet_bbbnd, which keep working. A volume part is an
error. A plain Region of BBND or
BBBND is accepted as well
(dirichlet=mesh.BBoundaries("rail")); a non-empty
VOL region is an error. dirichlet=BBND("rail")
and dirichlet_bbnd="rail" give the same free dofs. A dof is
constrained if it belongs to an element of a selected region; for \(H^1\) and \(H(\operatorname{curl})\) spaces a face
therefore constrains the dofs on its edges and vertices as before,
without a closure. What is new is that an isolated edge or point is
given in the same argument.
Compact syntax.
Solve(a == f, u[BND("left") | BBND("edge")] == g, pre, solver)
takes a descriptor (also BND("bot") alone); the condition
keeps it (bc.vbn). It was run with BDDC and
CGSolver; the solution equals that of the flag form to
\(10^{-16}\).
Coefficients.
mesh.RegionCF({region: value, ...}, default=...) without a
VorB takes regions of any codimension as keys. It is one
CoefficientFunction; the codimension of the element selects
the list of values, the region index the entry. A
MixedRegion as key sets the value in each of its non-empty
parts. The default applies to the remaining regions of
those codimensions which have a given region; in the other codimensions
the function is undefined, and the use there is refused before any
element is touched. The region-wise functions MaterialCF,
BoundaryCF and RegionCF are now one class
(RegionCoefficientFunction, C. Lackner); pickles of the
former class DomainWiseCoefficientFunction written since
version 6.2.2406 can be loaded.
Not an integration domain.
dx(definedon=...), ds(definedon=...) and
Integrate(..., definedon=...) take a Region.
The measure and usually the integrand depend on the codimension, so an
integral over a MixedRegion is not defined. Use the parts:
dx(definedon=mr[VOL]).
The flag is closed. For every form of
definedon (Region, MixedRegion,
descriptor, string, dict {VOL: ..., BND: ...}) the space is
defined on the given regions and all their sub-entities: each
lower-dimensional mask is what was given, united with the closure of
everything given above it. Before, edges and points were either
unrestricted or exactly the given part. The dof numbering does not
change. What changes is where edge and point terms are assembled and
where a GridFunction counts as defined. With MPI the closed
masks are OR-reduced over the ranks, since the incidence is known per
rank only.
fs = H1(mesh, order=2, definedon=mesh.Boundaries("top"))
MixedRegion(mesh.Boundaries("top")).Closure() == fs.definedon # True
Storage. The space keeps both sets as
MixedRegion. In Python fes.definedon and
fes.dirichlet are read-only copies;
fes.GetDefinedOnRegion(vb) equals
fes.definedon[vb], and for an unrestricted space
fes.definedon == ~MixedRegion(mesh). In C++:
members definedon_region,
dirichlet_region; all four masks always have full size,
“everywhere” means all bits set (before: empty array);
DefinedOnAll(vb); GetDefinedOn(vb) and
DefinedOn(vb) return BitArray (before:
Array<bool>); DefinedOnX is
removed;
the archive layout is unchanged; Update resizes the
masks of an unrestricted space if the number of regions changed, and
throws for a restricted one.
Elements without region. A segment added by hand
without edge index (Element1D(..., index=0) in a 3D mesh)
is a BBND element with region index \(-1\). It belongs to no region: the space is
not defined on it (GetDofNrs is empty) and it gets no
Dirichlet dofs.
A unit cube contains a ball. The solution is fixed on the bottom face, on one edge of the top face, and in one corner. The coefficient is \(1\) in the cube, \(10\) in the ball, and the same function gives the Robin coefficient \(5\) on the top face.
from ngsolve import *
from netgen.occ import *
box = Box((0,0,0), (1,1,1))
box.solids.name = "air"; box.faces.name = "wall"
box.faces.Min(Z).name = "bot"; box.faces.Max(Z).name = "top"
box.edges.Max(X+Z).name = "rail"
box.vertices.Max(X+Y+Z).name = "pin"
ball = Sphere((0.5,0.5,0.5), 0.25)
ball.solids.name = "ball"; ball.faces.name = "sphere"
mesh = Mesh(OCCGeometry(Glue([box-ball, ball])).GenerateMesh(maxh=0.2))
clamp = mesh.Boundaries("bot") | mesh.BBoundaries("rail") | mesh.BBBoundaries("pin")
fes = H1(mesh, order=2, dirichlet=clamp) # ndof = 2089, 1937 free dofs
# same as H1(mesh, order=2, dirichlet="bot", dirichlet_bbnd="rail", dirichlet_bbbnd="pin")
k = mesh.RegionCF({mesh.Materials("air"): 1, mesh.Materials("ball"): 10,
mesh.Boundaries("top"): 5}, default=0)
u, v = fes.TnT()
a = BilinearForm(k*grad(u)*grad(v)*dx + k*u*v*ds).Assemble()
f = LinearForm(v*dx).Assemble()
gfu = GridFunction(fes)
gfu.vec.data = a.mat.Inverse(fes.FreeDofs()) * f.vec # mean value 0.1184
# topology
cball = MixedRegion(mesh.Materials("ball")).Closure()
cball[BND] == mesh.Boundaries("sphere") # True
iface = MixedRegion(mesh.Materials("air")).Closure() & cball # the sphere, no volume
MixedRegion(mesh.BBBoundaries("pin")).Star() # 1 volume, 3 faces, 3 edges, the point
ind = clamp.IndicatorCF()
Integrate(ind, mesh, BND), Integrate(ind, mesh, BBND) # 1.0, 1.0: area, length
The matrix a equals the one assembled with a
MaterialCF in the volume term and the boundary term
5*u*v*ds("top"); the two solutions agree to the last digit.
The coefficient k is \(0\)
on the boundaries other than top by the
default.
Descriptors, the closed flag and elements without region:
descr = BND("bot") | BBND("rail") | BBBND("pin")
fes = H1(mesh, order=2, dirichlet=descr) # 2089 dofs, 1937 free: as clamp above
gf = GridFunction(fes); gf[descr] = 3 # 3.0 at (.3,.3,0) and (1,1,1), 0 at (.1,.1,.9)
k = mesh.RegionCF({VOL("air"): 1, VOL("ball"): 10,
BND("top") | BBND("rail"): 5}, default=0)
Integrate(k, mesh, BND), Integrate(k, mesh, BBND) # 5.0, 5.0
u, v = fes.TnT()
gs = Solve(grad(u)*grad(v)*dx + u*v*ds("top") == 1*v*dx, u[descr] == 0)
H1(mesh, order=2, dirichlet=mesh.BBoundaries("rail")) # 2078 free of 2089
H1(mesh, order=2, dirichlet=mesh.Materials("ball")) # NgException: VOL regions are not supported
In a tetrahedron with two hand-made segments, one with index \(0\) (region \(-1\)) and one with index \(1\), H1(order=1) has dof
counts [0, 2] on the two segments, and
dirichlet_bbnd=".*" leaves
[True, True, False, False] free.
The mesh object matters. Regions belong to one
Mesh object. Regions of two Mesh objects are
not combined, also if both wrap the same Netgen mesh or one is the
unpickled copy of the other. Pickle a region together with its
mesh.
After a change of the mesh. The masks have the
sizes of the region lists at the time of creation. Refinement keeps the
regions; after a change of the region lists a stored region is rejected
by the flags of the spaces and by RegionCF.
Empty parts. An empty part of a
MixedRegion does not stand for its codimension: as a key of
RegionCF it does not activate the default
there, and a completely empty key is an error. A mistyped name gives an
empty Region without a message, as before.
One region around two materials. Incidence is by
regions. A boundary region running around two materials makes a space
with definedon one material defined on the whole boundary
region. In a 2D mesh of \(4\times4\)
quadrilaterals with materials left, right and
one boundary region outer,
H1(order=2, definedon=mesh.Materials("left")) has 63 dofs,
60 of them used, and 15 used dofs have a zero diagonal in
u*v*dx (no volume element on the far part). With
outer_l and outer_r instead: 55 dofs, 45 used,
no zero row. Remedy: one boundary region per material.
Boundary is incidence. Boundary()
contains the interface between two selected domains. There is no
orientation, and no relation like \(\partial\partial = 0\).
Parallel meshes. The incidence is computed from
the elements of each rank. Closure, boundary and star may differ between
the ranks, as Region.Neighbours did before. The masks and
dirichlet are not affected; the closed
definedon masks are OR-reduced over the ranks.
Regions of all dimensions with a closure are the labels of PETSc
DMPlex [3, 4], where a
label marks mesh points of any dimension and boundary conditions act on
the closure of a label. The difference is the level: DMPlex stores the
cell complex of the mesh entities, the region incidence of Section 3
is the complex of the geometric entities, which is small and independent
of refinement. A closed MixedRegion is a subcomplex in the
sense of finite element exterior calculus [5];
essential conditions on it lead to the relative de Rham complex.
Further functions are planned to take a MixedRegion:
marks for singular points, edges and faces in \(hp\)-refinement, extraction of a submesh
with its lower-dimensional regions, selection of additional coarse dofs
in BDDC, and local mesh size.
Status. The features are in the NGSolve master branch since November 2026.
J. Schöberl. NETGEN: An advancing front 2D/3D-mesh generator based on abstract rules. Comput. Vis. Sci. 1(1):41–52, 1997.
J. Schöberl. C++11 implementation of finite elements in NGSolve. ASC Report 30/2014, TU Wien, 2014.
M. G. Knepley and D. A. Karpeev. Mesh algorithms for PDE with Sieve I: Mesh distribution. Sci. Program. 17(3):215–230, 2009.
M. Lange, L. Mitchell, M. G. Knepley and G. J. Gorman. Efficient mesh management in Firedrake using PETSc DMPlex. SIAM J. Sci. Comput. 38(5):S143–S155, 2016.
D. N. Arnold, R. S. Falk and R. Winther. Finite element exterior calculus, homological techniques, and applications. Acta Numer. 15:1–155, 2006.