← Microstructure notebook · Explore both 3D phase networks

Topology and connectivity of microstructures

A labyrinthine picture invites a question: which parts actually connect? In this tutorial we turn that question into measurements. Then we distinguish connected regions, periodic percolation, closed contours, tunnels and cavities. No prior topology course is assumed.

Decide what object you are measuring

The dimensionless composition field \(c\) is continuous-valued. I choose a dimensionless threshold \(\tau\) to define two discrete regions: red contains \(c\geq\tau\); blue contains \(c<\tau\). I use \(\tau=0.5\) for the teaching example. The conserved mean composition is an average over the field; it does not prescribe the connectivity of either thresholded region.

Next choose adjacency. In 2D, four neighbors share an edge; eight also allow corner contact. In 3D, six neighbors share a face, eighteen include edge contact, and twenty-six also include corners. Our primary connectivity calculation uses face sharing. A connection that exists only at a corner should be reported explicitly.

Finally choose the domain: a bounded image has physical or observation boundaries; a periodic image identifies opposite faces. The same pixels can have different component counts under those choices. “Connected” is a property of the object together with these definitions.

Label components: an experiment you can edit

A connected component is a maximal group of occupied pixels reachable from one another by allowed steps. Flood fill starts at one occupied pixel and visits every reachable neighbor. Repeat from the next unvisited pixel to count all components. Breadth-first search and union–find are two ways to perform this operation.

Click cells to toggle red occupancy. The measurements apply to red only; pale cells are background. Coordinates are \(x\) across the screen and \(y\) downwards. Periodic mode identifies left/right and top/bottom edges.

Use the downloadable Python examples if canvas is unavailable.

Report the number of components and the fraction of the phase in its largest component: largest-component pixels divided by all pixels of that phase. One component establishes complete connectivity of the sampled phase. A large spanning component with isolated pockets establishes percolation, but not complete connectivity.

Percolation and periodic winding

For a bounded specimen, a spanning path joins designated opposite faces. For a periodic specimen, we ask whether a component contains a noncontractible loop: a loop that cannot shrink to a point while remaining in the periodic domain.

Track a path in unwrapped coordinates. The stored pixel index returns to the box after crossing a boundary, but the unwrapped position keeps moving. When two paths reach the same stored pixel with different unwrapped positions, their difference reveals a closed loop. Let \(\Delta X\), \(\Delta Y\) and \(\Delta Z\) be the displacement differences in the three directions, and let \(L_x\), \(L_y\) and \(L_z\) be the corresponding box lengths. The displacement differences and box lengths use the same length units. Dividing them gives the dimensionless winding vector \(\mathbf w\):

\[\mathbf w=(\Delta X/L_x,\Delta Y/L_y,\Delta Z/L_z).\]

These integers form its winding vector. A curved loop with \((1,0,0)\) winds once along \(x\); its segments need not point along \(x\). A loop with \((1,1,0)\) winds along \(x\) and \(y\), but supplies only one independent winding. In the staircase preset, both coordinate entries are nonzero while the winding rank is one.

The rank counts linearly independent winding vectors, at most two in 2D or three in 3D. Three independent directions establish rank-three periodic percolation. This rank does not count every tunnel in the phase. Rank also does not, by itself, specify the full integer winding lattice; keep the vectors if primitive winding or multiple wrapping matters.

Check windings separately for each component. An x-wrapping component and a disconnected y-wrapping component do not constitute one interconnected network. The saved \(256^3\) example has one component per phase and rank three in each; the flood demonstration reaches every voxel from one seed in each phase. The optional wrapping loops illustrate selected paths; the exhaustive voxel measurement supplies the full connectivity result.

Hoshen–Kopelman: label, then merge

Scan occupied cells in a fixed order. If an occupied cell has no already scanned occupied neighbor, start a new label. If it has one, inherit that label. If it meets different labels, record that those labels belong to the same cluster using union–find. Resolve equivalent labels to count the final components. Join corresponding opposite-face neighbors for periodic data.

Labels alone do not prove wrapping. Store lifted displacement to each union–find root. When joining two cells already in the same cluster, a nonzero residual displacement identifies a periodic winding loop. Keep these vectors per component and measure their independent rank.

The new \(256^3\) explorer implements this scan and independently checks the result with a flood from one seed in each phase. Its front shows shortest-path graph distance, not simulated diffusion time. It also measures the unsimplified periodic interface, inspired by the Fiałkowski–Aksimentiev–Hołyst morphology work.

Download the Python notebook ↓ · Read the code in steps . Run it on the saved field, without evolving the simulation.

Build Hoshen–Kopelman in tested Python, Julia and C steps

Closed contours and holes are different counts

A closed contour is a boundary curve that returns to its starting point. A hole is an empty region enclosed by material in a two-dimensional image. The filled material and its boundary are different objects, so their counts need not be the same.

A filled disk has one connected region, no hole and one outer contour. An annulus is a disk with a hole removed from its middle. It still has one connected region, but now has one hole and two contours: the outside boundary and the boundary around the hole. Two separate filled disks also have two contours, but have two connected regions and no holes. The playground below shows these differences.

How I trace contours in a sampled composition field

A level contour follows points where the composition \(c\) has a selected value, here \(c=0.5\). Marching squares finds this curve one grid square at a time. It checks the composition at the four corners, estimates where the selected value crosses the edges, and joins those crossing points.

A contour cut by the image boundary can appear open. For periodic data, opposite edges represent adjacent parts of the same domain. I match the corresponding endpoints across those edges and follow the curve in unwrapped coordinates before classifying its closure and winding.

If high and low values alternate around the four corners of a square, there are two possible ways to join the crossings. The chosen rule determines which regions connect through that square. I state that rule along with the contour results. A straight line added across the image would create an artificial connection.

What a Betti number counts

One component count tells us whether regions connect, but it cannot distinguish a filled disk from a ring. Betti numbers provide separate counts for different topological features. Topology concerns these connections and openings. Stretching or smoothly bending a shape preserves these counts as long as material does not tear, join, or close an opening.

The symbol \(\beta\) is the Greek letter beta. Its subscript identifies the kind of feature being counted. For the filled regions and ordinary bounded solids used here:

These counts concern the filled region or solid. Four filled pixels arranged as a square have no hole, even though lines joining their centers form a loop. Counting loops in that graph would measure the graph, rather than the filled pixels.

Combining the counts: Euler characteristic

The Euler characteristic, written \(\chi\) and read “chi,” combines the Betti numbers into one number. For a bounded planar region, it is the number of connected components minus the number of holes:

\[\chi=\beta_0-\beta_1.\]

A filled disk gives \(\chi=1-0=1\). An annulus gives \(\chi=1-1=0\). A disk with two holes gives \(\chi=1-2=-1\). These are dimensionless counts. Different shapes can give the same Euler characteristic, so I retain the separate counts as well.

You can learn more about Betti numbers here and Euler characteristic here. Those pages also discuss surfaces, whose counts differ from those of filled solids.

Explore filled shapes and their boundaries

I use these ideal shapes to separate three questions: how many regions connect, how many holes or cavities they contain, and how many contours or surfaces bound them. All shapes below are bounded, with no periodic boundaries.

The Gaussian-curvature view describes bending in two surface directions. A sphere bends the same way in both directions, giving positive curvature. A saddle-shaped patch bends opposite ways, giving negative curvature. The doughnut has both types of patch. The curvature explanation below defines \(K\) and the Gauss–Bonnet relation.

The values describe the selected ideal shapes. They are not measurements of the display triangles or of the spinodal simulation. The size control keeps each hole open and each region separate, so these topology counts remain unchanged. Geometry changes even when topology does not. Lengths are arbitrary; all counts and Euler characteristics are dimensionless.

Two loops on the surface, one in the filled solid

I use two colored paths to show the difference. Gold goes around the central opening. Purple goes around the tube. The first views compare the boundary surface with the filled solid. The cut views then work with the boundary surface alone.

Drag to rotate; scroll or pinch to zoom. Gold: path around the central opening. Purple: path around the tube.

The cylinder and rectangle show the surface after cutting and deformation. They do not show cuts through a filled solid. The copies of each cut are shown in the same color.

“Independent” does not mean that these are the only paths one can draw. A torus surface also permits combinations and repeated windings of the two loop types. Betti numbers count the independent homology features. For these shapes, the disk view explains why one of the surface loop types disappears when the interior is included.

MathCurve illustrates surface cuts here.

In 3D: the solid and its boundary surface

A ball includes its filled interior. Its boundary is only the spherical surface enclosing that interior. A thick spherical shell includes the material between an inner and an outer sphere. It has one connected solid, one enclosed cavity and two boundary surfaces. I distinguish the solid from its boundary before assigning topology values.

Topology of the complete bounded solids shown in the playground
SolidComponents \(\beta_0\)Tunnels \(\beta_1\)Cavities \(\beta_2\)Euler characteristic \(\chi\)
Filled ball (or filled cube)1001
Solid doughnut / one through-tunnel1100
Thick spherical shell1012
Two separate filled balls2002

For these solids, the cavity count enters with a plus sign:

\[\chi=\beta_0-\beta_1+\beta_2.\]

The shell gives \(\chi=1-0+1=2\). Each spherical boundary has surface Euler characteristic \(2\), so its two boundary surfaces together give \(4\). The shell solid's value \(2\) and its boundary's value \(4\) describe different objects. The playground displays both.

MathCurve illustrates cuts and loops on surfaces here. Its doughnut example concerns the surface alone, which has \(\beta_1=2\). Our filled solid doughnut has \(\beta_1=1\): a loop around the tube's cross-section can be filled by material inside the tube, whereas it cannot be filled within the boundary surface alone.

Genus: the handles of a closed surface

For a connected closed surface, genus counts its handles. A sphere has no handle, so its genus is \(g=0\). A doughnut-shaped surface has one handle, so \(g=1\). Here “closed” means that the surface has no free edge. “Orientable” means that a consistent choice of normal direction can be followed over the whole surface. Spheres and doughnut-shaped surfaces have this property.

For a closed, connected, orientable surface:

\[\chi_{\mathrm{surface}}=2-2g.\]

This gives surface Euler characteristic \(2\) for a sphere and \(0\) for a doughnut-shaped surface. If there are \(S\) separate closed orientable surfaces, I add their contributions. Writing \(g_s\) for the genus of surface \(s\):

\[\chi_{\mathrm{surface}}=2S-2\sum_{s=1}^{S}g_s.\]

How I calculate Euler characteristic from a surface mesh

A triangular mesh represents a surface using vertices, edges and triangular faces. Let \(V\) be its number of unique vertices, \(E\) its number of unique edges, and \(F\) its number of faces. These are dimensionless integer counts, and:

\[\chi_{\mathrm{surface}}=V-E+F.\]

For periodic data, I identify matching seam vertices and edges and include triangles crossing the seam. A closed surface has two incident triangles at each edge. I also check that the neighborhood of every vertex forms a single surface patch and that the orientation is consistent. These checks are needed before converting Euler characteristic to genus. Open edges or junctions that do not form a surface require a different interpretation.

Why periodic domains need a separate interpretation

In a periodic box, crossing one face returns to the opposite face. The whole domain therefore has loops that an ordinary filled box does not have. Mathematically, a fully occupied periodic 3D box is a three-torus. It has Betti numbers \((\beta_0,\beta_1,\beta_2,\beta_3)=(1,3,3,1)\). The extra \(\beta_3\) counts a three-dimensional homology feature, not another cavity.

In general, Euler characteristic is the alternating sum over all Betti numbers, including any higher-dimensional terms. For this periodic domain:

\[\chi=\beta_0-\beta_1+\beta_2-\beta_3=1-3+3-1=0.\]

The cavity interpretation used for the bounded solids above does not directly apply to a periodic domain.

Geometry complements topology

The size and curvature of an interface can change while its topology remains the same. For example, enlarging the hole in the playground's annulus changes its area and boundary length, but it still has one connected region and one hole. Geometry describes size and bending. Topology describes connections, tunnels and cavities.

Minkowski functionals are a set of four geometric and topological measurements commonly used for 3D bodies: volume, surface area, integrated mean curvature and Euler characteristic. They describe how much material is present, how much interface it has, how the interface bends, and how its topology contributes. Different references use different numerical prefactors, so I state the convention used for each measurement.

What curvature measures

At a point on a smooth surface, a normal vector is perpendicular to the surface. Cutting the surface with planes containing this normal gives curves with different curvatures. The largest and smallest signed curvatures are the principal curvatures, written \(k_1\) and \(k_2\). A tighter bend has a larger curvature magnitude. For a circular curve of radius \(R\), that magnitude is \(1/R\).

The mean curvature averages the principal curvatures. The Gaussian curvature multiplies them:

\[H=\frac{k_1+k_2}{2},\qquad K=k_1k_2.\]

Here \(H\) denotes mean curvature and \(K\) denotes Gaussian curvature. On a sphere, both principal curvatures have the same sign, so \(K>0\). On a saddle-shaped patch they have opposite signs, so \(K<0\). On the curved side of a cylinder one principal curvature is zero, so \(K=0\). Reversing the normal reverses both principal-curvature signs. It changes the sign of \(H\), but leaves \(K\) unchanged.

If lengths are in meters, \(R\) has units \(\mathrm{m}\), \(k_1\), \(k_2\) and \(H\) have units \(\mathrm{m}^{-1}\), and \(K\) has units \(\mathrm{m}^{-2}\). Volume has units \(\mathrm{m}^3\), area has units \(\mathrm{m}^2\), and integrated mean curvature has units \(\mathrm{m}\). The same relations apply to nondimensional lengths with the corresponding nondimensional values.

Gauss–Bonnet: adding curvature over the whole surface

The Gauss–Bonnet theorem connects local bending to the topology of an entire surface. For a smooth closed orientable surface, adding Gaussian curvature over all its area gives a value fixed by its surface Euler characteristic. Local curvature can change as the surface bends, while this total stays the same if its topology is preserved.

Writing \(\mathcal S\) for the complete surface and \(dA\) for a small surface-area element:

\[\int_{\mathcal S}K\,dA=2\pi\chi_{\mathrm{surface}}.\]

The playground's Gaussian-curvature view colors positive curvature orange-red, negative curvature blue, and zero curvature white. A sphere is positive everywhere. On a doughnut, the outer side is positive and the inner side is negative; the top and bottom circles have zero Gaussian curvature. The color scale shows local curvature, while the displayed integral adds curvature weighted by surface area. Equal-looking colored areas alone do not determine whether the integral cancels.

The integral adds the contribution \(K\,dA\) from every small patch. Since \(K\) has inverse-area units, the total is dimensionless. A sphere of radius \(R\) has \(K=1/R^2\) and area \(4\pi R^2\), giving:

\[\int_{\mathcal S}K\,dA=\frac{1}{R^2}\,4\pi R^2=4\pi=2\pi\times2.\]

Changing the sphere's radius changes its curvature and area, but not this total. A doughnut-shaped surface has \(\chi_{\mathrm{surface}}=0\): its positive and negative Gaussian-curvature contributions cancel when integrated over the complete surface. This does not mean that its curvature is zero at every point. The simple formula above applies to complete closed surfaces. A patch with an edge, including a cutaway display, needs additional boundary terms.

You can learn more about Gauss–Bonnet here, with illustrated explanations in these University of Utah slides here.

Fiałkowski, Aksimentiev and Hołyst studied geometric and topological measurements during phase separation. Their work motivates measuring area and curvature alongside connectivity. One Euler characteristic alone does not establish bicontinuity.

Run and understand the worked examples

Download the Python notebook ↓ · Read the code in steps . It creates small exact masks; no simulation needs to evolve and no \(256^3\) field needs to be loaded.

python -m pip install numpy scikit-image
python topology_connectivity.py

Expected results: seam island → one periodic component, rank zero; stripe → rank one; staircase → rank one despite two nonzero coordinates; full periodic grid → rank two. Bounded Euler values: disk 1, annulus 0, filled ball 1, shell 2 and one-through-tunnel solid 0. The annulus has two closed contours. Assertions check every example.

How the code works

mask is a Boolean NumPy array: True marks occupied cells. deque holds cells awaiting a breadth-first visit. % shape implements periodic indices. lifts stores unwrapped positions; differences at already visited cells reveal windings. In 2D a nonzero determinant of two winding vectors establishes their independence.

label(..., connectivity=1) labels bounded edge- or face-sharing regions. euler_number computes a digital Euler characteristic; foreground and background use complementary connectivity conventions. find_contours returns arrays of points on interpolated level contours. These ordinary scikit-image calls do not identify periodic faces; only our explicit periodic routine does so.

The example uses Python loops for clarity. For the full saved \(256^3\) field use the compiled connectivity routines in Download the Python notebook ↓ · Read the code in steps . For Betti analysis, a periodic cubical-complex library can represent filled cells and their faces. A union of closed voxels includes edge and corner contacts; its topology need not match our six-neighbor graph. Align the chosen complex with the intended digital convention before comparing results.

Exercises, worked solutions and self-checks

Can two phases both percolate in 2D?

Yes. Non-crossing periodic bands allow both phases to wrap along the band direction. They can be wavy; exact parallelism is not necessary. Pinch-off or reconnection during coarsening can break a spanning connection. This does not imply that both have rank-two winding. Two-dimensional paths cannot pass over one another, while 3D permits richer interpenetrating networks. A 2D section can break an otherwise connected 3D phase into islands.

Does \(\chi=0\) establish a percolating network?

No. A bounded annulus has \(\chi=0\) but does not percolate around a periodic box. Conversely a wrapping stripe has a nonzero winding. \(\chi\) combines topology without stating where the loops go or which component carries them.

A loop has winding \((1,1,0)\). Does that prove two independent directions?

No. It is one vector, hence rank one. A second vector that is not a scalar multiple is needed for rank two. Toggle the staircase’s boundary setting and inspect the change.

A sphere and a shell both look spherical. What distinguishes them?

A filled ball has no cavity and solid \(\chi=1\). A thick shell encloses one cavity and solid \(\chi=2\). Its inner and outer interfaces are two separate spherical surfaces. Shape and topology describe different information.

How should we assess the simulation’s robustness?

Repeat segmentation at nearby thresholds, compare adjacency conventions, refine the grid at fixed physical domain, reduce the timestep, and vary seeds and coarsening times. Connectivity tests establish the saved discrete field’s topology; they do not establish convergence or ensemble representativeness. Only threshold checks 0.45, 0.50 and 0.55 are completed for the present \(256^3\) example.

A measurement record you can reproduce

Record the field identifier, dimensions, spacing, simulated time, threshold and inequality; adjacency and boundary conditions; phase fraction, component count and largest-component fraction; per-component winding vectors and rank. When adding morphology, record whether \(\chi\) belongs to the solid or the interface, the complex/mesh convention, periodic seam treatment and normalization. Keep display simplification separate from numerical measurements.

For further exploration

How spinodal geometry can be used

I include the ETH Zurich research on spinodal architectures as an application of the ideas discussed here. Their work connects phase-separation geometry with the mechanical properties of designed materials, including stiffness that differs with direction. It gives a reason to study how regions connect and how interfaces are shaped. The connected regions can become the load-bearing structure of a material.

The ETH example provides further reading on material design. The connectivity measurements on this page concern our own saved simulation field.

How I measure geometry and connectivity

I include the following sources for different parts of the analysis. Hoshen–Kopelman labels connected components; our additional winding calculation tests periodic wrapping. Surface area, curvature and holes describe other properties, so they require other measurements.

Return to the measured 3D percolation example