ndiffusion.load_gmsh

ndiffusion.load_gmsh(path: str | Path)[source]

Load a Gmsh .msh file into an UnstructuredMesh2D.

Physical surface groups (dim=2) map to 0-indexed material IDs, sorted by Gmsh physical group tag. Physical curve groups (dim=1) map to 0-indexed BC tags the same way. Cells or boundary edges not in any physical group default to index 0.

Parameters:

path – Path to a Gmsh .msh file (any format version supported by the installed gmsh Python package).

Returns:

With region_names and bc_names attributes mapping each physical group name to its material id or BC tag.

Return type:

UnstructuredMesh2D

Notes

Supported 2D element types: triangles and quadrangles of any order. Only the corner nodes are used - the solver is cell-centered finite volume, so a curved element becomes the straight-sided polygon through its corners, which is reported once per load as a UserWarning. Any element type that is neither a triangle nor a quadrangle is skipped, also with a warning.

BC tags follow the physical curve group tags sorted numerically: the group with the smallest tag becomes bc_tag 0, the next bc_tag 1, and so on. Boundary edges not belonging to any physical curve group default to 0.

Examples

In Gmsh (Python API):

import gmsh
gmsh.initialize()
gmsh.model.add("reactor")
core = gmsh.model.occ.addDisk(0, 0, 0, 100, 100)
gmsh.model.occ.synchronize()
gmsh.model.addPhysicalGroup(2, [core], tag=1, name="fuel")
boundary_curves = [t for _, t in gmsh.model.getBoundary([(2, core)])]
gmsh.model.addPhysicalGroup(1, boundary_curves, tag=10, name="vacuum")
gmsh.option.setNumber("Mesh.MeshSizeMax", 10.0)
gmsh.model.mesh.generate(2)
gmsh.write("reactor.msh")
gmsh.finalize()

import ndiffusion as nd
mesh = nd.load_gmsh("reactor.msh")