← 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.
1. Decide what object you are measuring
The composition field c is continuous-valued. Choose a threshold τ to define two discrete regions: red contains c ≥ τ; blue contains c < τ. We use τ = 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.
2. 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.
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.
3. 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. Divide that displacement by the corresponding box lengths:
\[\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³ 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³ 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 →
4. Closed contours and holes are different counts
In a bounded 2D region, a disk has one component and no hole. An annulus has one component, one hole and two boundary contours: inner and outer. Thus counting closed contours is not the same as counting components or holes.
Trace level contours at c = 0.5 using marching squares. Contours cut by an image boundary can appear open. With periodic data, match seam endpoints using the periodic field and unwrap the traced curves before classifying closure and winding. Do not add artificial straight segments across the image. Alternating high/low values in one square create an ambiguous diagonal case; choose and document the contour connectivity convention.
Betti numbers count independent topological features: β₀ counts components, β₁ counts independent loops that cannot be filled within the object, and β₂ counts enclosed-void features for ordinary bounded 3D solids. These concern the filled region. A square of four occupied pixels has a cycle in its adjacency graph but no hole when its pixels are filled. Raw graph cycle counts therefore do not give the phase’s β₁.
For a bounded planar region, the Euler characteristic is χ = β₀ − β₁. A disk has χ = 1; an annulus has χ = 0. Euler characteristic combines counts, so different topologies can share the same χ.
5. In 3D: the solid and its boundary surface
| Solid | β₀ | β₁: tunnels | β₂: cavities | χ |
|---|---|---|---|---|
| Filled ball (or filled cube) | 1 | 0 | 0 | 1 |
| Solid doughnut / one through-tunnel | 1 | 1 | 0 | 0 |
| Thick spherical shell | 1 | 0 | 1 | 2 |
| Two separate filled balls | 2 | 0 | 0 | 2 |
For these solids, χ = β₀ − β₁ + β₂. In general, χ is the alternating sum of all Betti numbers. Periodic domains require care: the fully occupied periodic 3D box is a three-torus with Betti numbers (1,3,3,1), giving χ = 0. Do not silently apply bounded-domain cavity intuition to it.
The boundary surface has its own Euler characteristic. A spherical surface has χ = 2; a toroidal surface has χ = 0. A thick shell has two spherical boundary components, whose total surface χ is 4, whereas the shell solid has χ = 2.
For a closed, connected, orientable surface of genus g, χ = 2 − 2g. For S such surface components, total χ = 2S − 2Σg. On a valid triangulated surface, χ = V − E + F, counting unique vertices, edges and faces. Identify periodic seam vertices and edges, include the cells crossing the seam, and verify that each edge belongs to two triangles before using the closed-surface formula. Boundary edges and nonmanifold junctions invalidate that shortcut.
6. Geometry complements topology
The four scalar Minkowski functionals in 3D describe volume, surface area, integrated mean curvature and Euler characteristic, up to normalization conventions. Volume and area tell us how much phase and interface exist; topology tells us how regions join. Curvature describes local bending.
For an oriented smooth interface, define H = (k₁+k₂)/2 and K = k₁k₂ from its principal curvatures. Reversing the normal changes the sign of H, but not K. For a closed orientable surface, Gauss–Bonnet gives ∫K dA = 2πχ. Report the normal orientation, curvature convention, grid spacing and boundary treatment.
Fiałkowski, Aksimentiev and Hołyst studied these quantities during phase separation. Their work motivates complementary geometric measurements; one Euler number alone does not certify bicontinuity.
7. 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³ 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³ 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.
8. Exercises, worked solutions and self-checks
1. 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.
2. Does χ = 0 establish a percolating network?
No. A bounded annulus has χ = 0 but does not percolate around a periodic box. Conversely a wrapping stripe has a nonzero winding. χ combines topology without stating where the loops go or which component carries them.
3. 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.
4. A sphere and a shell both look spherical. What distinguishes them?
A filled ball has no cavity and solid χ = 1. A thick shell encloses one cavity and solid χ = 2. Its inner and outer interfaces are two separate spherical surfaces. Shape and topology describe different information.
5. 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³ example.
9. 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 χ belongs to the solid or the interface, the complex/mesh convention, periodic seam treatment and normalization. Keep display simplification separate from numerical measurements.
Sources and further study
- Fiałkowski, Aksimentiev and Hołyst (2001): Euler characteristic, surface area and curvatures in phase-separating or ordering systems.
- Aksimentiev, Hołyst and Fiałkowski (2002): morphology of complex surfaces.
- scikit-image measurement documentation: contour ambiguity, digital connectivity, Euler characteristic and marching cubes.
- GUDHI periodic cubical complexes: a route to periodic homology, after choosing the appropriate cell representation.