Mesh Export¶
The voids.mesh sub-package converts regular porosity and permeability maps
into structured mesh files for downstream continuum workflows, including
quadrilateral/triangular 2-D exports and hexahedral/tetrahedral 3-D exports.
These helpers preserve the map grid and cell ordering; they do not generate a boundary-conforming mesh of the original segmented pore/bone interface. For the map definitions, schemes, Kozeny-Carman closure, export assumptions, and solver-facing caveats, see Porosity Maps.
The optional Gmsh helpers build in-memory CAD models and preserve physical tags when converting to DOLFINx. They require both the Gmsh executable and Python bindings; the centered-vug workflow is described in FEM Manufactured-Solution Verification.
API¶
voids.mesh
¶
DolfinxGmshMesh
dataclass
¶
DOLFINx mesh and physical tags converted from an in-memory Gmsh model.
Source code in src/voids/mesh/gmsh.py
StructuredMapMesh
dataclass
¶
Structured mesh representation for regular porosity/permeability maps.
Attributes:
| Name | Type | Description |
|---|---|---|
points |
ndarray
|
Mesh point coordinates. Points are always stored as three-dimensional
coordinates so 2-D maps can be written by formats that expect 3-D
coordinates with |
cells |
tuple[tuple[str, ndarray], ...]
|
A single meshio-compatible cell block. 2-D maps use |
cell_data |
dict[str, list[ndarray]]
|
Cell-wise data arrays whose flattened order follows
|
Source code in src/voids/mesh/structured.py
to_meshio
¶
Return a meshio.Mesh object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_cell_data
|
bool
|
If |
True
|
Source code in src/voids/mesh/structured.py
write
¶
Write the mesh with meshio and return the destination path.
add_physical_group
¶
Add a nonempty named physical group and return its integer tag.
Source code in src/voids/mesh/gmsh.py
axis_aligned_boundary_entities
¶
Classify axis-aligned facets by their Gmsh bounding boxes.
Curved and interior facets are returned in the second tuple item.
Source code in src/voids/mesh/gmsh.py
configure_uniform_mesh_size
¶
Configure a uniform target size for subsequent Gmsh generation.
Source code in src/voids/mesh/gmsh.py
generate_dolfinx_gmsh_mesh
¶
generate_dolfinx_gmsh_mesh(
build_model,
*,
name,
geometric_dimension,
comm=None,
model_rank=0,
terminal_output=False,
)
Build a Gmsh model on one MPI rank and convert it to DOLFINx.
build_model receives Gmsh after a fresh model has been created. It must
synchronize the CAD kernel, define physical groups, and generate the mesh.
Source code in src/voids/mesh/gmsh.py
require_gmsh
¶
Import and return the optional Gmsh Python module.
Source code in src/voids/mesh/gmsh.py
mesh_format_extension
¶
Return the default filename extension for a supported mesh export format.
Source code in src/voids/mesh/structured.py
structured_map_mesh
¶
structured_map_mesh(
porosity_map,
*,
permeability_map=None,
extra_cell_data=None,
element_type="auto",
include_cell_index=True,
require_finite_cell_data=True,
)
Generate a structured mesh from a regular porosity map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
porosity_map
|
PorosityMap
|
Cell-average porosity map. Its grid defines the mesh topology and physical coordinates. |
required |
permeability_map
|
PermeabilityMap | None
|
Optional permeability map on the same grid. When supplied, it is written
as the |
None
|
extra_cell_data
|
Mapping[str, ndarray] | None
|
Optional additional cell-data arrays. Each array must have the same shape
as |
None
|
element_type
|
MapMeshElement
|
Mesh cell type. |
'auto'
|
include_cell_index
|
bool
|
If |
True
|
require_finite_cell_data
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
StructuredMapMesh
|
Meshio-compatible points, cell connectivity, and cell-data arrays. |
Notes
The mesh is a representation of a regular map grid, not an image-boundary
conforming segmentation mesh. Cell n corresponds to
porosity_map.values.ravel(order="C")[n].
Source code in src/voids/mesh/structured.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
write_structured_map_mesh
¶
write_structured_map_mesh(
porosity_map,
path,
*,
permeability_map=None,
extra_cell_data=None,
element_type="auto",
file_format=None,
require_finite_cell_data=True,
)
Write a structured map mesh with porosity/permeability cell data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
porosity_map
|
PorosityMap
|
|
required |
permeability_map
|
PorosityMap
|
|
required |
extra_cell_data
|
PorosityMap
|
|
required |
element_type
|
PorosityMap
|
|
required |
require_finite_cell_data
|
bool
|
Passed to :func: |
True
|
path
|
str | Path
|
Destination mesh path. The file extension normally determines the meshio writer. |
required |
file_format
|
str | None
|
Optional meshio file-format override. |
None
|
Notes
Netgen .vol export is geometry-oriented in meshio. The writer does not
preserve arbitrary floating-point cell-data arrays, so keep the HDF5 map
export as the authoritative porosity/permeability field when using Netgen.
Source code in src/voids/mesh/structured.py
write_structured_map_meshes
¶
write_structured_map_meshes(
porosity_map,
output_dir,
*,
stem,
permeability_map=None,
formats=("gmsh", "vtk", "vtu", "netgen"),
extra_cell_data=None,
element_type="auto",
require_finite_cell_data=True,
)
Write the same structured map mesh to several mesh formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
porosity_map
|
PorosityMap
|
|
required |
permeability_map
|
PorosityMap
|
|
required |
extra_cell_data
|
PorosityMap
|
|
required |
element_type
|
PorosityMap
|
|
required |
require_finite_cell_data
|
bool
|
Passed to :func: |
True
|
output_dir
|
str | Path
|
Directory where mesh files will be written. |
required |
stem
|
str
|
Filename stem used for every exported file. |
required |
formats
|
Sequence[str]
|
Format labels. Supported labels are |
('gmsh', 'vtk', 'vtu', 'netgen')
|
Returns:
| Type | Description |
|---|---|
dict[str, Path]
|
Mapping from the requested format label to the written mesh path. |