porepy.fracs.gmsh_interface module

Functionality to interface with Gmsh, mainly by translating information from a PorePy format to that used by the Gmsh Python API. For examples on how that can be used, see FractureNetwork2d and FractureNetwork3d.

Content:
Tags: Enum with fixed numerical representation of geometric objects. Used for tagging

geometric objects internally in PorePy.

PhysicalNames: Enum with fixed string representation of geometric objects. The

mesh generated by gmsh will use these to tag cells on geometric objcets.

GmshData1d, 2d, 3d: dataclasses for the specification of geometries in the various

dimensions.

GmshWriter: Interface to Gmsh. Takes a GmshData*d object and translates it to a

gmsh model. Can also mesh.

class GmshData1d(pts: 'np.ndarray', mesh_size: 'np.ndarray', lines: 'np.ndarray', physical_points: 'dict[int, Tags]', physical_lines: 'dict[int, Tags]', dim: 'int' = 1)[source]

Bases: _GmshData

Parameters:
dim: int
class GmshData2d(pts: 'np.ndarray', mesh_size: 'np.ndarray', lines: 'np.ndarray', physical_points: 'dict[int, Tags]', physical_lines: 'dict[int, Tags]', dim: 'int' = 2)[source]

Bases: _GmshData

Parameters:
dim: int
class GmshData3d(pts: 'np.ndarray', mesh_size: 'np.ndarray', lines: 'np.ndarray', physical_points: 'dict[int, Tags]', physical_lines: 'dict[int, Tags]', polygons: 'list[np.ndarray]', polygon_tags: 'dict[int, Tags]', physical_surfaces: 'dict[int, Tags]', lines_in_surface: 'list[list[int]]', dim: 'int' = 3)[source]

Bases: _GmshData

Parameters:
dim: int
lines_in_surface: list[list[int]]
physical_surfaces: dict[int, Tags]
polygon_tags: dict[int, Tags]
polygons: list[ndarray]
class GmshWriter(data)[source]

Bases: object

Interface to Gmsh’s python API.

The geometry specification (in the form of a GmshData object) is converted to a model (in the Gmsh sense) upon initiation of a GmshWriter. A mesh can then be constructed either by the method generate, or by directly working with the gmsh api in a client script.

Parameters:

data (Union[GmshData2d, GmshData3d])

define_geometry()[source]

Feed the geometry specified in self._data to gmsh.

Return type:

None

generate(file_name, ndim=-1, write_geo=False, clear_gmsh=True, finalize=True)[source]

Make gmsh generate a mesh and write it to specified mesh size.

The mesh is generated from the geometry specified in gmsh.model.

NOTE: We have experienced issues relating to memory leakages in gmsh which manifest when gmsh is initialized and finalized several times in a session. In these situation, best practice seems to be not to finalize gmsh after mesh generation (set finalize=False, but rather clear the gmsh model by setting clear_gmsh=True), and finalize gmsh from the outside.

Parameters:
  • file_name (str) – Name of the file. The suffix ‘.msh’ is added if necessary.

  • ndim (int, optional) – Dimension of the grid to be made. If not specified, the dimension of the data used to initialize this GmshWriter will be used.

  • write_geo (bool, optional) – If True, the geometry will be written before meshing. The name of the file will be file_name.geo_unrolled. Defaults to False.

  • clear_gmsh (bool, optional) – If True, the function gmsh.clear() is called after mesh generation. This will delete the geometry from gmsh.

  • finalize (bool, optional) – If True (default), the finalize method of the gmsh module is called after mesh generation. If set to False, gmsh should be finalized by a direct call to gmsh.finalize(); note however that if this is done, Gmsh cannot be accessed either from the outside or by an instance of the GmshWriter class before gmsh.initialize() is called.

Return type:

None

set_gmsh_options(options=None)[source]

Set Gmsh options. See Gmsh documentation for choices available.

Parameters:

options (dict) – Options to set. Keys should be recognizable for Gmsh.

Return type:

None

gmsh_initialized
class PhysicalNames(*values)[source]

Bases: Enum

String-based tags used to assign physical names (Gmsh jargon) to classes of objects in a mixed-dimensional geometry.

AUXILIARY_LINE
AUXILIARY_PLANE
DOMAIN
DOMAIN_BOUNDARY_LINE
DOMAIN_BOUNDARY_POINT
DOMAIN_BOUNDARY_SURFACE
FRACTURE
FRACTURE_BOUNDARY_LINE
FRACTURE_BOUNDARY_POINT
FRACTURE_CONSTRAINT_INTERSECTION_POINT
FRACTURE_INTERSECTION_LINE
FRACTURE_INTERSECTION_POINT
FRACTURE_TIP
class Tags(*values)[source]

Bases: Enum

Numerical tags used to identify special objects in a mixed-dimensional geometry. These may be mapped to the string-based tag system used in Gmsh (see PhysicalNames)

AUXILIARY_LINE
AUXILIARY_PLANE
DOMAIN_BOUNDARY_LINE
DOMAIN_BOUNDARY_POINT
DOMAIN_BOUNDARY_SURFACE
FRACTURE
FRACTURE_BOUNDARY_LINE
FRACTURE_BOUNDARY_POINT
FRACTURE_CONSTRAINT_INTERSECTION_POINT
FRACTURE_INTERSECTION_LINE
FRACTURE_INTERSECTION_POINT
FRACTURE_TIP
NEUTRAL