Helpers API¶
gmshparser.helpers contains two groups of functions: visualization adapters for 2D meshes and low-level line parsers used by section parsers.
get_triangles()¶
gmshparser.helpers.get_triangles(mesh)
¶
Return (X, Y, triangles) for three-node surface triangles.
Both :func:gmshparser.read meshes and compatibility
:func:gmshparser.parse meshes are accepted. Connectivity is converted to
zero-based indices into X and Y.
Source code in gmshparser/helpers.py
Returns (X, Y, triangles). Triangle connectivity contains zero-based indices into X and Y.
import matplotlib.pyplot as plt
from gmshparser.helpers import get_triangles
X, Y, triangles = get_triangles(mesh)
plt.triplot(X, Y, triangles)
Only two-dimensional Gmsh type-2 elements are included.
get_quads()¶
gmshparser.helpers.get_quads(mesh)
¶
Return (X, Y, quads) for four-node surface quadrilaterals.
Both modern and compatibility mesh objects are accepted. Connectivity is
converted to zero-based indices into X and Y.
Source code in gmshparser/helpers.py
Returns (X, Y, quads). Quad connectivity contains zero-based indices into X and Y.
from matplotlib.patches import Polygon
from gmshparser.helpers import get_quads
X, Y, quads = get_quads(mesh)
for quad in quads:
coordinates = [(X[index], Y[index]) for index in quad]
axes.add_patch(Polygon(coordinates, fill=False))
Only two-dimensional Gmsh type-3 elements are included.
get_elements_2d()¶
gmshparser.helpers.get_elements_2d(mesh)
¶
Return node coordinates, triangles, and quadrilaterals for plotting.
Connectivity in triangles and quads retains the original Gmsh node
tags. The function accepts both the modern and compatibility APIs.
Source code in gmshparser/helpers.py
Returns a dictionary rather than coordinate arrays:
from gmshparser.helpers import get_elements_2d
data = get_elements_2d(mesh)
nodes = data["nodes"]
triangles = data["triangles"]
quads = data["quads"]
node_ids = data["node_ids"]
nodesmaps original Gmsh node tags to(x, y)coordinates.trianglesandquadspreserve original node tags in their connectivity.node_idsis the sorted list of referenced node tags.
Do not unpack this helper as (X, Y, triangles, quads) and do not apply a -1 offset to its node tags.
Line parsers¶
gmshparser.helpers.parse_ints(io)
¶
gmshparser.helpers.parse_floats(io)
¶
Parse one required line from io as floating-point values.
These functions read one line from a text stream and convert its space-separated values. They are primarily parser-development utilities rather than application-level mesh APIs.