trusty.subspace¶
Subspace (reduced-order) runtime + offline precompute.
Build a :class:Basis from arrays (Basis.modal,
Basis.skinning_eigenmodes, Basis.corotated) or with
the builders in :mod:trusty.subspace.precompute.build_basis, then attach a
subspace body to the world with :func:add_hex_body / :func:add_tet_body;
the subspace module runs on every world and picks up every SubspaceBody. Contact for any subspace body (subspace floor, FEM
floor, cross-block subspace<->FEM) is governed by the single
trusty.contact.enable knob shared by every module in the simulator.
Basis
¶
A reduced basis for add_hex_body / add_tet_body. Skinning weights are stored unlifted, so bodies at different rest positions can share one basis.
modes
property
¶
(3N, r) modal columns; r = 0 for a skinning-eigenmode basis.
skinning_weights
property
¶
(N, m) skinning weights; m = 0 for a modal or corotated basis.
modal
staticmethod
¶
Modal basis from modes, a (3N, r) array of displacement modes with rows interleaved x, y, z per node.
skinning_eigenmodes
staticmethod
¶
Skinning-eigenmode basis from weights, an (N, m) array with one scalar skinning field per column. Each field drives a 12-DOF affine handle, so the reduced size is 12 m.
corotated
staticmethod
¶
Corotated basis: modes, a (3N, r) array of body-frame displacement modes, carried by a 12-DOF floating frame, so the body moves as A (X + U z) + p. Its reduced state is 12 + r long, frame first. Adding a body drops the mode directions that are affine fields of its rest positions, which the frame already carries, so r can be smaller than the array's column count.
save
¶
Write the basis to path (a NumPy .npz archive); read it back with trusty.subspace.load.
matrix
¶
The (3N, reduced_size) basis matrix B of a body whose rest positions are rest (N, 3): a modal or skinning body moves as rest + B z, a corotated one as A (X + B z) + p.
BasisKind
¶
CubatureRule
¶
Weighted element subset integrating a body's elastic energy.
SurfaceProxy
¶
add_hex_body
¶
add_hex_body(
world: World,
rest_mesh: HexMesh,
material: StableNeoHookean
| Corotational
| StableFung
| NeohookeanBW
| ARAP
| QuadraticVolume
| Hencky
| FiberReinforced
| HolzapfelGasserOgden,
density: float,
basis: Basis,
*,
friction_mu: float = 0.0,
surface_proxy: SurfaceProxy | None = None,
) -> int
Add a Q1 hex subspace body that moves in basis, lifted at the mesh's rest positions. Raises if the basis has a different node count or its columns are linearly dependent at that rest. A surface_proxy is published in place of the mesh boundary: contact, surface loads and pressure cavities act on it, and their face indices index its F. Each proxy vertex rides the rest element holding it (outside the mesh, the nearest one extended linearly).
add_tet_body
¶
add_tet_body(
world: World,
rest_mesh: TetMesh,
material: StableNeoHookean
| Corotational
| StableFung
| NeohookeanBW
| ARAP
| QuadraticVolume
| Hencky
| FiberReinforced
| HolzapfelGasserOgden,
density: float,
basis: Basis,
*,
friction_mu: float = 0.0,
surface_proxy: SurfaceProxy | None = None,
) -> int
Tet counterpart of add_hex_body.
deformed_positions
¶
Current deformed node positions of subspace body as an (N, 3) numpy array. The rest mesh before the first step.
fem_rest_operator
¶
Full-space rest stiffness operator (3N, 3N) of the world's single FEM solid: the elastic K plus every fiber muscle (actuators.add_fiber_muscle) the world declares, at the gain it is simulated with. This is the operator the basis is decomposed from, so declaring a muscle on the precompute world is all it takes for the basis to account for it. Compliant pins to bodies are deliberately excluded -- one is a both-sided coupled term whose stiffness on the pinned body depends on how freely its target body moves, so folding a grounded k I3 would delete the pinned motion a movable target body exists to permit.
fem_elastic_stiffness_matrix
¶
Elastic stiffness (3N, 3N) at the rest configuration of the world's single FEM solid -- the elastic block of fem_rest_operator.
fem_muscle_stiffness_matrix
¶
Muscle stiffness (3N, 3N) at rest: sum_muscles A_musc, without the elastic block. Only the activation-mode solve needs this alone (its rest contraction force is -A_musc x0); the eigenproblem wants fem_rest_operator.
fem_mass_matrix
¶
Lumped nodal mass of the world's single FEM solid as a length-3N diagonal, each node's mass repeated 3 times (scalar-DOF indexable).
fem_pinned_dofs
¶
Sorted scalar DOF indices of the nodes the world holds in place with exact pins. Slice these out before a generalised eigensolve.
fit_cubature
¶
fit_cubature(
world: World,
body: int,
*,
rtol: float = 0.0001,
block: int = 4,
energy_fraction: float = 1.0,
mass_regularization: float = 0.0,
max_points: int = -1,
) -> CubatureRule
Fit body's elastic cubature rule against the spectrum of its reduced rest Hessian, store it on the body, and return it. energy_fraction < 1 keeps only the softest modes.
set_cubature
¶
Store rule (e.g. a cached fit_cubature result) on body; CubatureRule([], []) restores full integration. Raises unless the rule's element ids are strictly ascending inside body and its weights finite, non-negative and not all zero.
set_project_positive_definite
¶
PSD-project this module's Hessians on every Newton iteration (default off). Call before the first step().
state
¶
Reduced state z of subspace body after the last accepted step. Returns a length-r numpy array (12 + r for a corotated body, frame first), zero before the first step.