Connectivity
Understanding mesh connectivity in Rodin.
Introduction
Connectivity (or incidence) information describes how the polytopes (vertices, edges, faces, cells) in a mesh relate to each other. In Rodin, this is managed by the Connectivity class, which is accessed through Mesh::
Connectivity is essential for:
- Identifying boundary entities for imposing boundary conditions
- Traversing mesh topology during assembly
- Finding neighbors and adjacencies
Notation
Connectivity is described as a relation between polytopes of dimension and dimension . We write this as the -connectivity.
For a 2D triangular mesh:
- (cells are triangles)
- (edges)
- (vertices)
Common connectivity relations:
| Relation | Meaning | Use case |
|---|---|---|
| Vertices → Cells | Which cells share a vertex | |
| Edges → Cells | Boundary detection (edges with 1 cell) | |
| Cells → Vertices | Cell vertex lookup | |
| Cells → Edges | Cell edge lookup |
Computing connectivity
Connectivity relations are computed on demand using the compute() method.
Mesh mesh; mesh = mesh.UniformGrid(Polytope::Type::Triangle, {16, 16}); // Compute edge-to-cell connectivity (required for boundary detection) mesh.getConnectivity().compute(1, 2);
Computation modes
The compute() method accepts an optional mode parameter that controls how sub-entities are handled:
| Mode | Behavior |
|---|---|
Connectivity::Mode::Discover (default) | Creates any missing sub-polytopes that are needed for the relation. For example, computing on a triangle mesh will create edge entities if they do not yet exist. |
Connectivity::Mode::Restrict | Restricts the relation to existing polytopes. Entity creation remains under the control of the mesh builder. |
// Default mode: discovers (creates) edges if needed mesh.getConnectivity().compute(1, 2); // Restrict mode: only uses existing entities mesh.getConnectivity().compute(1, 2, Connectivity::Mode::Restrict);
The default Discover mode constructs the sub-polytopes required by each requested relation.
Boundary detection
Once the connectivity is computed (where is the mesh dimension), Rodin can identify boundary entities — those that are incident to exactly one cell. This is how DirichletBC finds the boundary DOFs automatically.
P1 vh(mesh); TrialFunction u(vh); TestFunction v(vh); RealFunction f = 1; Problem poisson(u, v); poisson = Integral(Grad(u), Grad(v)) - Integral(f, v) + DirichletBC(u, Zero());
Boundary attributes
Different parts of the boundary can be distinguished by attributes (integer labels). This is useful when different boundary conditions are applied to different segments.
Attribute GammaD = 2, GammaN = 3; // Apply Dirichlet BC only on boundary with attribute GammaD DirichletBC(u, Zero()).on(GammaD) // Apply Neumann BC only on boundary with attribute GammaN BoundaryIntegral(g, v).over(GammaN)
Boundary attributes are typically set when loading a mesh from a file or when building a mesh programmatically.