Mesh¶
pynumgeo.mesh
¶
Mesh container and conversions.
- :mod:
~pynumgeo.mesh.mesh— the container (:class:Mesh); - :mod:
~pynumgeo.mesh.topology— node layout, shape functions and faces of numgeo's elements; - :mod:
~pynumgeo.mesh.convert— node permutations from VTK/meshio, gmsh, Abaqus; choice of element types; - :mod:
~pynumgeo.mesh.meshio_adapter, :mod:~pynumgeo.mesh.freecad_adapter— meshio and FreeCAD meshes (both optional dependencies, imported when used); - :mod:
~pynumgeo.mesh.quality— element orientation (positive Jacobian).
ImportedMesh(mesh, node_ids, element_ids, ignored=dict())
dataclass
¶
A mesh built from another format, with the maps back to the original numbering.
Attributes:
| Name | Type | Description |
|---|---|---|
mesh |
Mesh
|
the numgeo mesh (node labels 1..n when built with |
node_ids |
IntArray
|
original id of numgeo node |
element_ids |
IntArray
|
original id of numgeo element |
ignored |
dict[str, int]
|
cell types left out as lower-dimensional (boundary) cells and how many. |
ElementBlock(type, labels, connectivity, options=list(), comment=None)
dataclass
¶
Elements of one type. connectivity[i] are node labels of element labels[i] in numgeo order.
options holds further *Element options as read (e.g. ("BI-QUADRATIC", None)).
ElementSet(name, kind='list', members=(lambda: np.zeros(0, dtype=np.int64))(), values=list(), internal=False, instance=None, comment=None)
dataclass
¶
Bases: _LabelSet
An element set (*Elset): element labels, or a query evaluated by numgeo.
Mesh()
¶
Nodes, element blocks, sets and surfaces of a deck (see module docstring).
node_count
property
¶
Number of nodes.
element_count
property
¶
Number of elements over all blocks.
element_labels
property
¶
All element labels in block order.
add_nodes(coords, labels=None)
¶
Append nodes; labels default to the next numbers after the current maximum.
add_elements(type, connectivity, labels=None, *, comment=None)
¶
Append a block of elements of one type; labels default to the next numbers.
add_nset(name, members, *, internal=False, comment=None)
¶
Add a node set given by node labels.
add_elset(name, members, *, internal=False, comment=None)
¶
Add an element set given by element labels.
add_surface(name, rows, type='element', *, comment=None)
¶
Add a surface: element-based rows (elset, "F1") or node-based rows (nset,).
nset(name)
¶
First node set of that name (numgeo also uses the first one).
elset(name)
¶
First element set of that name.
surface(name)
¶
First surface of that name.
find_nearest_node(point, candidates=None)
¶
Label of the node nearest to point as numgeo's find does (first minimum wins).
check()
¶
Problems that make numgeo fail or compute wrong results (empty list = fine).
Checks: node labels 1..n in order, unique element labels, connectivity refers to existing nodes, every node used by an element.
renumbered()
¶
Copy with node labels 1..n and element labels 1..m (block order).
Returns:
| Type | Description |
|---|---|
Mesh
|
|
IntArray
|
labels of new node |
summary()
¶
Counts and names, e.g. for agents (no arrays).
NodeSet(name, kind='list', members=(lambda: np.zeros(0, dtype=np.int64))(), values=list(), internal=False, instance=None, comment=None)
dataclass
¶
Bases: _LabelSet
A node set (*Nset): node labels, or a query evaluated by numgeo (find and variants).
Surface(name, type='element', rows=list(), comment=None)
dataclass
¶
A surface (*Surface).
type="element" rows are (elset, face), type="node" rows (nset,).
key
property
¶
Name as numgeo compares it.
Topology(name, shape, nnodes, dim, reference, corners, edges, face_centres, centre, vtk_type, meshio_type, source, _n)
dataclass
¶
Node layout of one numgeo element topology (independent of the formulation).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
pynumgeo name ( |
shape |
str
|
numgeo element shape ( |
nnodes |
int
|
number of nodes. |
dim |
int
|
dimension of the reference element (1, 2 or 3). |
reference |
tuple[tuple[float, ...], ...]
|
reference coordinates of nodes 1..n in numgeo's natural coordinates ( |
corners |
tuple[int, ...]
|
local numbers (1-based) of the corner nodes. |
edges |
tuple[tuple[int, ...], ...]
|
|
face_centres |
tuple[int, ...]
|
mid-face nodes (hex27 only). |
centre |
int | None
|
the interior node (quad9, hex27), else |
vtk_type |
int
|
VTK cell type with the same node layout. |
meshio_type |
str
|
meshio cell type name with the same node layout. |
source |
str
|
numgeo source lines of the shape functions that define the layout. |
order
property
¶
Polynomial order of the interpolation along an edge (1 or 2).
mid_nodes
property
¶
All nodes that are not corners (1-based).
centroid
property
¶
Reference coordinates of the element centre (where :mod:~pynumgeo.mesh.quality checks).
reference_array()
¶
:attr:reference as a (nnodes, dim) array.
shape_functions(xi)
¶
numgeo's shape functions N(1..n) at the natural coordinates xi.
topology("line3").shape_functions([0.0]).tolist() [-0.0, 0.0, 1.0]
shape_derivatives(xi)
¶
dN/dxi at xi as a (dim, nnodes) array (exact complex-step derivative of
:meth:shape_functions).
topology("quad4").shape_derivatives([0.0, 0.0]).tolist() [[-0.25, 0.25, 0.25, -0.25], [-0.25, -0.25, 0.25, 0.25]]
build_mesh(node_ids, coords, blocks, *, node_sets=None, element_sets=None, renumber=True, dim=None, ignored=None)
¶
Build a :class:~pynumgeo.mesh.mesh.Mesh from nodes and element blocks with arbitrary ids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_ids
|
ArrayLike
|
original node ids (unique integers). |
required |
coords
|
ArrayLike
|
|
required |
blocks
|
Sequence[tuple[str, ArrayLike, ArrayLike]]
|
|
required |
node_sets
|
Mapping[str, ArrayLike] | None
|
name -> original node ids. |
None
|
element_sets
|
Mapping[str, ArrayLike] | None
|
name -> original element ids (of elements in |
None
|
renumber
|
bool
|
|
True
|
dim
|
int | None
|
model dimension (2 or 3); default: the dimension of the element types. For a 2D model a
third coordinate must be zero (it is dropped; numgeo ignores it with a warning,
|
None
|
ignored
|
Mapping[str, int] | None
|
passed through to :attr: |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
unknown or unusable element types, a type that does not fit its cells, non-zero third coordinates in a 2D model, set members that are not part of the mesh. |
from_numgeo(convention, topology_name)
¶
Inverse of :func:to_numgeo: connectivity_in_convention = numgeo_connectivity[:, q].
from_numgeo("abaqus", "line3").tolist() [0, 2, 1]
numgeo_element_type(topology_name, dofs, *, ndim=None, axisymmetric=False, reduced=False, variant=None, stem=None, formulation=None)
¶
The one numgeo element type (lower case, as pynumgeo writes it) for a topology and formulation.
Filters the catalogue as :func:element_type_candidates does; returns the single match.
Raises:
| Type | Description |
|---|---|
ValueError
|
if no or more than one library entry matches (the message lists the candidates and the tokens that tell them apart). |
Examples:
>>> numgeo_element_type("tet10", ["U1", "U2", "U3"])
'u10-solid-3d'
>>> numgeo_element_type("quad4", ["U1", "U2"], variant=["SOLID"], axisymmetric=True, reduced=True)
'u4-solid-ax-red'
>>> numgeo_element_type("tri3", ["U1", "U2", "U3", "R1", "R2", "R3"], ndim=3)
'u3-shell'
permute(connectivity, convention, topology_name)
¶
Connectivity rows given in convention order, reordered to numgeo order.
to_numgeo(convention, topology_name)
¶
Permutation p (0-based) with numgeo_connectivity = connectivity[:, p].
Derived by matching the reference coordinates of convention with numgeo's
(:func:reference_coordinates).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convention
|
str
|
|
required |
topology_name
|
str
|
|
required |
to_numgeo("vtk", "hex27").tolist() == list(range(27)) True
femmesh_import(femmesh, element_types, *, length_scale, renumber=True, groups=True, dim=None)
¶
Like :func:mesh_from_femmesh, also returning the maps to FreeCAD's node and element ids.
mesh_from_femmesh(femmesh, element_types, *, length_scale, renumber=True, groups=True, dim=None)
¶
A numgeo mesh from a FreeCAD Fem::FemMesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
femmesh
|
FemMeshLike
|
the FemMesh (see the module docstring for the API used). |
required |
element_types
|
Mapping[str, str]
|
topology ( |
required |
length_scale
|
float
|
factor applied to FreeCAD's coordinates (mm): |
required |
renumber
|
bool
|
nodes 1..n (in the order of FreeCAD's node ids, unused nodes dropped) and elements 1..m in
block order (default); |
True
|
groups
|
bool
|
turn FemMesh groups into sets: node groups and the nodes of lower-dimensional groups become node sets, groups of mapped elements element sets. |
True
|
dim
|
int | None
|
model dimension; default from the element types. A 2D mesh must lie in the x-y plane (z = 0). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
invalid |
mesh_from_meshio(m, element_types, *, renumber=True, convention='vtk', dim=None)
¶
A numgeo mesh from a meshio.Mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
Any
|
the meshio mesh (anything with |
required |
element_types
|
Mapping[str, str]
|
meshio cell type (or pynumgeo topology name) -> numgeo element type, e.g.
|
required |
renumber
|
bool
|
drop unused points and label nodes 1..n / elements 1..m (default). With |
True
|
convention
|
str
|
node order of the cells: |
'vtk'
|
dim
|
int | None
|
model dimension; default from the element types. 2D models drop a zero third coordinate. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
see :func: |
mesh_to_meshio(mesh)
¶
A meshio.Mesh (VTK node order) from a numgeo mesh, e.g. to write VTU/XDMF for inspection.
Node sets become point_sets and element sets cell_sets (list and generate sets; sets that
numgeo evaluates itself — find, boundingbox, cylinder — cannot be represented and are left
out with a warning). cell_data["numgeo:label"] holds the element labels. Surfaces are not converted.
Raises:
| Type | Description |
|---|---|
KeyError
|
for an element type that is not in the catalogue. |
meshio_import(m, element_types, *, renumber=True, convention='vtk', dim=None)
¶
Like :func:mesh_from_meshio, also returning the maps to the meshio numbering.
ImportedMesh.node_ids[i] is the meshio point index of numgeo node i + 1;
ImportedMesh.element_ids[j] the index of the cell counted over all cell blocks.
element_faces(element_type)
¶
The face table numgeo uses for element-based surfaces of an element type.
This is the catalogue's surface_face_topology of the element type (the selection of
src/contacts/contact_.f90:553-610: 2D models by interpolation, 3D models by shape; triangles and
quadrilaterals in 3D models are shells with the faces F1 (side of the normal) and F2).
element_topology(element_type)
¶
The topology of a numgeo element type (library name or alias, any case).
Raises:
| Type | Description |
|---|---|
KeyError
|
if the element type is not in the catalogue. |
face_connectivity(element_type, connectivity, face)
¶
Global node labels of one face of each element (rows of connectivity in numgeo order).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_type
|
str
|
numgeo element type of the rows. |
required |
connectivity
|
ArrayLike
|
|
required |
face
|
str | int
|
|
required |
Returns:
| Type | Description |
|---|---|
IntArray
|
|