Examples and tutorials » Mesh geometry examples » Computing mesh connectivity

How to compute and use topological connectivity.

Introduction

Mesh connectivity describes how polytopes of different dimensions relate to each other. This example demonstrates computing various incidence relations and measuring the performance.

Computing Connectivity

The Connectivity::compute(d1, d2) method computes the incidence mapping from polytopes of dimension $ d_1 $ to polytopes of dimension $ d_2 $ :

#include <Rodin/Geometry.h>

using namespace Rodin;
using namespace Rodin::Geometry;

int main()
{
  Mesh mesh;
  mesh = mesh.UniformGrid(Polytope::Type::Triangle, { 1024, 1024 });

  // Compute various connectivity relations
  mesh.getConnectivity().compute(1, 2);  // edges → cells
  mesh.getConnectivity().compute(2, 1);  // cells → edges
  mesh.getConnectivity().compute(1, 1);  // edge adjacency

  return 0;
}

Common Relations

RelationUse Case
compute(1, 2)Required for boundary detection and Dirichlet BC
compute(0, 2)Vertex-to-cell: which cells share a vertex
compute(2, 1)Cell-to-edge: enumerate edges of each cell
compute(1, 1)Edge adjacency: which edges share a vertex

Why Boundary Detection Needs Connectivity

The $ (d{-}1, d) $ connectivity tells us which faces belong to exactly one cell — those are the boundary faces. This is why you must call compute(1, 2) before using DirichletBC on a 2D mesh:

mesh.getConnectivity().compute(1, 2);

P1 vh(mesh);
TrialFunction u(vh);
TestFunction  v(vh);

Problem poisson(u, v);
poisson = Integral(Grad(u), Grad(v))
        - Integral(RealFunction(1.0), v)
        + DirichletBC(u, Zero());  // needs (1,2) connectivity
Solver::CG(poisson).solve();

Full Source Code

See Also