Skip to content

hertzforge.core.geometry

geometry

Test and model geometry: nodes, coordinate systems, elements and element groups.

Node coordinates are stored in the global cartesian frame, in meters once their unit is known. A geometry read from a file that does not declare units (an sdynpy .npz, an exodus file, a UNV file without dataset 164) keeps the file's coordinates as they are, and length_unit is None until define_units() is called. Element types are identified by the FE descriptor codes of UFF dataset 2412.

Classes:

Name Description
View

The direction a geometry is viewed from in 3-D: where the eye is,

Geometry

Nodes, coordinate systems, elements and element groups.

Functions:

Name Description
pen_up_runs

The runs of a traceline's node list, in which 0 lifts the pen.

element_family

Which family a 2412 element code belongs to.

placed

A point given in a coordinate system, converted to global cartesian.

written_in

The inverse of placed: a global cartesian point in the

to_global

Node coordinates given in each node's own placement system,

to_local

The inverse of to_global, for a writer that gives each node in

reconcile_type

The descriptor that matches the number of nodes an element has,

face_corners

How many corners a face element is drawn with: three for a

solid_faces

The faces of a solid cell with this many nodes, each face as

deck_to_si

A finite element deck's element group properties converted to SI

implausible_materials

A sentence for each material whose modulus or density, in SI, is

Classes

View

View(eye: ArrayLike = (1.0, 1.0, 1.0), up: ArrayLike = (0.0, 0.0, 1.0))

The direction a geometry is viewed from in 3-D: where the eye is, seen from the model's center, and which way is up on screen.

A view is only a direction. Every view is fitted to what it shows, so there is no distance or zoom to store. Set on a geometry, it is the view the app opens the geometry and everything drawn on it in, the view Reset View returns to, and the view of the report's scenes and exported figures. A model built with Y up then opens upright without its nodes being rotated. Raises ValueError for a zero or non-finite direction, or an up along the line of sight.

Parameters:

Name Type Description Default
eye sequence of 3 floats

The direction from the model toward the eye, in the global frame; any length.

(1, 1, 1)
up sequence of 3 floats

Which way is up on screen. Only its part across the line of sight counts, so it need not be exactly perpendicular to eye.

(0, 0, 1)

Examples:

A model built with Y up, seen from the front, above and to the right:

>>> geometry.view = View(eye=(1, 1, -1), up=(0, 1, 0))

Methods:

Name Description
basis

(right, up) on screen, as unit vectors in the global frame.

Methods:
basis
basis() -> tuple[tuple[float, ...], tuple[float, ...]]

(right, up) on screen, as unit vectors in the global frame.

Right is the line of sight crossed with up, and up is up made perpendicular to the line of sight.

Geometry

Geometry(node_id: Ids, node_xyz: ArrayLike, node_def_cs: ArrayLike | None = None, node_disp_cs: ArrayLike | None = None, node_color: ArrayLike | None = None, cs_id: Ids | None = None, cs_name: Sequence[str] | None = None, cs_type: ArrayLike | None = None, cs_matrix: ArrayLike | None = None, elem_id: Ids | None = None, elem_type: ArrayLike | None = None, elem_color: ArrayLike | None = None, elem_conn: Sequence[ArrayLike] | None = None, elem_group: Ids | None = None, group_id: Ids | None = None, group_name: Sequence[str] | None = None, length_unit: str | None = None, group_properties: Mapping[int, Any] | None = None, from_deck: bool = False, mass_unit: str | None = None)

Nodes, coordinate systems, elements and element groups.

The parameters are array-likes with the names of the attributes below; elem_conn holds one integer array of node ids per element. Coordinates are in the global cartesian frame, in meters once length_unit is declared. Without coordinate systems the geometry gets one, the global cartesian system with id 1. An element whose descriptor does not match its node count is corrected (reconcile_type), and an element group holding more than one element family is split (split_groups_by_family). Raises ValueError when the result is not consistent (validate).

The arrays below hold the data; nodes, coordinate_systems, elements and groups are views of them, which is how the project tree lists a geometry and usually the easiest way for a script to use one. A view is not a copy, so writing through a row writes into the geometry.

There are no separate tracelines. A line drawn through nodes is an element group of two-node line elements with no properties: add_beams creates one, and drawn_lines returns them for the file formats that store tracelines separately. The same element group becomes part of the structure once it is given a section.

Attributes: node_id: Every node's id. Unique, because elements and placement refer to nodes by id. node_xyz: (nodes, 3) coordinates, in meters once length_unit is declared and the file's numbers before that. node_def_cs: The coordinate system each node is placed in. node_disp_cs: The coordinate system each node is measured in, which is the system a shape's values at that node are in. node_color: Palette index per node. cs_id: Coordinate system ids. Unique, for the same reason as node ids. cs_name: A name per system, often empty. cs_type: 0 cartesian, 1 cylindrical, 2 spherical (CS_TYPES). cs_matrix: (systems, 4, 3): three direction rows, then the origin, so cs_matrix[i, 3] is the origin of system i. elem_id: Element ids. They are only labels; nothing refers to them. elem_type: UFF dataset 2412 descriptor code per element (ELEMENT_TYPES names them and says how each is drawn). elem_color: Palette index per element. elem_conn: One array of node ids per element. elem_group: The id of the element group each element belongs to. group_id: The declared element groups. Unique, since elements refer to them by id. group_name: A name per element group, such as 'wing' or 'arm front left'. This is where a mesh records that a region is a different part from its neighbor, and fem.Model.from_geometry reads a member's section from it. group_properties: {element group id: fem.GroupProperties}, the material and thickness or section of each element group that has them. length_unit: The unit of the coordinates, or None while it has not been declared, in which case they are the file's own numbers and nothing has been scaled. mass_properties: The reference point, mass and inertia for the rigid-body shapes (core.rigid.MassProperties), or None. view: The direction the geometry opens in 3-D (View), or None for DEFAULT_VIEW. solids: The solid shapes of the parts before they are meshed (core.solids). mates: Where element groups' surfaces are joined, by rigid links or springs made when a model is built (core.mates).

Methods:

Name Description
validate

Check that the geometry is consistent, and raise ValueError

node_index

Positions of the given node ids in the node arrays.

contains_nodes

Boolean array: which of node_ids this geometry defines.

missing_dofs

The DOF strings whose node this geometry does not define.

suggest_mass_properties

Mass properties with the centroid of the nodes as the reference

define_units

Declare the length unit of the coordinates, converting them to SI.

undefine_units

Remove the length unit and restore the original coordinates; returns self.

dof_direction

A DOF's direction in global coordinates, from the coordinate

add_node

Add a node at xyz and return its id.

add_nodes

Add nodes at xyz, numbered from one more than the highest id.

add_coordinate_system

Add a coordinate system and return its id.

place_coordinate_system

Rotate a coordinate system, move it, or both, as the 3-D

set_coordinate_system_type

Make a coordinate system cartesian (0), cylindrical (1) or

node_local_xyz

Each node's coordinates in the coordinate system it is placed

set_node_local_xyz

Place the node at row at xyz, given in the coordinate

set_node_placement

Place nodes in another coordinate system, keeping their

add_beams

Add a chain of two-node line elements through the given nodes,

mixed_groups

{element group id: families} for every element group that

split_groups_by_family

Split every element group that holds more than one element family.

attach_drawn_lines

Add drawn lines read from a format that stores them separately

is_drawn_line

Whether an element group is a drawn line.

drawn_lines

The drawn lines, in the form used by file formats that store

group_of

The name of the element group an element belongs to, or '' when

elements_in

The ids of the elements in an element group, given by id or name.

nodes_in

The ids of the nodes used by the elements of these element

add_group

Declare an element group and return its id.

add_element

Add an element and return its row index.

add_elements

Add many elements at once, numbered from one more than the

renumber_node

Give a node a new id, and update the elements that use it.

rename_group

Give an element group a name.

move_elements

Put elements in another element group, as dragging them onto it in the tree does.

renumber_group

Give an element group a new id, and update its elements.

renumber_coordinate_system

Give a coordinate system a new id, and update the nodes that use it.

delete_nodes

Remove nodes, and the elements that use them.

coincident_nodes

{node: the node it coincides with} for every node within

duplicate_elements

{element id: the element it duplicates} for every solid

merge_duplicate_elements

Remove duplicate solid elements (duplicate_elements).

node_spacing

The mesh's finest spacing: the shortest nonzero distance between

coincident_spots

The places where a merge would make one node.

merge_folds

Why this merge would be refused, or None.

merge_collapses

The ids of the line elements this merge would remove.

merge_coincident_nodes

Merge nodes that are at one point into one node.

align_reach

The default reach of Align Meshes: half the mesh size of the

align_moves

The moves Align Meshes would make, each [node, onto]: a node

align_folds

Why these moves would be refused, or None.

align_meshes

Move the nodes of the coarser piece onto the nodes of the finer

delete_coordinate_systems

Remove coordinate systems, and give the nodes that used them to

delete_groups

Remove element groups with their elements, their properties, and

merge_refusal

Why these element groups cannot be merged, or None when they can.

merge_groups

Merge several element groups into the first one (Merge Element

delete_elements

Remove elements by id. Ids that are not present are ignored.

save

Write the geometry to a file of its own.

load

Read a geometry written by save.

Attributes:

Name Type Description
opening_view View

The view the geometry opens in 3-D: its own view, or

num_nodes int

How many nodes the geometry defines.

nodes EntityView

Every node: ids, xyz, colors, placement_systems and

coordinate_systems EntityView

Every coordinate system: ids, names, types and matrices

elements EntityView

Every element: ids, types, colors, groups and nodes

groups EntityView

Every element group: ids and names (an EntityView).

extent tuple[ndarray, ndarray]

(min_xyz, max_xyz) of the nodes, in meters once units are defined.

units_defined bool

Whether the length unit of the coordinates has been declared.

Attributes
opening_view property
opening_view: View

The view the geometry opens in 3-D: its own view, or DEFAULT_VIEW (from +X+Y+Z, Z up) when it has none.

num_nodes property
num_nodes: int

How many nodes the geometry defines.

nodes property
nodes: EntityView

Every node: ids, xyz, colors, placement_systems and displacement_systems (an EntityView).

coordinate_systems property
coordinate_systems: EntityView

Every coordinate system: ids, names, types and matrices (an EntityView).

elements property
elements: EntityView

Every element: ids, types, colors, groups and nodes (an EntityView).

groups property
groups: EntityView

Every element group: ids and names (an EntityView).

An element group does not store its elements. Which elements are in one is read from elem_group (elements_in), so moving an element to another element group is an edit to the element.

extent property
extent: tuple[ndarray, ndarray]

(min_xyz, max_xyz) of the nodes, in meters once units are defined.

units_defined property
units_defined: bool

Whether the length unit of the coordinates has been declared. False until define_units is called.

Methods:
validate
validate() -> None

Check that the geometry is consistent, and raise ValueError naming the first problem found.

Node, coordinate system and element group ids must be unique, every element's nodes must exist, every element must name an element group the geometry has, every element type must be in ELEMENT_TYPES, and each element group must hold one element family.

node_index
node_index(node_ids: Ids) -> ndarray

Positions of the given node ids in the node arrays.

Every id must be one the geometry has (contains_nodes asks without raising).

Parameters:

Name Type Description Default
node_ids int or sequence of int

The identifiers, one or many.

required

Returns:

Type Description
ndarray

Each identifier's row in the node arrays.

Raises:

Type Description
KeyError

Naming the ids the geometry does not have.

contains_nodes
contains_nodes(node_ids: Ids) -> ndarray

Boolean array: which of node_ids this geometry defines.

Parameters:

Name Type Description Default
node_ids int or sequence of int

The identifiers, one or many.

required

Returns:

Type Description
ndarray

A boolean per identifier: whether the geometry has it.

missing_dofs
missing_dofs(dofs: Sequence[str]) -> list[str]

The DOF strings whose node this geometry does not define.

Parameters:

Name Type Description Default
dofs sequence of str

The degrees of freedom to check, such as '101Z+'.

required

Returns:

Type Description
list of str

The DOFs whose node the geometry does not have, including any DOF that names no node. A data object with such DOFs is not compatible with this geometry.

suggest_mass_properties
suggest_mass_properties() -> MassProperties

Mass properties with the centroid of the nodes as the reference point and no mass, which give unit rigid-body shapes about the middle of the model.

The rigid-body panel opens with these values, and generate_rigid_body_modes uses them when nothing has been set. They are the settings the virtual point transformation needs most often. Raises ValueError when the geometry has no nodes.

Returns:

Type Description
MassProperties

The centroid, unscaled.

define_units
define_units(length_unit: str, mass_unit: str | None = None) -> Geometry

Declare the length unit of the coordinates, converting them to SI.

The node coordinates, the coordinate system origins and the solids' lengths are converted. Declaring again reinterprets the original values instead of scaling twice, so a wrong unit can be corrected.

A geometry read from a finite element deck (from_deck) also holds the deck's property values, in the consistent system its length unit, a mass unit and seconds make: a thickness is a length, a modulus a force per area, a density a mass per volume, a point mass a mass, a spring a force per length (or, about an axis, a force times a length). Those are converted with the coordinates (deck_to_si). The mass unit is mass_unit, or the one a deck in that length is written with when it is omitted (DECK_MASS_UNITS: tonnes with millimeters, lbf·s²/in with inches). A material whose converted modulus or density is not a structural material's is warned about, since that is what a wrong mass unit looks like.

Parameters:

Name Type Description Default
length_unit str

The unit the coordinates are in, such as 'm' or 'in'.

required
mass_unit str

The mass unit of a deck's properties, such as 'tonne'.

None

Returns:

Type Description
Geometry

Self, converted to SI in place.

undefine_units
undefine_units() -> Geometry

Remove the length unit and restore the original coordinates; returns self.

dof_direction
dof_direction(dof: str) -> ndarray | None

A DOF's direction in global coordinates, from the coordinate system its node is measured in.

'101X+' at a node whose node_disp_cs is rotated is not global X. The report's table of control channels uses this to show which global axis each channel is nearest and how far it is from it. A rotational DOF points along its axis, as the DOF arrows draw it. A node whose system is not in the geometry is taken to be in the global system.

Parameters:

Name Type Description Default
dof str

The DOF, such as '101X+' or '1313RZ-'.

required

Returns:

Type Description
ndarray or None

A unit vector, or None when the DOF names no node this geometry has, has no axis (a node number alone), or is at a node measured in a cylindrical or spherical system, whose local axes depend on the node's position and are not computed here.

add_node
add_node(xyz: ArrayLike, node_id: int | None = None, color: int = 1, def_cs: int | None = None, disp_cs: int | None = None) -> int

Add a node at xyz and return its id.

Raises ValueError if a node with node_id already exists.

Parameters:

Name Type Description Default
xyz array_like

The node's coordinates in the global cartesian frame, in meters once units are defined. They are stored as given.

required
node_id int

Its identifier. One more than the highest node id when omitted.

None
color int

Its display color index.

1
def_cs int

The coordinate system the node is placed in, which a writer uses to give its position. xyz is not converted from it. The first coordinate system when omitted.

None
disp_cs int

The coordinate system displacements at the node are measured in. The first coordinate system when omitted.

None

Returns:

Type Description
int

The node's identifier.

add_nodes
add_nodes(xyz: ArrayLike) -> ndarray

Add nodes at xyz, numbered from one more than the highest id.

This is add_node for many nodes at once, with the defaults of add_node. Each array is copied once instead of once per node, so adding the thousands of nodes of a meshed plane is fast.

Parameters:

Name Type Description Default
xyz array_like

(n, 3) coordinates in the global cartesian frame, in meters once units are defined.

required

Returns:

Type Description
ndarray

The new nodes' identifiers, in order.

add_coordinate_system
add_coordinate_system(origin: ArrayLike = (0.0, 0.0, 0.0), rotation: ArrayLike | None = None, cs_id: int | None = None, name: str = '', cs_type: int = 0) -> int

Add a coordinate system and return its id.

Raises ValueError if a system with cs_id already exists.

Parameters:

Name Type Description Default
origin array_like

The system's origin, in meters once units are defined.

(0, 0, 0)
rotation array_like

A 3x3 matrix whose rows are the system's axes. Identity when omitted.

None
cs_id int

Its identifier. One more than the highest id when omitted.

None
name str

What to call it.

''
cs_type int

0 cartesian, 1 cylindrical, 2 spherical.

0

Returns:

Type Description
int

The coordinate system's identifier.

place_coordinate_system
place_coordinate_system(cs_id: int, *, origin: ArrayLike | None = None, angles: ArrayLike | None = None, rotation: ArrayLike | None = None) -> None

Rotate a coordinate system, move it, or both, as the 3-D view's rings and arrows do. The nodes placed in it move with it, keeping their coordinates in it.

Raises KeyError for an unknown cs_id, and ValueError when both angles and rotation are given.

Parameters:

Name Type Description Default
cs_id int

Which coordinate system.

required
origin array_like

The new origin, in the geometry's stored length unit (meters once its units are declared). Unchanged when omitted.

None
angles array_like

The rotation as angles in degrees about the fixed global X, then Y, then Z axes (rotate.frame_from_angles), the same angles the view's angle box and the box panel use. (0, 0, 0) removes any rotation. Unchanged when omitted.

None
rotation array_like

The rotation as a 3x3 matrix whose rows are the system's axes, instead of angles.

None

Returns:

Type Description
None
set_coordinate_system_type
set_coordinate_system_type(cs_id: int, cs_type: int) -> None

Make a coordinate system cartesian (0), cylindrical (1) or spherical (2). The nodes placed in it keep their coordinates, which now mean (r, theta, z) or (r, theta, phi), so they move.

Raises KeyError for an unknown cs_id, and ValueError for a type that is none of the three.

Parameters:

Name Type Description Default
cs_id int

Which coordinate system.

required
cs_type int

0 cartesian, 1 cylindrical, 2 spherical.

required

Returns:

Type Description
None
node_local_xyz
node_local_xyz(rows: Ids | None = None) -> ndarray

Each node's coordinates in the coordinate system it is placed in, as the node table shows them: (x, y, z) in a cartesian system, (r, theta, z) in a cylindrical one and (r, theta, phi) in a spherical one, angles in degrees.

Parameters:

Name Type Description Default
rows sequence of int

Which nodes, by row; all of them when omitted.

None

Returns:

Type Description
ndarray

(nodes, 3).

set_node_local_xyz
set_node_local_xyz(row: int, xyz: ArrayLike) -> None

Place the node at row at xyz, given in the coordinate system it is placed in (node_local_xyz).

Parameters:

Name Type Description Default
row int

The node's row.

required
xyz array_like

Its three coordinates in its placement system.

required

Returns:

Type Description
None
set_node_placement
set_node_placement(rows: Ids, cs_id: int) -> None

Place nodes in another coordinate system, keeping their coordinates: the same numbers, now in cs_id, so the nodes move to where those numbers put them.

Raises ValueError for a system the geometry does not have.

Parameters:

Name Type Description Default
rows int or sequence of int

The nodes, by row.

required
cs_id int

The coordinate system to place them in.

required

Returns:

Type Description
None
add_beams
add_beams(node_ids: Ids, group: int | None = None, color: int = 1, elem_type: int = 21) -> int

Add a chain of two-node line elements through the given nodes, in order, and return the element group's id.

This is how a drawn line (a traceline in some file formats) is stored, and it becomes a run of beams once the element group is given a section. Raises ValueError for fewer than two nodes, an unknown node, or an elem_type that is not a two-node line.

Parameters:

Name Type Description Default
node_ids sequence of int

The nodes the line runs through, in order; two at least.

required
group int

The element group the segments are added to. A new, unnamed element group when omitted; a drawn line is its own element group, named for the line.

None
color int

The display color index of every segment.

1
elem_type int

The two-node line code (ELEMENT_TYPES): a beam, unless the source says rod, pipe or rigid bar.

21

Returns:

Type Description
int

The element group the segments are in.

mixed_groups
mixed_groups() -> dict[int, list[str]]

{element group id: families} for every element group that holds more than one element family.

It is empty for any geometry that passes validate.

Returns:

Type Description
dict of int to list of str
split_groups_by_family
split_groups_by_family() -> dict[int, list[int]]

Split every element group that holds more than one element family.

The group keeps its first family, and each other family is moved into a new element group named with the old name and the family, such as 'wing quads', with the old group's properties. A file without element groups (UNV dataset 2412, the sdynpy layout) puts every element in one group, so this is applied when such a file is read.

Returns:

Type Description
dict of int to list of int

{old element group: [the new element groups made from it]}, empty when no group was mixed.

attach_drawn_lines
attach_drawn_lines(lines: Sequence[tuple[str, int, Sequence[Ids]]]) -> list[int]

Add drawn lines read from a format that stores them separately from elements, each as its own element group of two-node line elements with no properties.

This is the reading side of drawn_lines.

Parameters:

Name Type Description Default
lines sequence of (name, color, chains)

One entry per line: its name, its color index, and its runs, each a sequence of node ids in drawing order (a UNV line that lifts the pen has several).

required

Returns:

Type Description
list of int

The element groups made, one per line.

is_drawn_line
is_drawn_line(group: int) -> bool

Whether an element group is a drawn line.

It is when every element in it is a two-node line element and the element group has no properties. The app and every file writer use this one test. An empty element group is not a drawn line.

Parameters:

Name Type Description Default
group int

The element group's identifier.

required

Returns:

Type Description
bool
drawn_lines
drawn_lines() -> list[dict[str, Any]]

The drawn lines, in the form used by file formats that store tracelines separately from elements.

One dict {'group', 'name', 'color', 'chains'} per drawn-line element group (is_drawn_line), in element group order. The chains are the group's segments taken in element order, each a list of node ids, with a new chain wherever a segment does not start where the last one ended. An element group read from one polyline gives that polyline back, and one read from a UNV line that lifts the pen gives its runs back under the one element group. The color is that of the group's first element.

Returns:

Type Description
list of dict
group_of
group_of(elem_id: int) -> str

The name of the element group an element belongs to, or '' when that group is not declared.

Parameters:

Name Type Description Default
elem_id int

Which element.

required

Returns:

Type Description
str

The name of the element group it belongs to.

elements_in
elements_in(group: int | str) -> list[int]

The ids of the elements in an element group, given by id or name.

A name that no element group has gives an empty list; with two groups of one name, the first is used.

Parameters:

Name Type Description Default
group int or str

An element group, by identifier or by name.

required

Returns:

Type Description
list of int

The identifiers of the elements it holds.

nodes_in
nodes_in(groups: Ids) -> list[int]

The ids of the nodes used by the elements of these element groups, in ascending order. These are the nodes a merge limited to those groups may change.

Parameters:

Name Type Description Default
groups sequence of int

Element groups, by identifier.

required

Returns:

Type Description
list of int

The node identifiers.

Raises:

Type Description
ValueError

When a group is not in the geometry.

add_group
add_group(name: str = '', group_id: int | None = None, family: str = '') -> int

Declare an element group and return its id.

An empty element group is allowed: exodus files contain empty ones, and an element group has to exist before an element can be put in it. Raises ValueError if group_id is already used.

Parameters:

Name Type Description Default
name str

What to call the element group.

''
group_id int

Its identifier. One more than the highest id when omitted.

None
family str

The element family it is for, such as 'quads' (FAMILIES), kept in group_family: where an empty element group is listed.

''

Returns:

Type Description
int

The element group's identifier.

add_element
add_element(node_ids: Ids, elem_type: int | None = None, color: int = 1, group: int | None = None) -> int

Add an element and return its row index.

The element id is one more than the highest element id. Without elem_type, the type is chosen from the node count: 2 nodes a beam (21), 3 a triangle (41), 4 a quadrilateral (44); any other count needs elem_type. Raises ValueError for an unknown node or type, or for a group that holds a different element family.

Parameters:

Name Type Description Default
node_ids int or sequence of int

The nodes the element connects, in order.

required
elem_type int

The element type code. Inferred from the node count when omitted.

None
color int

Its display color index.

1
group int

The element group it belongs to, which is declared if it does not exist yet. When omitted, the first element group that holds this element's family (or is empty), otherwise a new one. An element group holds one family, so a beam added to a mesh of plates goes in an element group of its own.

None

Returns:

Type Description
int

The element's row index in the element arrays (not its id).

add_elements
add_elements(connectivity: Sequence[Ids], elem_types: Ids, groups: Ids) -> None

Add many elements at once, numbered from one more than the highest element id, with color 1.

The nodes and types are checked once for all of them, and an element group may hold only one element family, as in add_element. If any check fails, ValueError is raised and nothing is added.

Parameters:

Name Type Description Default
connectivity sequence of sequence of int

Each element's nodes, in order.

required
elem_types sequence of int

Each element's type code.

required
groups sequence of int

The element group each belongs to; an element group that does not exist yet is declared, with no name.

required

Returns:

Type Description
None
renumber_node
renumber_node(row: int, node_id: int) -> None

Give a node a new id, and update the elements that use it.

Elements refer to nodes by id, so the connectivity is updated too; otherwise every element at the node would lose it. Raises ValueError if another node already has the id.

Parameters:

Name Type Description Default
row int

Which node, by row.

required
node_id int

Its new identifier.

required

Returns:

Type Description
None
rename_group
rename_group(group_id: int, name: str) -> None

Give an element group a name.

Parameters:

Name Type Description Default
group_id int

The element group's id.

required
name str

Its new name; empty for none.

required

Returns:

Type Description
None

Raises:

Type Description
ValueError

When the geometry has no element group with that id.

move_elements
move_elements(elem_ids: Ids, group_id: int) -> int

Put elements in another element group, as dragging them onto it in the tree does.

An element group holds one element family, so elements of another family than the group holds, or than an empty group was made for (group_family), are refused, as are elements of two families at once. The groups they leave stay, empty if they held nothing else.

Parameters:

Name Type Description Default
elem_ids sequence of int

The elements, by id.

required
group_id int

The element group they go in.

required

Returns:

Type Description
int

How many elements moved: those not in the group already.

Raises:

Type Description
ValueError

When the group or an element is not in the geometry, or the families differ.

renumber_group
renumber_group(row: int, group_id: int) -> None

Give an element group a new id, and update its elements.

An element refers to its element group by id, so the elements are updated too; otherwise they would refer to an element group that no longer exists. Raises ValueError if another element group already has the id.

Parameters:

Name Type Description Default
row int

Which element group, by row.

required
group_id int

Its new identifier.

required

Returns:

Type Description
None
renumber_coordinate_system
renumber_coordinate_system(row: int, cs_id: int) -> None

Give a coordinate system a new id, and update the nodes that use it.

Both the placement and the displacement systems of the nodes are updated. Raises ValueError if another system already has the id.

Parameters:

Name Type Description Default
row int

Which system, by row.

required
cs_id int

Its new identifier.

required

Returns:

Type Description
None
delete_nodes
delete_nodes(node_ids: Ids) -> dict[str, int]

Remove nodes, and the elements that use them.

An element that uses a deleted node is deleted too. Ids that are not present are ignored.

Parameters:

Name Type Description Default
node_ids int or sequence of int

The identifiers, one or many.

required

Returns:

Type Description
dict of str to int

'nodes' and 'elements', the number of each removed.

coincident_nodes
coincident_nodes(tolerance: float, nodes: Ids | None = None) -> dict[int, int]

{node: the node it coincides with} for every node within tolerance of another.

Each node is mapped to the lowest id in its group, which is the node a merge keeps. Groups are chained: if a is within tolerance of b and b of c, all three are one point.

Parameters:

Name Type Description Default
tolerance float

How close two nodes must be to be one point, in the stored length unit: meters once units are defined.

required
nodes sequence of int

Only these nodes are considered, by id; a node outside them is not merged and nothing is merged into it, however close. Every node when omitted.

None

Returns:

Type Description
dict of int to int

Only the nodes that would be removed, each mapped to the node it becomes.

duplicate_elements
duplicate_elements(groups: Ids | None = None) -> dict[int, int]

{element id: the element it duplicates} for every solid element of the same type and on the same nodes as an earlier element, such as two bricks filling one cell.

The earlier element (in element order) is the one that stays. Only solids are checked: two beams on one line can be two members, and a plate on another plate's nodes is how a doubler or a layer is modeled, but two solids are never meant to fill one cell. Two element groups that overlap and share their nodes in the overlap (the bars of an X cross-section) put two elements in every cell there, which doubles the stiffness and mass of the region.

Parameters:

Name Type Description Default
groups sequence of int

Only the elements of these element groups, by id; every element when omitted.

None

Returns:

Type Description
dict of int to int

Each element that fills a cell another element already fills, mapped to that element.

merge_duplicate_elements
merge_duplicate_elements(groups: Ids | None = None) -> int

Remove duplicate solid elements (duplicate_elements).

The later element of each pair is removed, and the earlier one stays in its element group.

Parameters:

Name Type Description Default
groups sequence of int

Only the elements of these element groups, by id; every element when omitted.

None

Returns:

Type Description
int

How many elements were removed.

node_spacing
node_spacing(groups: Ids | None = None) -> float | None

The mesh's finest spacing: the shortest nonzero distance between two nodes of one element, such as a brick's shortest edge or half an edge of a quad8.

Merge Coincident Nodes sets its default tolerance to a quarter of this value. Nodes of parts meshed separately are usually much closer than that where the parts meet, and no two nodes of one element are.

Parameters:

Name Type Description Default
groups sequence of int

Only these element groups' elements, by id; every element when omitted.

None

Returns:

Type Description
float or None

The spacing, in the stored length unit; None when no element has two nodes at different positions.

coincident_spots
coincident_spots(tolerance: float, groups: Ids | None = None, exclude: Ids | None = None) -> list[list[int]]

The places where a merge would make one node.

Each place is a list of the node ids that coincide there, in ascending order, so the first is the node that stays. Merge Coincident Nodes marks these places in the view before anything is merged, so some of them can be left out.

Parameters:

Name Type Description Default
tolerance float

How close two nodes must be to be one, in the stored length unit: meters once units are defined.

required
groups sequence of int

Only the nodes used by these element groups' elements, by id; every node when omitted.

None
exclude sequence of int

Nodes left out, by id: they are not merged and nothing is merged into them.

None

Returns:

Type Description
list of list of int

One list per place, sorted by the node each keeps.

merge_folds
merge_folds(tolerance: float, groups: Ids | None = None, exclude: Ids | None = None) -> str | None

Why this merge would be refused, or None.

Returns the message merge_coincident_nodes raises when the tolerance would fold an element onto itself, so a panel can show it before the merge is applied.

Parameters:

Name Type Description Default
tolerance float

As merge_coincident_nodes.

required
groups sequence of int

As merge_coincident_nodes.

None
exclude sequence of int

As merge_coincident_nodes.

None

Returns:

Type Description
str or None
merge_collapses
merge_collapses(tolerance: float, groups: Ids | None = None, exclude: Ids | None = None) -> list[int]

The ids of the line elements this merge would remove.

These are the line elements (a rigid link, a spring, a beam) whose nodes would all become one node, so they no longer join anything. Merging a joint built with rigid links removes the links.

Parameters:

Name Type Description Default
tolerance float

As merge_coincident_nodes.

required
groups sequence of int

As merge_coincident_nodes.

None
exclude sequence of int

As merge_coincident_nodes.

None

Returns:

Type Description
list of int
merge_coincident_nodes
merge_coincident_nodes(tolerance: float, groups: Ids | None = None, exclude: Ids | None = None) -> dict[str, int]

Merge nodes that are at one point into one node.

Nodes within tolerance of each other (coincident_nodes) become the one with the lowest id: every element that uses one of them is changed to use that node, and the others are removed. Plates are only connected where they share nodes, so this is what connects a model built from separate planes at its edges.

The merge is refused with ValueError, naming the element, when the tolerance would fold an element onto itself (two of its own nodes within the tolerance), since that means the tolerance is larger than the mesh. A line element whose nodes would all become one, such as a rigid link across the gap the merge closes, is removed instead (merge_collapses). Solid elements the merge leaves on exactly the same nodes fill one cell twice, and the duplicates are removed (merge_duplicate_elements).

With groups, only those element groups are merged: the nodes their elements use are the candidates, so two groups picked together are joined to each other and to nothing else, and only their duplicate elements are removed. A merge over the whole geometry joins every part to every part it touches, which is usually more than intended; the app offers the merge on element groups only.

Parameters:

Name Type Description Default
tolerance float

How close two nodes must be to be one, in the stored length unit: meters once units are defined.

required
groups sequence of int

The element groups whose nodes are merged, by id. Every node of the geometry when omitted.

None
exclude sequence of int

Nodes left out of the merge, by id: they are not merged and nothing is merged into them. In the app, these are the places that were unpicked (coincident_spots).

None

Returns:

Type Description
dict of str to int

'merged', the number of nodes removed; 'into', the number of nodes they became; 'duplicates', the number of elements removed for filling a cell another already filled; and 'links', the number of line elements removed because their nodes became one.

align_reach
align_reach(groups: Ids | None = None) -> float | None

The default reach of Align Meshes: half the mesh size of the coarsest piece.

A piece is a set of elements connected by shared nodes. With this reach no node moves more than half an element of its own mesh. Parts with a gap between them need a larger reach, by the size of the gap.

Parameters:

Name Type Description Default
groups sequence of int

The element groups, by id; every element when omitted.

None

Returns:

Type Description
float or None

In the stored length unit; None when no element has a nonzero size.

align_moves
align_moves(reach: float, groups: Ids | None = None, exclude: Ids | None = None) -> list[list[int]]

The moves Align Meshes would make, each [node, onto]: a node of a coarser piece and the node of a finer piece it would move onto, so the two are at one point and can be merged with Merge Coincident Nodes.

A piece is a set of elements connected by shared nodes. Two pieces meshed at different sizes cannot be matched node for node, since their node counts differ, but each node of the coarser piece can be moved onto the nearest node of the finer one. No node moves more than reach. The rules:

  • Only nodes on the outside of the pieces move or are moved onto.
  • A node moves once, and onto a node no other node moves onto.
  • A node already at another node's position is a place to merge, not a move.
  • The nearest pairs are taken first. As a result, a washer's lower face moves onto the frame under it, and its upper face, whose nearest frame nodes are already taken, stays.
  • Of two pieces with the same mesh size, the later piece moves.
  • A move that would turn an element inside out is left out.

Parameters:

Name Type Description Default
reach float

How far a node may move, in the stored length unit.

required
groups sequence of int

The element groups whose pieces are aligned, by id; every element when omitted.

None
exclude sequence of int

Nodes left out, by id: they are not moved and nothing is moved onto them. In the app, these are the moves that were unpicked.

None

Returns:

Type Description
list of [int, int]

Sorted by the node moved.

align_folds
align_folds(moves: Sequence[Sequence[int]]) -> str | None

Why these moves would be refused, or None.

Returns the message align_meshes raises when a move would turn an element inside out (a solid's corner volume or a plate's normal changing sign), so a panel can show it before the moves are applied.

Parameters:

Name Type Description Default
moves sequence of [int, int]

As align_moves gives them.

required

Returns:

Type Description
str or None
align_meshes
align_meshes(reach: float, groups: Ids | None = None, exclude: Ids | None = None) -> dict[str, float]

Move the nodes of the coarser piece onto the nodes of the finer piece where they meet (align_moves), so Merge Coincident Nodes can join them.

This is for parts meshed separately at sizes that do not match: it makes their nodes coincide at their mating faces or where they overlap. Nothing is merged and no node is removed. A move that would turn an element inside out is left out by align_moves; the call raises ValueError, naming the element, only when the nodes left out with exclude make one of the other moves do so (align_folds).

Parameters:

Name Type Description Default
reach float

How far a node may move, in the stored length unit: meters once units are defined.

required
groups sequence of int

The element groups whose pieces are aligned, by id; every element of the geometry when omitted.

None
exclude sequence of int

Nodes left out, by id: neither moved nor moved onto.

None

Returns:

Type Description
dict

'moved', how many nodes moved; 'farthest', the longest move, in the stored length unit.

delete_coordinate_systems
delete_coordinate_systems(cs_ids: Ids) -> dict[str, int]

Remove coordinate systems, and give the nodes that used them to the first remaining system. A node placed in a removed system keeps its coordinates, now in the remaining one, so it moves.

Ids that are not present are ignored. Removing every coordinate system is refused with ValueError, since every node needs one.

Parameters:

Name Type Description Default
cs_ids int or sequence of int

The identifiers, one or many.

required

Returns:

Type Description
dict of str to int

'coordinate_systems', the number removed, and 'nodes_reassigned', the number of node placement and displacement references moved to the remaining system.

delete_groups
delete_groups(group_ids: Ids, keep: Ids = ()) -> dict[str, int]

Remove element groups with their elements, their properties, and the nodes no element outside them uses.

A node that an element of another element group also uses stays, so a neighboring part is not cut along the nodes the two share. Ids that are not present are ignored. To combine element groups instead, use merge_groups.

Parameters:

Name Type Description Default
group_ids int or sequence of int

The identifiers, one or many.

required
keep sequence of int

Nodes that stay whatever uses them (delete_elements).

()

Returns:

Type Description
dict of str to int

'groups', 'elements' and 'nodes', the number of each removed.

merge_refusal
merge_refusal(group_ids: Ids) -> str | None

Why these element groups cannot be merged, or None when they can.

There must be at least two, all in the geometry, holding the same element types and with the same properties. A merged element group has one material and one thickness or section, so merging groups that differ would change the model without saying so.

Parameters:

Name Type Description Default
group_ids sequence of int

The element groups, by identifier.

required

Returns:

Type Description
str or None
merge_groups
merge_groups(group_ids: Ids) -> dict[str, int]

Merge several element groups into the first one (Merge Element Groups).

The elements of the others are moved into the first group, and the others are removed with their properties. Raises ValueError with the reason from merge_refusal when the groups cannot be merged.

Parameters:

Name Type Description Default
group_ids sequence of int

The element groups; the first keeps its id, name and properties.

required

Returns:

Type Description
dict of str to int

'into', the id of the element group kept; 'groups', how many were merged into it; 'elements', how many elements moved.

delete_elements
delete_elements(elem_ids: Ids, nodes: bool = False, keep: Ids = ()) -> dict[str, int]

Remove elements by id. Ids that are not present are ignored.

With nodes, the nodes used only by these elements are removed too, which is what deleting an element group (delete_groups) and deleting elements in the app do. A node another element uses stays, and so does a node in keep: the project keeps the nodes its data is measured or solved at (Project.delete_elements), so redrawing a test geometry's panels leaves its measurement points. nodes is off by default because the merge removes the links it collapses and then remaps their nodes.

Parameters:

Name Type Description Default
elem_ids int or sequence of int

The identifiers, one or many.

required
nodes bool

Also remove the nodes only these elements used.

False
keep sequence of int

Nodes never removed that way.

()

Returns:

Type Description
dict of str to int

'elements', the number removed, and with nodes, 'nodes', the number of nodes removed.

save
save(path: str | PathLike) -> None

Write the geometry to a file of its own.

Parameters:

Name Type Description Default
path str or PathLike

Where to write it.

required

Returns:

Type Description
None
load classmethod
load(path: str | PathLike) -> Geometry

Read a geometry written by save.

Raises TypeError when the file holds something other than a geometry.

Functions:

pen_up_runs

pen_up_runs(entries: Sequence[int]) -> list[list[int]]

The runs of a traceline's node list, in which 0 lifts the pen.

A file's traceline is one node list in which 0 moves without drawing; a run of fewer than two nodes draws nothing and is left out.

element_family

element_family(code: int) -> str

Which family a 2412 element code belongs to.

Parameters:

Name Type Description Default
code int

The element type code.

required

Returns:

Type Description
str

One of FAMILIES, or 'points' or 'pyramids' (RARE_FAMILIES).

placed

placed(local: ArrayLike, kind: int, matrix: ArrayLike) -> ndarray

A point given in a coordinate system, converted to global cartesian.

kind is the system's CS_TYPES code and matrix its (4, 3) rows: three directions, then the origin. A cylindrical system gives (r, theta, z) and a spherical one (r, theta from +z, phi), with the angles in degrees in both, which is the convention of the universal file, Nastran's CORD2C and CORD2S, and sdynpy.

written_in

written_in(point: ArrayLike, kind: int, matrix: ArrayLike) -> ndarray

The inverse of placed: a global cartesian point in the coordinates of a system, so a file can be written with its nodes in the systems they were read in.

to_global

to_global(node_xyz: ArrayLike, node_def_cs: ArrayLike, cs_id: Ids, cs_type: ArrayLike, cs_matrix: ArrayLike) -> ndarray

Node coordinates given in each node's own placement system, converted to global cartesian, which is what Geometry stores.

A file gives each node's position in the coordinate system the node is placed in, its def_cs. Reading those numbers as global would put the node in the wrong place. A node whose system is not among the given systems, or is the global system, keeps its coordinates as written.

Parameters:

Name Type Description Default
node_xyz array - like

(nodes, 3) as the source wrote them.

required
node_def_cs array - like

The frame each node is placed in.

required
cs_id array - like

The frames themselves, as Geometry holds them.

required
cs_type array - like

The frames themselves, as Geometry holds them.

required
cs_matrix array - like

The frames themselves, as Geometry holds them.

required

Returns:

Type Description
ndarray

(nodes, 3) in the global cartesian frame.

to_local

to_local(node_xyz: ArrayLike, node_def_cs: ArrayLike, cs_id: Ids, cs_type: ArrayLike, cs_matrix: ArrayLike) -> ndarray

The inverse of to_global, for a writer that gives each node in the coordinate system it is placed in.

reconcile_type

reconcile_type(code: int, node_count: int) -> int

The descriptor that matches the number of nodes an element has, when the file's descriptor and node count disagree.

A file gives both, and they can contradict each other. The node count is taken as correct, and a descriptor with the wrong count is replaced by the one in the same family with that many nodes: 41 (a plane-stress triangle) with four nodes becomes 44, the plane-stress quadrilateral. Dataset 2412 numbers each family within one decade, triangles before quadrilaterals, which is how the replacement is found. When no descriptor in the family fits, the original is kept, since an element that cannot be identified is better kept as written than renamed to a guess.

Parameters:

Name Type Description Default
code int

The descriptor the file gave.

required
node_count int

How many nodes the file actually listed for it.

required

Returns:

Type Description
int

The descriptor to use.

face_corners

face_corners(code: int) -> int

How many corners a face element is drawn with: three for a triangle and four for a quadrilateral, whatever family its descriptor names and however many nodes it has.

It is read from the name in ELEMENT_TYPES and not from the node count, because a nine-node cubic triangle and a nine-node quadrilateral have the same count.

Parameters:

Name Type Description Default
code int

The element's descriptor.

required

Returns:

Type Description
int

3 or 4.

solid_faces

solid_faces(node_count: int) -> tuple[tuple[int, ...], ...]

The faces of a solid cell with this many nodes, each face as positions in the cell's node list.

A higher-order cell is drawn by its corner nodes, which come first in its node list. An unknown node count gives an empty tuple.

Parameters:

Name Type Description Default
node_count int

How many nodes the cell names.

required

Returns:

Type Description
tuple of tuple of int

deck_to_si

deck_to_si(properties: Mapping[int, Any], length_unit: str, mass_unit: str, inverse: bool = False) -> dict[int, Any]

A finite element deck's element group properties converted to SI from the consistent system length_unit, mass_unit and seconds make (or back, with inverse).

Force is mass times length per second squared, so a modulus scales by mass/length, a density by mass/length³, a thickness by length, a point mass by mass, a spring along an axis (force per length) by mass and a spring about one (force times length per radian) by mass·length². A beam section scales by its powers of length. Names and directions are kept.

implausible_materials

implausible_materials(properties: Mapping[int, Any]) -> list[str]

A sentence for each material whose modulus or density, in SI, is outside what a structural material has (PLAUSIBLE_MODULUS, PLAUSIBLE_DENSITY).