Skip to content

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

modes: ndarray[float64, (N, M)]

(3N, r) modal columns; r = 0 for a skinning-eigenmode basis.

skinning_weights property

skinning_weights: ndarray[float64, (N, M)]

(N, m) skinning weights; m = 0 for a modal or corotated basis.

num_nodes property

num_nodes: int

reduced_size property

reduced_size: int

kind property

kind: BasisKind

modal staticmethod

modal(modes: ndarray[float64, (N, M)]) -> Basis

Modal basis from modes, a (3N, r) array of displacement modes with rows interleaved x, y, z per node.

skinning_eigenmodes staticmethod

skinning_eigenmodes(
    weights: ndarray[float64, (N, M)],
) -> Basis

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(modes: ndarray[float64, (N, M)]) -> Basis

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

save(path: str) -> None

Write the basis to path (a NumPy .npz archive); read it back with trusty.subspace.load.

matrix

matrix(
    rest: ndarray[float64, (N, 3)],
) -> ndarray[float64, (N, M)]

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

Bases: Enum

Which columns a Basis has.

Modal class-attribute instance-attribute

Modal = 0

SkinningEigenmodes class-attribute instance-attribute

SkinningEigenmodes = 1

Corotated class-attribute instance-attribute

Corotated = 2

CubatureRule

Weighted element subset integrating a body's elastic energy.

elements property

elements: ndarray[int32, (N,)]

(n,) element ids, ascending.

weights property

weights: ndarray[float64, (N,)]

(n,) non-negative weights.

rel_residual property

rel_residual: float

Relative fit residual (0 for a rule built from arrays).

SurfaceProxy

A triangle surface a subspace body publishes in place of its mesh boundary.

V property

V: ndarray[float64, (N, 3)]

(n, 3) rest positions, world coordinates (m).

F property

F: ndarray[int32, (N, 3)]

(m, 3) triangles into V.

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

deformed_positions(
    world: World, body: int
) -> ndarray[float64, (N, 3)]

Current deformed node positions of subspace body as an (N, 3) numpy array. The rest mesh before the first step.

fem_rest_operator

fem_rest_operator(
    world: World,
) -> scipy.sparse.csc_matrix[float]

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

fem_elastic_stiffness_matrix(
    world: World,
) -> scipy.sparse.csc_matrix[float]

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

fem_muscle_stiffness_matrix(
    world: World,
) -> scipy.sparse.csc_matrix[float]

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

fem_mass_matrix(world: World) -> ndarray[float64, (N,)]

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

fem_pinned_dofs(world: World) -> list[int]

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.

load

load(path: str) -> Basis

Read a basis written by Basis.save.

num_bodies

num_bodies(world: World) -> int

Number of subspace bodies in the world.

project_positive_definite

project_positive_definite(world: World) -> bool

set_cubature

set_cubature(
    world: World, body: int, rule: CubatureRule
) -> None

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

set_project_positive_definite(
    world: World, project: bool
) -> None

PSD-project this module's Hessians on every Newton iteration (default off). Call before the first step().

state

state(world: World, body: int) -> ndarray[float64, (N,)]

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.