trusty.fem¶
FEM solid bodies.
ElementOrder
¶
ElementMaterials
¶
Which material every element of a body runs: element e runs materials[material_id[e]]. material_id is an int array with one entry per element of the mesh. A body of one material takes the material itself, not an ElementMaterials. A material's per-element arrays (a (num_elements,) youngs_modulus, say) hold one value per element of that material, in element order.
add_hex_solid
¶
add_hex_solid(
world: World,
mesh: HexMesh,
material: ElementMaterials,
density: float,
*,
order: ElementOrder = ElementOrder.Linear,
consistent_mass: bool = True,
friction_mu: float = 0.0,
initial_positions: ndarray[float64, (N, 3)]
| None = None,
) -> int
Add a hex solid body running material: a material: a constitutive model with the parameters it reads, or an ElementMaterials giving each element its own material. order selects Q1 linear (default), Q2 Lagrange (Quadratic), or Q2 serendipity (QuadraticSerendipity); quadratic orders promote the linear mesh internally. consistent_mass (default True) runs a quadratic body on the consistent mass matrix; False falls back to HRZ-lumped mass. Linear bodies are lumped either way. friction_mu is the body's surface Coulomb coefficient (>= 0); 0 is frictionless. initial_positions (num_vertices, 3) is where the mesh vertices start (default: the rest vertices); a start that differs from mesh leaves the body strained, relaxing toward its rest shape.
add_tet_solid
¶
add_tet_solid(
world: World,
mesh: TetMesh,
material: ElementMaterials,
density: float,
*,
order: ElementOrder = ElementOrder.Linear,
consistent_mass: bool = True,
friction_mu: float = 0.0,
initial_positions: ndarray[float64, (N, 3)]
| None = None,
) -> int
Add a tet solid body running material (a material, or an ElementMaterials). order selects P1 linear (default) or P2 (Quadratic); P2 promotes the linear mesh internally. consistent_mass (default True) runs a P2 body on the consistent mass matrix; False falls back to HRZ-lumped mass. friction_mu is the body's surface Coulomb coefficient (>= 0); 0 is frictionless. initial_positions (num_vertices, 3) is where the mesh vertices start (default: the rest vertices); a start that differs from mesh leaves the body strained, relaxing toward its rest shape.
add_embedded_solid
¶
add_embedded_solid(
world: World,
V: ndarray[float64, (N, 3)],
F: ndarray[int32, (N, 3)],
voxel_size: float,
material: StableNeoHookean
| Corotational
| StableFung
| NeohookeanBW
| ARAP
| QuadraticVolume
| Hencky
| FiberReinforced
| HolzapfelGasserOgden,
density: float,
*,
sizing_field: Callable[[ndarray[float64, (3,)]], float]
| None = None,
max_level: int = 0,
order: ElementOrder = ElementOrder.Linear,
friction_mu: float = 0.0,
initial_linear_map: ndarray[float64, (3, 3)]
| None = None,
initial_translation: tuple[float, float, float] = (
0.0,
0.0,
0.0,
),
) -> int
Voxelize (V, F) into a hex solid carrying (V, F) as its surface. voxel_size is the coarsest cell size; sizing_field (world point -> target edge length, default voxel_size) refines cells by up to max_level halvings. order selects Q1/Q2 interpolation. friction_mu is the body's surface Coulomb coefficient (>= 0); 0 is frictionless. The body starts at x -> A x + t of its rest positions, with A = initial_linear_map (default identity) and t = initial_translation; a non-rigid A starts it strained, relaxing toward V.
set_velocity
¶
Overwrite per-node velocities for a body. v must have shape (num_nodes, 3). Applied at the next step(); only this body's history is rewritten.
elements
¶
Element connectivity (num_elements, k) of a solid body, indices into positions(world, body): k = 4 (P1 tet), 8 (Q1 hex), 10 (P2 tet), 20 (Q2 serendipity hex) or 27 (Q2 hex).
positions
¶
The current deformed node positions (num_nodes, 3) of any solid body, regardless of element family (linear or quadratic).
surface_positions
¶
Current positions (V, 3) of the body's surface vertices, the rows trusty.surface.mesh(world, body) indexes: its nodes, or for an embedded body their interpolation at each surface vertex.
interpolate_to_surface
¶
interpolate_to_surface(
world: World,
body: int,
nodal_values: ndarray[float64, (N,)],
) -> ndarray[float64, (N,)]
Carry a per-node scalar field (one value per node, e.g. fem.von_mises(..., nodal=True)) onto the body's surface vertices, through the map surface_positions reads positions through. Returns one value per surface vertex.
von_mises
¶
Von Mises Cauchy stress (Pa) of a solid at the current deformation. nodal=True returns a smooth per-node field (length num_nodes); nodal=False returns raw per-element values (length num_elements). A plastic body is read at its current plastic state.
cauchy_stress
¶
Per-element Cauchy stress tensor sigma = P F^T / det F (Pa) of a solid at the current deformation, volume-averaged over each element's quadrature points. Returns shape (num_elements, 3, 3). The normal traction on a plane with unit normal n is n @ sigma @ n, negative in compression.
strain_energy_density
¶
Hyperelastic strain energy density (J/m^3 = Pa) of a solid at the current deformation -- unlike von Mises it includes the volumetric (pressure) term. nodal=True returns a smooth per-node field (length num_nodes); nodal=False returns raw per-element values (length num_elements).
equivalent_strain
¶
Equivalent strain sqrt(2/3 e_dev : e_dev) (dimensionless) of a solid at the current deformation, where e_dev = e - tr(e)/3 I is the deviatoric part of the log strain e = 1/2 log(F^T F). It reads the deformation alone, so regions of any stiffness or model compare directly; pure volume change reads 0. nodal=True returns a smooth per-node field (length num_nodes); nodal=False returns raw per-element values (length num_elements).
plastic_strain
¶
Accumulated equivalent plastic strain (dimensionless) of a body running a plastic model, on any discretization. nodal=True returns a per-node field recovered by volume-weighted averaging (length num_nodes, matching positions); nodal=False returns raw per-element values (length num_elements); an element whose model has no material state reads 0. Raises when none of the body's models is plastic.
set_project_positive_definite
¶
PSD-project this module's Hessians on every Newton iteration (default off). Call before the first step().