Gmsh#

class pandamesh.gmsh_mesher.FieldCombination(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Controls how cell size fields are combined when they are found at the same location.

MAX = 'Max'#
MEAN = 'Mean'#
MIN = 'Min'#
class pandamesh.gmsh_mesher.GeneralVerbosity(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Level of information printed.

DEBUG = 99#
DIRECT = 3#
ERRORS = 1#
INFORMATION = 4#
SILENT = 0#
STATUS = 5#
WARNINGS = 2#
class pandamesh.gmsh_mesher.GmshMesher(gdf: GeoDataFrame)[source]#

Wrapper for the python bindings to Gmsh. This class must be initialized with a geopandas GeoDataFrame containing at least one polygon, and a column named "cellsize".

Optionally, multiple polygons with different cell sizes can be included in the geodataframe. These can be used to achieve local mesh remfinement.

Linestrings and points may also be included. The segments of linestrings will be directly forced into the triangulation. Points can also be forced into the triangulation. Unlike Triangle, the cell size values associated with these geometries will be used.

Gmsh cannot automatically resolve overlapping polygons, or points located exactly on segments. During initialization, the geometries of the geodataframe are checked:

  • Polygons should not have any overlap with each other.

  • Linestrings should not intersect each other.

  • Every linestring should be fully contained by a single polygon; a linestring may not intersect two or more polygons.

  • Linestrings and points should not “touch” / be located on polygon borders.

  • Holes in polygons are fully supported, but they must not contain any linestrings or points.

If such cases are detected, the initialization will error.

For more details on Gmsh, see: https://gmsh.info/doc/texinfo/gmsh.html

A helpful index can be found near the bottom: https://gmsh.info/doc/texinfo/gmsh.html#Syntax-index

add_distance_field(gdf: GeoDataFrame, minimum_cellsize: float) None[source]#

Add a distance field to the mesher.

The of geometry of these fields are not forced into the mesh, but they can be used to specify zones of with cell sizes.

Parameters:
  • gdf (geopandas.GeoDataFrame) – Location and cell size of the fields, as vector data.

  • minimum_cellsize (float) –

add_structured_field(cellsize: ndarray, xmin: float, ymin: float, dx: float, dy: float, outside_value: float | None = None) None[source]#

Add a structured field specifying cell sizes. Gmsh will interpolate between the points to determine the desired cell size.

Parameters:
  • cellsize (FloatArray with shape (n_y, n_x)) – Specifies the cell size on a structured grid. The location of this grid is determined by xmin, ymin, dx, dy.

  • xmin (float) – x-origin.

  • ymin (float) – y-origin.

  • dx (float) – Spacing along the x-axis.

  • dy (float) – Spacing along the y-axis.

  • outside_value (Union[float, None]) – Value outside of the window (xmin, xmax) and (ymin, ymax). Default value is None.

clear_fields() None[source]#

Clear all cell size fields from the mesher.

property field_combination#

Controls how cell size fields are combined when they are found at the same location. Can be set to one of pandamesh.FieldCombination:

MIN = "Min"
MAX = "Max"
MEAN = "Mean"
static finalize_gmsh()[source]#

Finalize Gmsh.

property force_geometry: bool#
property general_verbosity: GeneralVerbosity#
generate() Tuple[ndarray, ndarray][source]#

Generate a mesh of triangles or quadrangles.

Returns:

  • vertices (np.ndarray of floats with shape (n_vertex, 2))

  • faces (np.ndarray of integers with shape (n_face, nmax_per_face)) – nmax_per_face is 3 for exclusively triangles and 4 if quadrangles are included. A fill value of -1 is used as a last entry for triangles in that case.

generate_ugrid() xugrid.Ugrid2d[source]#
property mesh_algorithm#

Can be set to one of pandamesh.MeshAlgorithm:

MESH_ADAPT = 1
AUTOMATIC = 2
INITIAL_MESH_ONLY = 3
FRONTAL_DELAUNAY = 5
BAMG = 7
FRONTAL_DELAUNAY_FOR_QUADS = 8
PACKING_OF_PARALLELLOGRAMS = 9

Each algorithm has its own advantages and disadvantages.

property mesh_size_extend_from_boundary#

Forces the mesh size to be extended from the boundary, or not, per surface.

property mesh_size_from_curvature#

Automatically compute mesh element sizes from curvature, using the value as the target number of elements per 2 * Pi radians

property mesh_size_from_points#

Compute mesh element sizes from values given at geometry points.

property recombine_all#

Apply recombination algorithm to all surfaces, ignoring per-surface spec.

property subdivision_algorithm#

All meshes can be subdivided to generate fully quadrangular cells. Can be set to one of pandamesh.SubdivisionAlgorithm:

NONE = 0
ALL_QUADRANGLES = 1
BARYCENTRIC = 3
write(path: str | Path)[source]#

Write a gmsh .msh file

Parameters:

path (Union[str, pathlib.Path) –

class pandamesh.gmsh_mesher.MeshAlgorithm(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Each algorithm has its own advantages and disadvantages.

For all 2D unstructured algorithms a Delaunay mesh that contains all the points of the 1D mesh is initially constructed using a divide-and-conquer algorithm. Missing edges are recovered using edge swaps. After this initial step several algorithms can be applied to generate the final mesh:

  • The MeshAdapt algorithm is based on local mesh modifications. This technique makes use of edge swaps, splits, and collapses: long edges are split, short edges are collapsed, and edges are swapped if a better geometrical configuration is obtained.

  • The Delaunay algorithm is inspired by the work of the GAMMA team at INRIA. New points are inserted sequentially at the circumcenter of the element that has the largest adimensional circumradius. The mesh is then reconnected using an anisotropic Delaunay criterion.

  • The Frontal-Delaunay algorithm is inspired by the work of S. Rebay.

  • Other experimental algorithms with specific features are also available. In particular, Frontal-Delaunay for Quads is a variant of the Frontal-Delaunay algorithm aiming at generating right-angle triangles suitable for recombination; and BAMG allows to generate anisotropic triangulations.

For very complex curved surfaces the MeshAdapt algorithm is the most robust. When high element quality is important, the Frontal-Delaunay algorithm should be tried. For very large meshes of plane surfaces the Delaunay algorithm is the fastest; it usually also handles complex mesh size fields better than the Frontal-Delaunay. When the Delaunay or Frontal-Delaunay algorithms fail, MeshAdapt is automatically triggered. The Automatic algorithm uses Delaunay for plane surfaces and MeshAdapt for all other surfaces.

AUTOMATIC = 2#
BAMG = 7#
FRONTAL_DELAUNAY = 5#
FRONTAL_DELAUNAY_FOR_QUADS = 8#
INITIAL_MESH_ONLY = 3#
MESH_ADAPT = 1#
PACKING_OF_PARALLELLOGRAMS = 9#
class pandamesh.gmsh_mesher.SubdivisionAlgorithm(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

All meshes can be subdivided to generate fully quadrangular cells.

ALL_QUADRANGLES = 1#
BARYCENTRIC = 3#
NONE = 0#
pandamesh.gmsh_mesher.coerce_field(field: dict | str) dict[source]#
pandamesh.gmsh_mesher.gmsh_env()[source]#