Session — apeGmsh¶
The top-level session object. Owns a single Gmsh kernel and wires
all composites (model, mesh, parts, constraints, loads,
masses, …). The OpenSees bridge is not a session composite —
import it explicitly via from apeGmsh.opensees import apeSees.
Package¶
apeGmsh ¶
apeGmsh — Gmsh wrapper for structural FEM workflows.¶
Composition-based API with sub-composites for focused surfaces:
-
Standalone (single-model, quick prototyping)::
from apeGmsh import apeGmsh
g = apeGmsh(model_name="plate", verbose=True) g.begin() p = g.model.geometry.add_point(0, 0, 0) ... g.end()
-
Multi-part (assembly workflow via
g.parts)::from apeGmsh import apeGmsh, Part
web = Part("web") web.begin() web.model.geometry.add_box(0, 0, 0, 1, 0.5, 10) web.save("web.step") web.end()
g = apeGmsh(model_name="bridge") g.begin() g.parts.add(web, label="web") g.parts.fragment_all() g.constraints.equal_dof("web", "slab", tolerance=1e-3) with g.loads.pattern("dead"): g.loads.gravity("web", g=(0, 0, -9.81), density=7850) g.masses.volume("web", density=7850) g.mesh.generation.generate(dim=3) fem = g.mesh.queries.get_fem_data(dim=3) g.end()
-
Persisted session (autosave + resume across scripts)::
from apeGmsh import apeGmsh, FEMData
# Build once and autosave on context-manager exit. with apeGmsh(model_name="plate", save_to="plate.h5") as g: g.model.geometry.add_box(0, 0, 0, 1, 1, 0.1, label="body") g.physical.add_volume("body", name="body") g.mesh.generation.generate(dim=3)
# Resume in a later script — symmetric load. fem = FEMData.from_h5("plate.h5")
apeGmsh ¶
apeGmsh(*, model_name: str = 'ModelName', verbose: bool = False, save_to: str | Path | None = None, overwrite: bool = True)
Bases: _SessionBase
Standalone single-model Gmsh session with all composites.
Parameters¶
model_name : str
Name passed to gmsh.model.add().
verbose : bool
If True, composites print diagnostic messages.
Source code in src/apeGmsh/_core.py
save ¶
Write the neutral-zone model.h5 for this session.
Persists what the session knows about the model: nodes,
elements, physical groups, labels, constraints, loads, masses.
Downstream solver enrichment (e.g. apeSees(fem).h5(p)) is
a separate user-driven action and not invoked here.
Parameters¶
path : str, Path, or None
Destination file. None (default) uses the save_to
given to the constructor. Raises if neither is set.
Returns the resolved path.
Source code in src/apeGmsh/_core.py
Part ¶
Bases: _SessionBase
An isolated geometry unit — no meshing, no physical groups.
Parameters¶
name : str
Descriptive name (also used as the Gmsh model name).
auto_persist : bool, default True
When True, the Part writes its geometry to an OS tempfile
on end() if save() was not called explicitly. The
tempfile is reclaimed via weakref.finalize when the
Part is garbage-collected, or eagerly via cleanup().
Set to False to opt out — in that case parts.add(part)
will raise FileNotFoundError unless you called save()
by hand.
Source code in src/apeGmsh/core/Part.py
begin ¶
Open the Part's Gmsh session.
If the Part is being reused — a previous with part: block
auto-persisted a tempfile and this call re-enters — the stale
tempfile is cleaned up before the new session starts so the
next end() can auto-persist fresh geometry.
Source code in src/apeGmsh/core/Part.py
end ¶
Close the Part's Gmsh session.
When auto_persist=True and the user did not call
save() inside the session, the geometry is written to
an OS tempfile before Gmsh is finalised so the Part can
flow straight into assembly.parts.add(part).
Exceptions raised by auto-persist itself are caught and emitted as a warning rather than masking any exception the user's build code may have raised. Gmsh finalisation always runs.
Source code in src/apeGmsh/core/Part.py
cleanup ¶
Delete any auto-persisted tempfile now, without waiting for garbage collection.
Safe to call multiple times. Safe to call on a Part whose
file_path was set by explicit save() — the
_owns_file guard means the user's file is never
touched. After cleanup(), has_file returns False
and the Part can be re-built via a new with block.
Source code in src/apeGmsh/core/Part.py
save ¶
save(file_path: str | Path | None = None, *, fmt: str | None = None, write_anchors: bool = True, _internal_autopersist: bool = False) -> Path
Export the Part geometry to a CAD file.
Calling save() with a user-supplied path transfers
ownership of the output file to the caller — any
tempfile previously created by auto-persist is cleaned up
immediately, and the library will never delete the new
output.
Parameters¶
file_path : str, Path, or None
Destination path. If None, defaults to
"{name}.step". The extension determines the format
unless fmt overrides it.
fmt : str, optional
Force format: "step" or "iges".
write_anchors : bool, default True
Write a JSON sidecar ({file_path}.apegmsh.json)
carrying the label -> center-of-mass map for every
user-named entity in the Part. This is what lets
assembly.parts.add(part) expose the instance's
labels via inst.by_label('name'). The sidecar is
silently omitted when the Part has no user-named
entities, so there is no cost for small throwaway
Parts. Pass write_anchors=False to suppress
unconditionally — useful when publishing a CAD file
to third-party tools that shouldn't see apeGmsh
metadata.
Returns¶
Path Resolved path of the written file.
Source code in src/apeGmsh/core/Part.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
PartsRegistry ¶
Bases: _PartsFragmentationMixin
Instance management composite — registered as g.parts.
Source code in src/apeGmsh/core/_parts_registry.py
part ¶
Track entities created inside the block as a named part.
Yields the label string. After the block, any entities that exist now but didn't before are stored as an Instance.
Example::
with g.parts.part("beam"):
g.model.geometry.add_box(0, 0, 0, 1, 0.5, 10)
Source code in src/apeGmsh/core/_parts_registry.py
register ¶
register(name: str, dimtags: list[DimTag] | None = None, *, label: str | None = None, pg: str | None = None, dim: int | None = None) -> Instance
Tag existing entities under a part name.
Exactly one of dimtags, label, or pg must be given.
Parameters¶
name : str
Unique part name.
dimtags : list of (dim, tag), optional
Entities to assign directly. Also accepted positionally
as the second argument.
label : str, optional
Name of an apeGmsh label (g.labels) whose entities
should be adopted.
pg : str, optional
Name of a physical group (g.physical) whose entities
should be adopted.
dim : int, optional
Forwarded to g.labels.entities(label, dim=dim) when
using label= and the label spans multiple dimensions.
Returns¶
Instance
Source code in src/apeGmsh/core/_parts_registry.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
from_model ¶
Adopt entities already in the Gmsh session as a named part.
Useful after g.model.io.load_step() or g.model.io.load_iges()
when you want the imported geometry tracked for constraints
and fragmentation.
Parameters¶
label : str Part name. dim : int, optional Dimension to adopt. If None, adopts all dimensions. tags : list[int], optional Specific entity tags to adopt. If None, adopts all untracked entities (not already assigned to a part).
Returns¶
Instance
Examples¶
::
# Load geometry, then adopt it
g.model.io.load_step("bracket.step")
g.parts.from_model("bracket")
# Adopt only specific volumes
g.parts.from_model("slab", dim=3, tags=[1, 2])
Source code in src/apeGmsh/core/_parts_registry.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
add ¶
add(part: 'Part', *, label: str | None = None, translate: tuple[float, float, float] = (0.0, 0.0, 0.0), rotate: tuple[float, ...] | None = None, highest_dim_only: bool = True) -> Instance
Import a saved Part into the session.
Parameters¶
part : Part
Must have been save()-d to disk.
label : str, optional
Auto-generated as "{part.name}_1" if omitted.
translate, rotate : placement transforms.
highest_dim_only : keep only highest-dim entities from the CAD.
Source code in src/apeGmsh/core/_parts_registry.py
import_step ¶
import_step(file_path: str | Path, *, label: str | None = None, translate: tuple[float, float, float] = (0.0, 0.0, 0.0), rotate: tuple[float, ...] | None = None, highest_dim_only: bool = True, properties: dict[str, Any] | None = None) -> Instance
Import a STEP or IGES file as a named instance.
Parameters¶
file_path : path STEP (.step, .stp) or IGES (.iges, .igs) file. label : str, optional Auto-generated from file stem if omitted. translate, rotate : placement transforms. properties : arbitrary metadata.
Source code in src/apeGmsh/core/_parts_registry.py
build_node_map ¶
Partition mesh nodes by instance bounding box.
Returns {label: {node_tag, ...}}.
Source code in src/apeGmsh/core/_parts_registry.py
build_face_map ¶
Partition surface elements by instance node ownership.
Returns {label: face_connectivity_array}.
Source code in src/apeGmsh/core/_parts_registry.py
get ¶
Return the Instance registered under label.
Useful when you didn't store the return value of
:meth:add / :meth:import_step and want to access an
Instance later — e.g. to apply inst.edit.* transforms::
g.parts.add(beam, label="b1")
g.parts.get("b1").edit.translate(0, 0, 50)
Raises¶
KeyError
If no instance is registered under label. The error
message lists the available labels so you can spot a typo.
Source code in src/apeGmsh/core/_parts_registry.py
labels ¶
rename ¶
Rename an instance.
Raises¶
KeyError if old_label does not exist. ValueError if new_label already exists.
Source code in src/apeGmsh/core/_parts_registry.py
delete ¶
Remove an instance from the registry.
The entities remain in the Gmsh session — they become "untracked" and will appear under the Untracked group in the viewer's Parts tab.
Raises¶
KeyError if label does not exist.
Source code in src/apeGmsh/core/_parts_registry.py
Instance
dataclass
¶
Instance(label: str, part_name: str, file_path: Path | None = None, entities: dict[int, list[int]] = dict(), translate: tuple[float, float, float] = (0.0, 0.0, 0.0), rotate: tuple[float, ...] | None = None, properties: dict[str, Any] = dict(), bbox: tuple[float, float, float, float, float, float] | None = None, label_names: list[str] = list())
Bookkeeping record for one part placement.
Attributes¶
label : unique name inside the session
part_name : name of the source Part or file stem
file_path : CAD file that was imported (None for inline parts)
entities : {dim: [tag, ...]} — updated in-place by fragment
translate : applied translation (dx, dy, dz)
rotate : applied rotation (angle_rad, ax, ay, az[, cx, cy, cz])
properties : arbitrary user metadata
bbox : axis-aligned bounding box (xmin, ymin, zmin, xmax, ymax, zmax)
label_names : label names created for this instance (Tier 1
naming, e.g. ["col_A.shaft", "col_A.top"]).
Populated by _import_cad when the Part's CAD
file has a .apegmsh.json sidecar carrying
label definitions. These are NOT solver-facing
physical groups — use g.labels.entities(name)
to resolve entity tags, and
g.labels.promote_to_physical(name) to create
a solver PG when ready.
ConstraintsComposite ¶
Solver-agnostic kinematic-constraint composite — declare on geometry, resolve to nodes after meshing.
Two-stage pipeline¶
- Declare (pre-mesh): the factory methods on this composite
(
equal_dof,rigid_link,rigid_diaphragm,tie, …) store :class:~apeGmsh.solvers.Constraints.ConstraintDefdataclasses describing intent at the geometry level. Defs carry no node tags and survive remeshing. - Resolve (post-mesh): :meth:
resolve(called automatically by :meth:Mesh.queries.get_fem_data) walks the def list and hands each one to :class:~apeGmsh.solvers.Constraints.ConstraintResolver, which produces concrete :class:~apeGmsh.solvers.Constraints.ConstraintRecordobjects — actual node tags, weights, and offset vectors.
The resolved records land on the FEM broker:
- node-pair / node-group / node_to_surface records →
fem.nodes.constraints - surface-coupling / interpolation records →
fem.elements.constraints
Constraint taxonomy¶
Five tiers, ordered by topology and the role each plays in a structural model:
============= ===================================================== =================================
Tier Methods Record family
============= ===================================================== =================================
1 — Pair :meth:equal_dof, :meth:rigid_link, NodePairRecord
:meth:penalty
2 — Group :meth:rigid_diaphragm, :meth:rigid_body, NodeGroupRecord
:meth:kinematic_coupling
2b — Mixed :meth:node_to_surface, NodeToSurfaceRecord
:meth:node_to_surface_spring (+ phantom nodes)
3 — Surface :meth:tie, :meth:distributing_coupling, InterpolationRecord
:meth:embedded
4 — Contact :meth:tied_contact, :meth:mortar SurfaceCouplingRecord
============= ===================================================== =================================
All constraints ultimately express the linear MPC equation
u_slave = C · u_master. Tiers differ in how C is
built — by node co-location (Tier 1), kinematic transformation
around a master point (Tier 2), shape-function interpolation
(Tier 3), or numerical integration on the interface (Tier 4).
Target identification¶
Most methods identify their master and slave sides by part
label (a key of g.parts._instances). :meth:_add_def
validates both labels against the registry and raises
KeyError on a typo::
g.constraints.tie(master_label="column",
slave_label="slab",
master_entities=[(2, 13)], # optional scope
slave_entities=[(2, 17)])
Optional master_entities / slave_entities (list of
(dim, tag)) narrow the search to a subset of the part's
entities — useful when a part has many surfaces and only one is
the interface.
Exceptions to the part-label scheme ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- :meth:
node_to_surfaceand :meth:node_to_surface_springtake bare tags instead. Themasteris a Gmsh point entity (dim=0) andslaveis one or more surface entities (dim=2). Both arguments acceptint,str, or(dim, tag); label validation is skipped. - :meth:
embeddeduseshost_label/embedded_labelto mirror the host/embedded vocabulary, but the lookup logic otherwise matches the part-label scheme.
Resolution semantics¶
:meth:resolve is dependency-injected — it never imports
PartsRegistry. The caller (typically
Mesh.queries.get_fem_data) supplies:
node_map:{part_label → set[int]}of mesh node tagsface_map:{part_label → ndarray(F, n_per_face)}built only when surface constraints (Tier 3 / 4) are present.
See Also¶
apeGmsh.solvers.Constraints :
Module-level taxonomy and theory.
apeGmsh.solvers._constraint_defs :
Stage-1 dataclasses with full per-method theory.
apeGmsh.solvers._constraint_resolver.ConstraintResolver :
Stage-2 implementation.
apeGmsh.mesh._record_set.NodeConstraintSet :
Iteration helpers (rigid_link_groups, equal_dofs,
rigid_diaphragms, pairs).
Examples¶
Declare a mix of constraints, mesh, and read out grouped rigid-link masters for OpenSees emission::
with apeGmsh(model_name="frame") as g:
# Tier 1 — co-located nodes share x/y/z
g.constraints.equal_dof("col", "beam", dofs=[1, 2, 3])
# Tier 2 — slab nodes follow the centre-of-mass node
g.constraints.rigid_diaphragm(
"slab", "slab_master",
master_point=(2.5, 2.5, 3.0),
plane_normal=(0, 0, 1),
)
# Tier 3 — non-matching shell-to-solid interface
g.constraints.tie(
"shell", "solid",
master_entities=[(2, 17)],
slave_entities=[(2, 41)],
)
g.mesh.generation.generate(dim=3)
fem = g.mesh.queries.get_fem_data(dim=3)
for master, slaves in fem.nodes.constraints.rigid_link_groups():
for slave in slaves:
ops.rigidLink("beam", master, slave)
Source code in src/apeGmsh/core/ConstraintsComposite.py
bc ¶
Homogeneous single-point constraint — fix a pattern to ground.
The natural (essential / Dirichlet) boundary condition: every
mesh node in the resolved pattern gets ops.fix(node, *mask)
downstream. There is no master and no slave — unlike every
other method on this composite, this is a constraint to
ground, not between two parts. It resolves into
fem.nodes.sp (homogeneous :class:SPRecord\ s) — the same
broker channel as :meth:g.loads.face_sp — not
fem.nodes.constraints.
Because it is a permanent constraint (not a pattern-scoped
quantity), it lives here on g.constraints rather than on
g.loads: there is no load-pattern context to accidentally
scope it into, and the downstream emitter places it in the
model → bcs → patterns deck order via ops.fix.
Parameters¶
target : str or list[(dim, tag)]
Pattern to fix. Resolved label → physical group → raw
tags (or a mesh selection) — the same flexible target
model as :meth:g.loads.face_sp. Pass pg= / label=
/ tag= instead to force a specific resolution path.
dofs : list[int], optional
Restraint mask (1 = constrained, 0 = free), in
DOF order [ux, uy, uz, rx, ry, rz]. Default
[1, 1, 1] (pin all translations). This is the
OpenSees ops.fix / face_sp convention — not
the index-list convention used by
:meth:equal_dof (dofs=[1,2,3]).
name : str, optional
Friendly name shown in summaries / the viewer.
Returns¶
BCDef
The stored definition; the same object is appended to
self._bc_defs.
Warnings¶
Resolution is dimension-agnostic — a point, edge, surface, or volume pattern all just contribute their mesh nodes. Pointing a BC at a volume physical group therefore fixes every interior node of the solid, which is almost never intended; target a boundary surface/edge instead.
Examples¶
::
g.constraints.bc("base_face") # pin x,y,z
g.constraints.bc(pg="Supports", dofs=[1, 1, 0])
g.constraints.bc(label="col.base",
dofs=[1, 1, 1, 1, 1, 1]) # full fixity
Source code in src/apeGmsh/core/ConstraintsComposite.py
resolve_bcs ¶
Resolve every :meth:bc def to homogeneous SPRecord\ s.
Mirrors the load/SP resolution path: each BCDef target is
run through the loads composite's dimension-agnostic
_target_nodes (label → PG → tag → mesh-selection, any
dim), then one SPRecord(value=0.0, is_homogeneous=True) is
emitted per restrained DOF per node.
Fails loud — consistent with :meth:_resolve_nodes and the
resolver contract — if a pattern resolves to zero mesh nodes:
a BC that silently binds nothing is worse than one that errors.
Source code in src/apeGmsh/core/ConstraintsComposite.py
equal_dof ¶
equal_dof(master_label, slave_label, *, master_entities=None, slave_entities=None, dofs=None, tolerance=1e-06, name=None) -> EqualDOFDef
Tie matching DOFs between co-located node pairs.
At resolution time the resolver finds every master node
whose coordinates match a slave node within tolerance
and emits one
:class:~apeGmsh.solvers.Constraints.NodePairRecord per
match. Each pair becomes ops.equalDOF(master, slave, *dofs)
downstream — i.e. u_slave[i] = u_master[i] for every
i in dofs.
Use this for conformal interfaces only — meshes that share
nodes at the boundary. For non-matching meshes use :meth:tie.
Parameters¶
master_label : str
Part label whose nodes drive the constraint.
slave_label : str
Part label whose matching nodes are slaved.
master_entities, slave_entities : list of (dim, tag), optional
Restrict the node search to specific Gmsh entities of
each side. Useful when only one face of a multi-face
part is the interface.
dofs : list[int], optional
1-based DOF indices to constrain (1=ux, 2=uy, 3=uz,
4=rx, 5=ry, 6=rz). None (default) means all DOFs
available — the actual count depends on the model's
ndf.
tolerance : float, default 1e-6
Maximum distance (in model units) between two nodes for
them to be treated as co-located. Unit-sensitive:
1e-3 for millimetre models, 1e-6 for metre
models.
name : str, optional
Friendly name shown in :meth:summary and the viewer.
Returns¶
EqualDOFDef
The stored definition; the same object is appended to
self.constraint_defs.
Raises¶
KeyError
If master_label or slave_label is not in
g.parts.
See Also¶
tie : Non-matching mesh equivalent (shape-function projection). rigid_link : Add a kinematic offset on top of co-location.
Examples¶
Translational continuity between a column and a beam at a joint::
g.constraints.equal_dof(
"column", "beam",
dofs=[1, 2, 3],
tolerance=1e-3, # mm model
)
Source code in src/apeGmsh/core/ConstraintsComposite.py
rigid_link ¶
rigid_link(master_label, slave_label, *, link_type='beam', master_point=None, slave_entities=None, tolerance=1e-06, name=None) -> RigidLinkDef
Rigid bar between a master node and one or more slave nodes.
Each slave node is constrained to follow the master through
a rigid offset arm r = x_slave − x_master::
link_type="beam": u_s = u_m + θ_m × r, θ_s = θ_m
link_type="rod": u_s = u_m + θ_m × r, θ_s free
Use "beam" for fully rigid kinematic offsets (eccentric
connections, lumped-mass arms, fictitious rigid extensions).
Use "rod" when you want to transmit translation but leave
the slave free to rotate — e.g. pinned eccentric supports.
Parameters¶
master_label : str
Part label that owns the master node. The master is
identified inside this part either by master_point
(proximity match) or by being the unique node when the
part collapses to a single point.
slave_label : str
Part label whose nodes become slaves.
link_type : "beam" or "rod", default "beam"
"beam" couples 6 DOFs with rotational offset;
"rod" couples translations only.
master_point : (x, y, z), optional
Explicit master coordinates. If None, the resolver
picks the master node by proximity within tolerance.
slave_entities : list of (dim, tag), optional
Restrict the slave node search to specific entities.
tolerance : float, default 1e-6
Proximity tolerance for master-node detection.
name : str, optional
Friendly name.
Returns¶
RigidLinkDef
Raises¶
KeyError
If either label is not in g.parts.
See Also¶
kinematic_coupling : Same idea, but lets you pick which DOFs to couple instead of the fixed beam/rod sets. node_to_surface : When the slave side has only translational DOFs (3-DOF solid nodes).
Examples¶
Lumped-mass arm at the top of a tower::
g.constraints.rigid_link(
"tower_top", "lumped_mass",
link_type="beam",
master_point=(0, 0, 30.0),
)
Source code in src/apeGmsh/core/ConstraintsComposite.py
penalty ¶
penalty(master_label, slave_label, *, stiffness=10000000000.0, dofs=None, tolerance=1e-06, name=None) -> PenaltyDef
Soft-spring (penalty) coupling between co-located node pairs.
Numerically approximates :meth:equal_dof as
stiffness → ∞. The resolver still requires master and
slave nodes to be co-located within tolerance, but
downstream the constraint is enforced by inserting a stiff
spring element between each pair instead of a hard MPC.
Use this when:
- The hard
equal_dofconstraint causes the constraint-handler to ill-condition the reduced stiffness matrix (typical with mismatched DOF spaces). - You want a tunable interface compliance — e.g. a soft contact at a bearing pad.
Parameters¶
master_label : str
Part label of the master side.
slave_label : str
Part label of the slave side.
stiffness : float, default 1e10
Penalty spring stiffness in force/length units. Pick
~3–6 orders of magnitude above the stiffest neighbouring
element diagonal — overshoot causes ill-conditioning,
undershoot leaks displacement.
dofs : list[int], optional
1-based DOFs to penalise. None = all available.
tolerance : float, default 1e-6
Spatial co-location tolerance.
name : str, optional
Friendly name.
Returns¶
PenaltyDef
Raises¶
KeyError
If either label is not in g.parts.
See Also¶
equal_dof : Hard MPC equivalent (no tunable stiffness).
Source code in src/apeGmsh/core/ConstraintsComposite.py
rigid_diaphragm ¶
rigid_diaphragm(master_label, slave_label, *, master_point=(0.0, 0.0, 0.0), plane_normal=(0.0, 0.0, 1.0), constrained_dofs=None, plane_tolerance=1.0, name=None) -> RigidDiaphragmDef
In-plane rigid floor — slaves follow master in the diaphragm plane.
Classic use: each floor of a multi-storey building. All
slab nodes within plane_tolerance of the diaphragm
plane share in-plane translation and rotation about the
out-of-plane axis with the master node, while remaining
free in the out-of-plane direction.
Resolution emits a single
:class:~apeGmsh.solvers.Constraints.NodeGroupRecord
with one master and many slaves. Downstream this becomes
ops.rigidDiaphragm(perpDirn, master, *slaves).
Parameters¶
master_label : str
Part label that contains (or whose proximity will
select) the master node — typically a centre-of-mass
point.
slave_label : str
Part label whose nodes are gathered into the diaphragm.
master_point : (x, y, z), default (0, 0, 0)
Coordinates of the master node. Used to disambiguate
when the master part has more than one node.
plane_normal : (nx, ny, nz), default (0, 0, 1)
Unit normal to the diaphragm plane. (0, 0, 1) is a
horizontal floor; (0, 1, 0) is a vertical wall, etc.
constrained_dofs : list[int], optional
DOFs slaved to the master. Default for a horizontal
floor (Z up) is [1, 2, 6] — ux, uy, rz. For a
vertical wall use [1, 3, 5].
plane_tolerance : float, default 1.0
Perpendicular distance (in model units) from the
diaphragm plane within which a slave node is
collected. Unit-sensitive — set this to a fraction
of slab thickness.
name : str, optional
Friendly name.
Returns¶
RigidDiaphragmDef
Raises¶
KeyError
If either label is not in g.parts.
See Also¶
kinematic_coupling : When you need a different DOF subset
than [1, 2, 6] and don't need plane filtering.
rigid_body : When all 6 DOFs must follow the master.
Examples¶
A horizontal slab at z = 3.0 m::
g.constraints.rigid_diaphragm(
"slab", "slab_master",
master_point=(2.5, 2.5, 3.0),
plane_normal=(0, 0, 1),
constrained_dofs=[1, 2, 6],
plane_tolerance=0.05,
)
Source code in src/apeGmsh/core/ConstraintsComposite.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
rigid_body ¶
Fully rigid cluster — every slave DOF follows the master.
All six DOFs (ux, uy, uz, rx, ry, rz) of every node in
the slave part follow the master node through a rigid
transformation::
u_s = u_m + θ_m × (x_s − x_m)
θ_s = θ_m
Use this for genuinely rigid pieces (bearing blocks, lumped rigid masses) where the slave region must not deform.
Parameters¶
master_label : str Part label that contains (or whose proximity selects) the master node. slave_label : str Part label whose nodes are gathered into the rigid body. master_point : (x, y, z), default (0, 0, 0) Coordinates of the master node. name : str, optional Friendly name.
Returns¶
RigidBodyDef
Raises¶
KeyError
If either label is not in g.parts.
See Also¶
kinematic_coupling : Same topology but with a user-selectable DOF subset. rigid_diaphragm : In-plane variant with plane filtering.
Source code in src/apeGmsh/core/ConstraintsComposite.py
kinematic_coupling ¶
kinematic_coupling(master_label, slave_label, *, master_point=(0.0, 0.0, 0.0), dofs=None, name=None) -> KinematicCouplingDef
Generalised one-master-many-slaves coupling on a chosen DOF subset.
The "parent" of :meth:rigid_diaphragm and :meth:rigid_body
— they are special cases with pre-set DOF lists. Use this
directly when you need a non-standard combination, e.g.::
* vertical-only follower: dofs=[3]
* 2-D in-plane rigid: dofs=[1, 2, 6]
* symmetry plane: dofs=[1, 4, 5]
Resolution emits a single
:class:~apeGmsh.solvers.Constraints.NodeGroupRecord.
Downstream this is typically expanded to one
ops.equalDOF per slave.
Parameters¶
master_label : str
Part label that owns the master node.
slave_label : str
Part label whose nodes are slaved.
master_point : (x, y, z), default (0, 0, 0)
Coordinates of the master node.
dofs : list[int], optional
1-based DOFs to couple. Default [1, 2, 3, 4, 5, 6]
(full 6-DOF, equivalent to :meth:rigid_body).
name : str, optional
Friendly name.
Returns¶
KinematicCouplingDef
Raises¶
KeyError
If either label is not in g.parts.
Source code in src/apeGmsh/core/ConstraintsComposite.py
tie ¶
tie(master_label, slave_label, *, master_entities=None, slave_entities=None, dofs=None, tolerance=1.0, name=None) -> TieDef
Non-matching mesh tie via shape-function interpolation.
For each slave node, the resolver finds the closest master element face, projects the node onto it, and constrains its DOFs to the master corner DOFs through that face's shape functions::
u_slave = Σ N_i(ξ, η) · u_master_i
where (ξ, η) are the projected parametric coordinates
and N_i are the master face's shape functions (tri3,
quad4, tri6, quad8 supported). This is what Abaqus
*TIE does — it preserves displacement continuity across
non-matching meshes.
Resolution emits one
:class:~apeGmsh.mesh.records.InterpolationRecord per
successfully projected slave node. Downstream the apeGmsh
OpenSees bridge emits these as ASDEmbeddedNodeElement
penalty elements (default K = 1e18; tunable on the bridge
ingest API).
Parameters¶
master_label : str
Part label of the master surface (the side whose mesh
will provide the shape functions).
slave_label : str
Part label of the slave surface (whose nodes are
projected).
master_entities : list of (dim, tag), optional
Restrict the master surface to specific Gmsh
entities. Strongly recommended when the master
part has more than one face.
slave_entities : list of (dim, tag), optional
Restrict the slave surface to specific entities.
dofs : list[int], optional
DOFs to tie. None (default) ties all translational
DOFs available — typically [1, 2, 3].
tolerance : float, default 1.0
Maximum allowed projection distance from a slave node
to the master surface. Slave nodes farther than this
are silently skipped — set generously if the two
meshes have a small geometric gap, but not so large
that the wrong face is selected. Unit-sensitive.
name : str, optional
Friendly name.
Returns¶
TieDef
Raises¶
KeyError
If either label is not in g.parts.
See Also¶
equal_dof : Conformal-mesh equivalent (no interpolation). tied_contact : Bidirectional surface-to-surface tie. mortar : Higher-accuracy variant via Lagrange multipliers.
Notes¶
Master/slave choice matters for accuracy. As a rule:
- The master should have the finer mesh (more shape functions to project onto).
- The slave should have the coarser mesh (fewer projection operations).
Examples¶
Shell-to-solid tie at a column-top interface::
g.constraints.tie(
"shell_floor", "solid_column",
master_entities=[(2, 17)], # column top face
slave_entities=[(2, 41)], # shell bottom face
tolerance=5.0, # mm gap
)
Source code in src/apeGmsh/core/ConstraintsComposite.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 | |
distributing_coupling ¶
distributing_coupling(master_label, slave_label, *, master_point=(0.0, 0.0, 0.0), dofs=None, weighting='uniform', name=None) -> DistributingCouplingDef
Not implemented — raises NotImplementedError.
A true distributing coupling (RBE3) distributes a master
force/moment to the slave nodes so that Σ Fᵢ = F and
Σ rᵢ × Fᵢ = M while leaving the surface free to deform —
a force relation, not a kinematic one.
The previous implementation did not do this: it emitted a
kinematic mean constraint (u_ref = Σ wᵢ u_surfᵢ) and its
weighting="area" option was inverse-distance-from-centroid
(physically meaningless — the opposite of tributary area),
with no moment-equilibrium term. It silently produced a
mechanically wrong model under a correct-looking API, so it is
refused rather than shipped.
Use instead, depending on intent:
- :meth:
kinematic_coupling— a DOF-selective rigid coupling of the surface to a reference node. - :meth:
tie— shape-function interpolation onto a master face (compatible, non-rigid). - a distributed nodal load (
g.loads) — to introduce a statically-equivalent load without any kinematic tie.
Raises¶
NotImplementedError Always. Parameters are accepted only so the message is actionable.
Source code in src/apeGmsh/core/ConstraintsComposite.py
embedded ¶
embedded(host_label, embedded_label, *, tolerance=1.0, host_entities=None, embedded_entities=None, name=None) -> EmbeddedDef
Embed lower-dimensional elements inside a host volume or surface.
Each node of the embedded part is constrained to the displacement field of the host element it falls inside via host shape functions. Used for rebar in concrete, stiffeners in shells, fibres in composite hosts, etc.
Currently supports:
- 3-D host: tet4 (Gmsh element type 4) volumes.
- 2-D host: tri3 (Gmsh element type 2) surfaces.
Higher-order or hex/quad hosts are not yet supported and
will be silently skipped — fall back to :meth:tie if you
need that.
The resolver automatically drops embedded nodes that coincide with host element corners, since those are already rigidly attached through shared connectivity.
Parameters¶
host_label : str
Part label whose tet4/tri3 elements form the host
field. Stored internally as master_label.
embedded_label : str
Part label whose nodes are embedded. Stored as
slave_label. (Label validation is bypassed for
EmbeddedDef — these labels may also be physical
group names if no part registry is in use.)
tolerance : float, default 1.0
Reserved; not currently enforced (the resolver accepts
any located host record). Retained for API stability.
host_entities, embedded_entities : list of (dim, tag), optional
Restrict the host / embedded sides to specific Gmsh
entities. When omitted the whole label is used.
name : str, optional
Friendly name.
Returns¶
EmbeddedDef
Notes¶
Emitted downstream as ASDEmbeddedNodeElement. The
host_label / embedded_label argument names mirror
Abaqus's *EMBEDDED ELEMENT vocabulary; internally the
composite still stores them as master/slave for
consistency with the rest of the constraint records.
Examples¶
Rebar curve embedded inside a concrete tet mesh::
g.constraints.embedded(
host_label="concrete_block",
embedded_label="rebar_curve",
tolerance=2.0, # mm
)
Source code in src/apeGmsh/core/ConstraintsComposite.py
node_to_surface ¶
6-DOF node to 3-DOF surface coupling via phantom nodes.
Creates a single constraint that aggregates all surface entities in slave. Shared-edge mesh nodes are deduplicated so each original slave node gets exactly one phantom.
Parameters¶
master : int, str, or (dim, tag) The 6-DOF reference node. slave : int, str, or (dim, tag) The surface(s) to couple. If it resolves to multiple surface entities, they are combined into a single constraint and slave nodes are deduplicated.
Returns¶
NodeToSurfaceDef A single def covering all resolved surface entities.
Source code in src/apeGmsh/core/ConstraintsComposite.py
node_to_surface_spring ¶
Spring-based variant of :meth:node_to_surface.
Identical topology and call signature, but the master → phantom
links are tagged for downstream emission as stiff
elasticBeamColumn elements instead of kinematic
rigidLink('beam', ...) constraints. Use this variant when
the master carries free rotational DOFs (fork support on a
solid end face) that receive direct moment loading — the
constraint-based variant of node_to_surface can produce an
ill-conditioned reduced stiffness matrix in that case because
the master rotation DOFs get stiffness only through the
kinematic constraint back-propagation, with nothing attaching
directly to them.
See :class:~apeGmsh.solvers.Constraints.NodeToSurfaceSpringDef
for the full rationale.
Emission in OpenSees::
# Each master → phantom link becomes a stiff beam element
next_eid = max_tet_eid + 1
for master, slaves in fem.nodes.constraints.stiff_beam_groups():
for phantom in slaves:
ops.element(
'elasticBeamColumn', next_eid,
master, phantom,
A_big, E, I_big, I_big, J_big, transf_tag,
)
next_eid += 1
# equalDOFs are unchanged from the normal variant
for pair in fem.nodes.constraints.equal_dofs():
ops.equalDOF(
pair.master_node, pair.slave_node, *pair.dofs)
Parameters¶
Same as :meth:node_to_surface.
Returns¶
NodeToSurfaceSpringDef
Source code in src/apeGmsh/core/ConstraintsComposite.py
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 | |
tied_contact ¶
tied_contact(master_label, slave_label, *, master_entities=None, slave_entities=None, dofs=None, tolerance=1.0, name=None) -> TiedContactDef
Bidirectional surface-to-surface tie.
Conceptually a :meth:tie applied in both directions —
slave nodes are projected onto the master surface, and
master nodes are also projected onto the slave surface, so
every node on either side is interpolated against the
opposite mesh. Useful when neither side can be picked as
clearly finer than the other and you want a symmetric
treatment.
Resolution emits
:class:~apeGmsh.solvers.Constraints.SurfaceCouplingRecord
objects on fem.elements.constraints.
Parameters¶
master_label : str
Part label of the first surface.
slave_label : str
Part label of the second surface.
master_entities, slave_entities : list of (dim, tag), optional
Restrict each side to specific Gmsh entities.
dofs : list[int], optional
DOFs to tie. None = all translational.
tolerance : float, default 1.0
Maximum projection distance. Unit-sensitive.
name : str, optional
Friendly name.
Returns¶
TiedContactDef
Raises¶
KeyError
If either label is not in g.parts.
See Also¶
tie : One-directional tie (slave-projected only). mortar : Mathematically rigorous Lagrange-multiplier coupling.
Source code in src/apeGmsh/core/ConstraintsComposite.py
mortar ¶
mortar(master_label, slave_label, *, master_entities=None, slave_entities=None, dofs=None, integration_order=2, name=None) -> MortarDef
Not implemented — raises NotImplementedError.
A true mortar method introduces a Lagrange-multiplier space
ψᵢ on the slave side and integrates the coupling operator
Bᵢⱼ = ∫_Γ ψᵢ·Nⱼ dΓ over the overlapping surface segments,
satisfying the inf-sup (LBB) condition.
The previous implementation did none of that: no segment
intersection, no surface integral, no dual basis — it scattered
tied_contact collocation weights onto a block-diagonal
B with a hardcoded tolerance=10.0 (model-unit
dependent → mis-pairs on millimetre models), yet returned a
record labelled MORTAR that downstream could not
distinguish from a real one. It is refused rather than
shipped as a plausible-but-wrong operator.
Use :meth:tied_contact for a collocation-based non-matching
tie (the honest version of what the old code actually did).
Raises¶
NotImplementedError Always. Parameters are accepted only so the message is actionable.
Source code in src/apeGmsh/core/ConstraintsComposite.py
validate_pre_mesh ¶
No-op: constraints validate targets eagerly at _add_def.
Present so :meth:Mesh.generate can invoke validate_pre_mesh
on all three composites uniformly.
Source code in src/apeGmsh/core/ConstraintsComposite.py
summary ¶
DataFrame of the declared constraint intent — one row per def.
Columns: kind, name, master, slave, params. params is a
short stringified view of the kind-specific fields (dofs,
tolerance, etc.).
Source code in src/apeGmsh/core/ConstraintsComposite.py
FEMData ¶
FEMData(nodes: NodeComposite, elements: ElementComposite, info: MeshInfo, mesh_selection: 'MeshSelectionStore | None' = None)
Solver-ready FEM mesh broker.
Organized by what the user needs::
fem.nodes → NodeComposite
fem.elements → ElementComposite
fem.info → MeshInfo
fem.inspect → InspectComposite
Source code in src/apeGmsh/mesh/FEMData.py
snapshot_id
property
¶
Deterministic content hash identifying this FEMData snapshot.
Computed once and cached. Used by the Results module to bind
result files to their producing geometry — see
internal_docs/Results_architecture.md § "FEMData embedding
& binding".
from_gmsh
classmethod
¶
Extract FEMData from a live Gmsh session.
Parameters¶
dim : int or None
Element dimension to extract. None = all dims.
session : apeGmsh session, optional
When provided, auto-resolves constraints, loads, masses.
ndf : int
DOFs per node for load/mass vector padding.
remove_orphans : bool
If True, remove mesh nodes not connected to any element.
Source code in src/apeGmsh/mesh/FEMData.py
from_msh
classmethod
¶
Load FEMData from an external .msh file.
Source code in src/apeGmsh/mesh/FEMData.py
from_h5
classmethod
¶
Load a :class:FEMData snapshot from a root-layout model.h5.
Inverse of :meth:to_h5. Reads the seven neutral-zone groups
plus /meta and rebuilds nodes, elements (per type),
physical groups, labels, mesh selections, constraints, loads,
and masses — everything the writer round-trips.
Use this to resume a session-saved model in a later script::
# script 1 — build & save
with apeGmsh(model_name="m", save_to="m.h5") as g:
...
# script 2 — analyse
fem = FEMData.from_h5("m.h5")
apeSees(fem).h5("m.h5") # enrich with /opensees/...
Source code in src/apeGmsh/mesh/FEMData.py
to_native_h5 ¶
Embed this FEMData into an open HDF5 group (/model/).
Used by NativeWriter to snapshot the geometry alongside
results. The reconstructed FEMData (via from_native_h5)
will produce the same snapshot_id — this is the linking
contract for Results.bind().
Source code in src/apeGmsh/mesh/FEMData.py
to_h5 ¶
Write a fresh model.h5 containing the neutral zone.
Phase 8.5 entry point: dumps everything the broker knows about
the model (nodes, elements per type, physical groups, labels,
constraints, loads, masses) into a root-level
model.h5. No /opensees/ content is emitted — absent
enrichment is the right "no solver loaded" signal.
Use apeSees(fem).h5(path) instead to get a fully enriched
file (neutral zone + /opensees/...).
Source code in src/apeGmsh/mesh/FEMData.py
from_native_h5
classmethod
¶
Reconstruct a FEMData from its embedded /model/ group.
The reconstructed object carries nodes, elements (per type),
physical groups, and labels. Loads/masses/constraints are not
round-tripped (they don't affect snapshot_id and the
viewer doesn't need them).
Source code in src/apeGmsh/mesh/FEMData.py
from_mpco_model
classmethod
¶
Synthesize a partial FEMData from an MPCO MODEL/ group.
Carries: nodes, elements (per OpenSees class tag), physical
groups derived from MPCO Regions (MODEL/SETS).
Missing vs. native:
- apeGmsh-specific labels
- Pre-mesh declarations (loads / masses / constraints)
- STKO named selection sets (those live in .cdata sidecars)
- Gmsh-style element type codes (uses negated class_tag instead)
snapshot_id will not match a native FEMData of the same
mesh — that's expected. Results.bind() will refuse such
mismatches.
Source code in src/apeGmsh/mesh/FEMData.py
viewer ¶
Open a non-interactive mesh viewer from this snapshot.
Currently disabled — the legacy Results.from_fem(...).viewer()
path was removed when the Results module was rebuilt. The new
flow is being designed as part of the viewer rebuild project;
see internal_docs/Results_architecture.md (Phase 9).
Source code in src/apeGmsh/mesh/FEMData.py
MeshInfo ¶
Read-only summary of mesh statistics.
Accessed via fem.info.
Attributes¶
n_nodes : int n_elems : int bandwidth : int types : list[ElementTypeInfo] Element types present in the mesh.
Source code in src/apeGmsh/mesh/FEMData.py
summary ¶
One-line summary string.
Source code in src/apeGmsh/mesh/FEMData.py
PhysicalGroupSet ¶
Bases: NamedGroupSet
Snapshot of solver-facing physical groups.
Accessed via fem.nodes.physical / fem.elements.physical
(shared reference) and indirectly via
fem.nodes.select(pg="Base").
Source code in src/apeGmsh/mesh/_group_set.py
LabelSet ¶
Bases: NamedGroupSet
Snapshot of geometry-time labels (Tier 1).
Accessed via fem.nodes.labels / fem.elements.labels
(shared reference) and indirectly via
fem.nodes.select(label="col.web").
Source code in src/apeGmsh/mesh/_group_set.py
Algorithm2D ¶
Bases: IntEnum
2-D meshing algorithm selector (legacy IntEnum form).
Prefer passing a string name to
:meth:apeGmsh.mesh.Mesh._Generation.set_algorithm — see
:data:ALGORITHM_2D and :class:MeshAlgorithm2D for the canonical
names and the accepted aliases.
Algorithm3D ¶
Bases: IntEnum
3-D meshing algorithm selector (legacy IntEnum form).
MeshAlgorithm2D ¶
Canonical 2-D algorithm names as string constants (IDE autocomplete).
MeshAlgorithm3D ¶
Canonical 3-D algorithm names as string constants (IDE autocomplete).
OptimizeMethod ¶
Mesh optimisation method names — use with g.mesh.generation.optimize.
MshLoader ¶
Bases: _HasLogging
Load .msh files and produce solver-ready :class:FEMData.
Can be used standalone via the :meth:load classmethod, or as a
composite on a apeGmsh / Assembly session via g.loader.
Parameters¶
parent : _SessionBase or None
The owning session when used as a composite. None when
used standalone.
Source code in src/apeGmsh/mesh/MshLoader.py
load
classmethod
¶
Load a .msh file and return a :class:FEMData.
Manages its own Gmsh session internally — no apeGmsh
instance, no begin()/end() needed. Supports MSH2
and MSH4 formats.
Parameters¶
path : str or Path
Path to the .msh file.
dim : int
Element dimension to extract (1 = lines, 2 = tri/quad,
3 = tet/hex). Default is 2.
verbose : bool
Print a summary of what was loaded.
Returns¶
FEMData Self-contained solver-ready mesh data with physical groups, mesh statistics, and connectivity.
Example¶
::
from apeGmsh import MshLoader, Numberer
fem = MshLoader.load("bridge.msh", dim=2)
print(fem.info)
print(fem.physical.summary())
numb = Numberer(fem)
data = numb.renumber(method="rcm")
Source code in src/apeGmsh/mesh/MshLoader.py
from_msh ¶
Load a .msh file into the active Gmsh session.
The mesh is merged via gmsh.merge(), so all composites
(g.physical, g.plot, g.inspect, etc.) remain
usable afterwards.
Parameters¶
path : str or Path
Path to the .msh file.
dim : int
Element dimension to extract. Default is 2.
Returns¶
FEMData Self-contained solver-ready mesh data.
Raises¶
FileNotFoundError
If path does not exist.
RuntimeError
If no Gmsh session is active (call g.begin() first).
Example¶
::
g = apeGmsh(model_name="imported")
g.begin()
fem = g.loader.from_msh("model.msh", dim=2)
print(fem.physical.summary())
g.end()
Source code in src/apeGmsh/mesh/MshLoader.py
Results ¶
Results(reader: ResultsReader, *, fem: 'Optional[FEMData]' = None, stage_id: Optional[str] = None, path: Optional[Path] = None)
Top-level results object. Returned by Results.from_* constructors.
Stage scoping¶
Instances may be unscoped (top-level — accesses any stage) or
scoped to one stage (returned by .stage(name),
.modes[i]). Scoped instances expose stage metadata as
properties (.kind, .time, .n_steps); mode-scoped
instances additionally expose .eigenvalue, .frequency_hz,
.period_s, .mode_index.
Source code in src/apeGmsh/results/Results.py
modes
property
¶
Stages with kind='mode' as a list of mode-scoped Results.
Order is the order the modes were written (typically by
ascending mode_index). For a stable lookup by index, sort:
sorted(results.modes, key=lambda m: m.mode_index).
plot
property
¶
results.plot — static matplotlib renderer.
Mirrors the interactive viewer's diagram catalog as headless, publication-ready matplotlib figures::
results.plot.contour("displacement_z", step=-1)
results.plot.deformed(step=-1, scale=50, component="stress_xx")
results.plot.history(node=412, component="displacement_x")
Requires the [plot] extra (matplotlib).
from_native
classmethod
¶
Open an apeGmsh native HDF5 results file.
If fem is omitted, the embedded /model/ snapshot is
used as the bound FEMData. If fem is provided and the file
embeds a snapshot, the two snapshot_id hashes must match.
Source code in src/apeGmsh/results/Results.py
from_recorders
classmethod
¶
from_recorders(spec, output_dir: str | Path, *, fem: 'FEMData', cache_root: str | Path | None = None, stage_name: str = 'analysis', stage_kind: str = 'transient', file_format: str = 'out', stage_id: str | None = None) -> 'Results'
Open the result of an OpenSees run driven by Tcl/Py recorders.
Parses the .out / .xml files emitted at
output_dir (matching what spec.emit_recorders(...) or
the apeGmsh OpenSees bridge's Tcl/Py emit produced) into an
apeGmsh native HDF5, caches the result at
cache_root, and opens it through NativeReader.
Caching: subsequent calls with unchanged input files return
the cached HDF5 directly (file mtime + size + spec
snapshot_id form the cache key). See
writers/_cache.py.
stage_id matches the per-stage filename prefix used by
:meth:ResolvedRecorderSpec.emit_recorders together with
begin_stage(stage_id, ...). When set, only files prefixed
with <stage_id>__ are read; stage_name defaults to
stage_id if not overridden. None (default) keeps the
legacy flat-naming used by Tcl/Py exports.
Phase 6 v1 supports nodal records only; element-level records in the spec are skipped with a note. The capture flow (Phase 7) handles modal recorders.
Source code in src/apeGmsh/results/Results.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
from_mpco
classmethod
¶
from_mpco(path: 'str | Path | list[str | Path]', *, fem: 'Optional[FEMData]' = None, merge_partitions: bool = True) -> 'Results'
Open a STKO .mpco HDF5 results file.
Single-file mode (default for non-partitioned analyses): pass
the path of one .mpco file. Synthesizes a partial FEMData
from the MPCO MODEL/ group if fem is omitted.
Multi-partition mode (parallel OpenSees runs): pass either
- a single
<stem>.part-<N>.mpcopath — siblings are discovered automatically by globbing<stem>.part-*.mpcoin the same directory and merged into one virtual reader; - an explicit list of partition paths.
Boundary nodes deduplicate by ID (first-occurrence wins); elements concatenate (disjoint by partition); slabs stitch across partitions transparently. Stage and time vectors must match across partitions or construction raises.
Pass merge_partitions=False to opt out of auto-discovery
and read only the file at path even if it follows the
.part-N naming convention.
Source code in src/apeGmsh/results/Results.py
bind ¶
Re-bind to fem.
Useful when you've re-built the same mesh in a fresh session and want labels / Parts that the embedded snapshot doesn't carry. No hash validation is performed — pairing the FEMData with a results file from the same run is the user's responsibility.
Source code in src/apeGmsh/results/Results.py
stage ¶
Return a Results scoped to a stage (matched by id or name).
close ¶
viewer ¶
viewer(*, blocking: bool = True, title: Optional[str] = None, restore_session: 'bool | str' = 'prompt', save_session: bool = True, cuts: 'Optional[Any]' = None, model_h5: 'Optional[Any]' = None)
Open the post-solve results viewer.
Parameters¶
blocking
True (default) — open the viewer in-process and block
the calling thread until the window closes. Matches the
signature of :meth:g.mesh.viewer and :meth:g.model.viewer.
False — spawn a subprocess via
python -m apeGmsh.viewers <path> so the notebook /
kernel can keep running. Requires that the Results was
opened from disk (self._path is set); raises
:class:RuntimeError for in-memory Results.
title
Optional window title; defaults to "Results — <filename>".
restore_session
How to handle a previously-saved session JSON next to the
results file. True restores silently, False ignores,
"prompt" (default) opens a yes/no dialog if a matching
session exists. No effect for in-memory Results.
save_session
If True (default), the active set of diagrams + scrubber
position is saved to <results>.viewer-session.json when
the window closes. False disables auto-save.
cuts
Optional sequence of :class:apeGmsh.cuts.SectionCutDef
instances to render as Layers at boot. Each cut becomes a
new SectionCutDiagram in the active geometry's
"Section cuts" composition (created if absent). Requires
model_h5 so OpenSees tags can be mapped back to FEM
eids — pass it alongside cuts. Subprocess launches
(blocking=False) currently ignore this argument; build
cuts programmatically via director.add_section_cut on
the spawned viewer once it exposes IPC.
model_h5
Path to a model.h5 that carries OpenSees enrichment:
/opensees/cuts (for section-cut tag mapping) and / or
/opensees/transforms + /opensees/element_meta (for
per-element beam orientation, ADR 0018). When omitted and
self was opened from disk via :meth:from_native, the
viewer auto-resolves the results file itself as the
orientation source if it carries those zones; cuts
auto-load still requires an explicit model_h5=.
Forwarded into the subprocess on blocking=False via
--model-h5 so the auto-resolve also fires there for
non-default layouts.
Returns¶
ResultsViewer
The viewer instance after the window closes (blocking).
subprocess.Popen
The spawned process handle (non-blocking).
None
If APEGMSH_SKIP_VIEWER is set in the environment. This
lets the same cell run under jupyter nbconvert --execute
or in CI without spawning a GUI window.
Source code in src/apeGmsh/results/Results.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
Numberer ¶
Renumbers a FEM mesh for solver consumption.
Parameters¶
fem_data : dict
Output of Mesh.get_fem_data(). Must contain:
node_tags, node_coords, elem_tags,
connectivity, used_tags.
Source code in src/apeGmsh/mesh/_numberer.py
renumber ¶
Produce a solver-ready mesh with contiguous IDs.
Parameters¶
method : "simple" or "rcm"
"simple" — preserves relative order, just makes IDs
contiguous. Fast, no optimisation.
``"rcm"`` — Reverse Cuthill-McKee bandwidth minimisation.
Reorders nodes so that the assembled stiffness matrix has
minimal bandwidth. Recommended for direct solvers.
int
Starting ID (default 1 = Fortran/OpenSees convention; use 0 for C/Python convention).
bool
If True (default), only include nodes that appear in at least one element (skip orphan nodes). Set False to include all nodes from the mesh.
Returns¶
NumberedMesh
Source code in src/apeGmsh/mesh/_numberer.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
NumberedMesh
dataclass
¶
NumberedMesh(node_ids: ndarray, node_coords: ndarray, elem_ids: ndarray, connectivity: ndarray, n_nodes: int = 0, n_elems: int = 0, bandwidth: int = 0, method: str = 'simple', gmsh_to_solver_node: dict[int, int] = dict(), solver_to_gmsh_node: dict[int, int] = dict(), gmsh_to_solver_elem: dict[int, int] = dict(), solver_to_gmsh_elem: dict[int, int] = dict())
Solver-ready mesh with contiguous IDs and bidirectional maps.
All IDs are 1-based (the standard in structural FEM solvers
like OpenSees, Abaqus, SAP2000). Set base=0 in
:meth:Numberer.renumber for 0-based if your solver needs it.
Attributes¶
node_ids : ndarray(N,)
New contiguous node IDs.
node_coords : ndarray(N, 3)
Nodal coordinates, same order as node_ids.
elem_ids : ndarray(E,)
New contiguous element IDs.
connectivity : ndarray(E, npe)
Element connectivity in terms of new node IDs.
n_nodes : int
n_elems : int
bandwidth : int
Semi-bandwidth of the resulting adjacency.
method : str
Numbering method used ("simple" or "rcm").
Maps ~~~~ gmsh_to_solver_node : dict[int, int] Gmsh node tag -> solver node ID. solver_to_gmsh_node : dict[int, int] Solver node ID -> Gmsh node tag. gmsh_to_solver_elem : dict[int, int] Gmsh element tag -> solver element ID. solver_to_gmsh_elem : dict[int, int] Solver element ID -> Gmsh element tag.
summary ¶
RenumberResult ¶
RenumberResult(method: str, n_nodes: int, n_elements: int, bandwidth_before: int, bandwidth_after: int)
Result of a mesh renumbering operation.
Attributes¶
method : str
Algorithm used ("simple", "rcm", "hilbert", "metis").
n_nodes : int
Number of nodes renumbered.
n_elements : int
Number of elements renumbered.
bandwidth_before : int
Semi-bandwidth before renumbering.
bandwidth_after : int
Semi-bandwidth after renumbering.
Source code in src/apeGmsh/mesh/_mesh_partitioning.py
PartitionInfo ¶
Result of a mesh partitioning operation.
Attributes¶
n_parts : int
Number of partitions created.
elements_per_partition : dict[int, int]
{partition_id: element_count}.
Source code in src/apeGmsh/mesh/_mesh_partitioning.py
MeshViewer ¶
MeshViewer(parent: '_SessionBase', *, dims: list[int] | None = None, point_size: float | None = None, line_width: float | None = None, surface_opacity: float | None = None, show_surface_edges: bool | None = None, origin_markers: list[tuple[float, float, float]] | None = None, origin_marker_show_coords: bool | None = None, view: 'ViewerData | None' = None, fast: bool = True, **kwargs: Any)
Interactive mesh viewer with element/node picking.
Displays mesh elements and nodes with optional load, constraint,
and mass overlays. Overlay data comes from a resolved
:class:apeGmsh.viewers.data.ViewerData snapshot — either passed
explicitly or auto-resolved from the session at show time.
Parameters¶
parent : _SessionBase
The apeGmsh session.
dims : list[int], optional
Which mesh dimensions to show (default: [1, 2, 3]).
point_size, line_width, surface_opacity, show_surface_edges
Visual properties.
view : ViewerData, optional
Pre-resolved structural snapshot. If not provided, the
viewer calls get_fem_data() automatically when the
window opens and wraps the resulting FEMData. Phase 8.7
commit 6 renamed this kwarg from fem to view.
fast : bool
Ignored (always fast). Kept for backward compatibility.
Source code in src/apeGmsh/viewers/mesh_viewer.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
show ¶
Open the viewer window, block until closed.
Source code in src/apeGmsh/viewers/mesh_viewer.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
ModelViewer ¶
ModelViewer(parent: '_SessionBase', model: 'Model', *, physical_group: str | None = None, dims: list[int] | None = None, point_size: float | None = None, line_width: float | None = None, surface_opacity: float | None = None, show_surface_edges: bool | None = None, origin_markers: list[tuple[float, float, float]] | None = None, origin_marker_show_coords: bool | None = None)
Interactive BRep model viewer with physical group management.
Displays BRep geometry, parts, physical groups, and labels.
This is a geometry-only viewer — loads, constraints, and masses
are mesh-resolved concepts and live on g.mesh.viewer() instead.
Parameters¶
parent : _SessionBase
The apeGmsh session (provides name, _verbose).
model : Model
The apeGmsh model (provides sync()).
physical_group : str, optional
Auto-activate this physical group on open.
dims : list[int], optional
Which entity dimensions to show (default: [0, 1, 2, 3]).
point_size, line_width, surface_opacity, show_surface_edges
Visual properties forwarded to the scene builder.
Source code in src/apeGmsh/viewers/model_viewer.py
active_group
property
¶
The name of the physical group currently receiving picks.
show ¶
Open the viewer window, block until closed.
Source code in src/apeGmsh/viewers/model_viewer.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 | |
to_physical ¶
Write the current picks as a Gmsh physical group.
Source code in src/apeGmsh/viewers/model_viewer.py
ResultsViewer ¶
ResultsViewer(results: 'Results', *, title: Optional[str] = None, restore_session: 'bool | str' = 'prompt', save_session: bool = True, cuts: 'Optional[Sequence[SectionCutDef]]' = None, model_h5: 'Optional[str | Path]' = None)
Post-solve interactive viewer.
Parameters¶
results
A :class:Results instance — must have a bound FEMData
(either from the embedded /model/ snapshot or via
results.bind(fem)).
title
Window title. Defaults to "Results — <path>".
Source code in src/apeGmsh/viewers/results_viewer.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
export_animation ¶
Export the time history as an animated MP4 or GIF.
Format auto-detected from the path suffix (.mp4 / .gif).
See :func:apeGmsh.viewers.animation.export_animation for the
full parameter documentation. Requires the viewer to have been
:meth:show-n so the plotter and director are wired.
Source code in src/apeGmsh/viewers/results_viewer.py
show ¶
Open the viewer window and run the Qt event loop until close.
Returns self so callers can introspect the viewer state
after the window closes.
Source code in src/apeGmsh/viewers/results_viewer.py
settings ¶
Open the global preferences editor (modal dialog).
Persists changes to the JSON file at
PreferencesManager.path (platform-appropriate config dir).
Spins up a QApplication if none exists.
Returns the dialog result code (QDialog.Accepted / Rejected).
Source code in src/apeGmsh/viewers/__init__.py
theme_editor ¶
Open the theme editor (modal dialog with live preview).
Custom themes are persisted under ThemeManager.themes_dir()
(platform-appropriate config dir). Spins up a QApplication if
none exists.
Returns the dialog result code (QDialog.Accepted / Rejected).
Source code in src/apeGmsh/viewers/__init__.py
preview ¶
preview(session: Any = None, *, mode: str = 'mesh', dims: list[int] | None = None, show_nodes: bool = True, browser: bool = False, return_fig: bool = False) -> Any
Unified entry point — routes to preview_model or preview_mesh.
Parameters¶
mode : {"model", "mesh"}
Which scene to render. Default "mesh".
show_nodes : bool
Mesh mode only — render the full mesh-node cloud as a
separate trace. Ignored in model mode.
browser : bool
Open in a new browser tab instead of rendering inline.
return_fig : bool
Skip display and return the raw plotly Figure.
Source code in src/apeGmsh/viz/NotebookPreview.py
workdir ¶
Return Path(name) after ensuring it exists.
Convention for example notebooks: every script puts its
artifacts (capture.h5, recorders/, exports, etc.) under
a sibling outputs/ folder so the example directory stays
self-contained. Typical use::
from apeGmsh import workdir
OUT = workdir() # ./outputs/
cap_path = OUT / 'capture.h5'
Pass an explicit name for nested or non-default layouts
(workdir('outputs/run_42')).
Source code in src/apeGmsh/_workdir.py
Session class¶
apeGmsh._core.apeGmsh ¶
apeGmsh(*, model_name: str = 'ModelName', verbose: bool = False, save_to: str | Path | None = None, overwrite: bool = True)
Bases: _SessionBase
Standalone single-model Gmsh session with all composites.
Parameters¶
model_name : str
Name passed to gmsh.model.add().
verbose : bool
If True, composites print diagnostic messages.
Source code in src/apeGmsh/_core.py
save ¶
Write the neutral-zone model.h5 for this session.
Persists what the session knows about the model: nodes,
elements, physical groups, labels, constraints, loads, masses.
Downstream solver enrichment (e.g. apeSees(fem).h5(p)) is
a separate user-driven action and not invoked here.
Parameters¶
path : str, Path, or None
Destination file. None (default) uses the save_to
given to the constructor. Raises if neither is set.
Returns the resolved path.
Source code in src/apeGmsh/_core.py
Base¶
apeGmsh._session._SessionBase ¶
Base class for objects that own a Gmsh session and parent composites.
Source code in src/apeGmsh/_session.py
begin ¶
Open a Gmsh session, create composites.
Parameters¶
verbose : bool or None
Override the verbosity set in __init__. None keeps
the current value.
Returns self for chaining.
Source code in src/apeGmsh/_session.py
end ¶
Close the Gmsh session.
If the subclass set a _save_to path (autosave configured at
construction), the broker snapshot is written before
gmsh.finalize(). Save failures are logged and swallowed —
the gmsh process must still finalize.