Meshing
Module: xfea.meshing.base
Meshing protocol for xfea plugins.
MeshResult
Section titled “MeshResult”MeshResult(
nodes: Sequence[Any],
elements: Sequence[Any],
groups: Mapping[str, Sequence[Any]] = <factory>,
metadata: Mapping[str, Any] = <factory>,
)
What a meshing plugin returns: the nodes and elements it made, and named sets of them.
Parameters
| Name | Type | Description |
|---|---|---|
| nodes | Sequence[Node] |
The nodes made. |
| elements | Sequence[ElementBase] |
The elements made, on those nodes. |
| groups | Mapping[str, Sequence], optional | Named sets to add to the part, each of nodes, elements, edges or faces only; empty by default. |
| metadata | Mapping[str, Any], optional | Information about the meshing (element order, sizes, …); empty by default. |
Mesher
Section titled “Mesher”Mesher(*args, **kwargs)
A meshing plugin: it turns a part’s base geometry into nodes and elements.
A plugin subclasses it, sets name and implements mesh(), and is
registered with algorithm().
Methods
mesh(model, **kwargs)→MeshResult
Mesh a part’s base geometry (or a geometry given directly) into nodes and elements.
Parameters
| Name | Type | Description |
|---|---|---|
| model | Part or geometry |
The part to mesh (its base geometry is read), or the geometry itself. |
| **kwargs | dict | The plugin’s options: the settings’ sizes and order, the section, and any of its own. |
Returns
| Name | Type | Description |
|---|---|---|
class:MeshResult |
The nodes, elements and named sets made; the part is not changed. |
MeshingSettings
Section titled “MeshingSettings”MeshingSettings(
min: Optional[float] = None,
max: Optional[float] = None,
optimize: Optional[int] = None,
verbose: Optional[bool] = False,
element_order: Optional[int] = None,
refine: Optional[list] = None,
divisions: Optional[int] = None,
**kwargs: Any,
)
How to mesh a part: element sizes (min, max) and element_order (1 linear, 2 quadratic).
These are the options every meshing plugin reads; a plugin’s own settings
class (xfea_gmsh.GmshMeshingSettings) adds its others. Plugins
subclass it without renaming its parameters.
Parameters
| Name | Type | Description |
|---|---|---|
| min | float, optional | The smallest element size, in length units, or None for the plugin’s default. |
| max | float, optional | The largest element size, in length units, or None for the plugin’s default. |
| optimize | int, optional | The plugin’s mesh optimisation setting (Gmsh’s Mesh.Optimize), or None for the plugin’s default. |
| verbose | bool, optional | Not used: the plugin’s output shows when xfea.config.settings.MESH_VERBOSE is True. |
| element_order | {1, 2}, optional | 1 for linear elements, 2 for quadratic ones (with midside nodes), or None for the plugin’s default. |
| refine | list of Refine, optional |
Where the mesh is finer: on what a Select picks (faces, edges, points of a STEP part, a surface mesh or lines), in a box or a ball. |
| divisions | int, optional | For a surface mesh or lines: keep the faces (the segments) as they are, each cut into divisions x divisions elements (divisions along a segment), quads staying quads. Sizes and refinements don’t apply. divisions=1: the mesh given is the mesh. |
| **kwargs | Ignored: options this class does not know are dropped, not passed to the plugin. |
Guidance (meshing)
maxsets the element size everywhere;refinemakes it finer where the answer is decided (holes, a joint, a support), so the rest stays coarse.- Quadratic elements (
element_order=2) for solids in bending: linear tetrahedra are far too stiff. - A plate from
Mesh.from_meshgrid:divisions=1keeps its quads; without it the surface is remeshed in triangles of the sizes asked for. - Give a plugin’s own options through its settings class (
GmshMeshingSettings(algorithm_3d=1)):MeshingSettingsdrops the options it does not know.
Methods
to_kwargs()→Mapping[str, Any]
The settings as keyword arguments for the plugin’s mesh, leaving out those that are None.
Returns
| Name | Type | Description |
|---|---|---|
| dict | min, max, algorithm_3d, optimize, element_order, refine (as plain data) and divisions, where set. |
validate()
Check the settings before meshing, raising ValueError if they are wrong; the base class checks nothing.
get_default_algorithm
Section titled “get_default_algorithm”get_default_algorithm() -> Optional[str]
The name of the meshing plugin used when none is named; None if no default is set.
set_default_algorithm
Section titled “set_default_algorithm”set_default_algorithm(name: str)
Set the meshing plugin used when none is named, by its name; None or “” clears it.
It does not check the name: set_algorithm() does.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The plugin’s registered name, e.g. "gmsh". |
Module: xfea.meshing.select
Parts of a geometry picked by their properties, and where the mesh is finer.
A STEP part has solids, faces, edges and points, each with properties: a
face is a plane with a normal, or a cylinder with an axis and a radius; an
edge is a straight line with a direction, or a circle. Select picks
them by those properties, never by their numbers, which change whenever the
CAD file does. A selection names a group of the meshed part’s nodes
(part.mesh(..., groups={"top": Select.faces(normal="+z")})) or says where
a Refine makes the mesh finer.
describe() lists a geometry’s entities with their properties, to see
what a selection can use, or what it picks.
GeometryEntity
Section titled “GeometryEntity”GeometryEntity(kind: str, id: int, type: str, properties: dict = <factory>)
A solid, face, edge or point of a geometry file, with its properties (from describe()).
Refine
Section titled “Refine”Refine(
on: Optional[Select] = None,
size: float = 0.0,
reach: Optional[float] = None,
box: Optional[Sequence[Sequence[float]]] = None,
ball: Optional[tuple] = None,
)
A finer mesh: size on what a selection picks (or in a box, or a ball), growing back to the part’s
size over reach.
Parameters
| Name | Type | Description |
|---|---|---|
| on | Select, optional | Where: faces, edges or points (the size grows with the distance from them), or solids (the size throughout). |
| size | float | The element size there. |
| reach | float, optional | How far the size takes to grow back to the part’s; 4 x size by default. |
| box | (low, high), optional | A box instead of a selection: size inside, growing back over reach outside (in_box()). |
| ball | (centre, radius), optional | A ball instead of a selection (around()). |
Methods
to_data()→dict
The refinement as plain data, as the meshing plugin reads it.
Select
Section titled “Select”Select(what: str, **conditions: Any)
Some of a geometry’s solids, faces, edges or points, picked by their properties.
Build one with solids(), faces(), edges(), points()
or holes(). Every condition given must hold. near keeps the
entity nearest a point (count of them), or with within all those
within that distance.
Guidance (selecting)
- Pick by properties, not
ids: the numbers change when the CAD file changes. Useidsonly to try something out withdescribe(). - Look at what a selection picks before meshing with it:
describe(geometry, select=...), or mesh and show the group it names.
Methods
to_data()→dict
The selection as plain data, as the meshing plugin reads it.
describe
Section titled “describe”describe(
geometry,
what: Optional[str] = None,
select: Optional[Select] = None,
) -> list[GeometryEntity]
The solids, faces, edges and points of a geometry file, with their properties.
Parameters
| Name | Type | Description |
|---|---|---|
| geometry | str or BaseGeometry or Part | A STEP (or BREP) file, a part’s base geometry, or the part. |
| what | {“solids”, “faces”, “edges”, “points”}, optional | One kind only; all by default. |
| select | Select, optional | Only what this selection picks: to check a selection before meshing with it. |
Returns
| Name | Type | Description |
|---|---|---|
| list[GeometryEntity] | Each with kind, id, type and its properties: a solid’s name and volume; a face’s area, center, normal (planes, outward), radius, axis, inner and around (round faces); an edge’s length, ends, direction (straight) or radius (circles), and the faces it borders; a point’s xyz. print gives one line each. |
© 2026 Francesco Ranaudo · Text and pictures CC BY 4.0 · Code Elastic License 2.0 · how to reuse them