Skip to content

trusty

Top-level classes and functions: the world and its settings, materials, meshes and solver reports. Each module has its own page in the menu.

Trusty โ€” a modular physics simulation library.

Backend

Bases: Enum

AUTO class-attribute instance-attribute

AUTO = 0

CPU class-attribute instance-attribute

CPU = 1

CUDA class-attribute instance-attribute

CUDA = 2

ACCELERATE class-attribute instance-attribute

ACCELERATE = 3

ConvergenceCriterion

Bases: Enum

GradientInfNorm class-attribute instance-attribute

GradientInfNorm = 0

VelocityAvgL2 class-attribute instance-attribute

VelocityAvgL2 = 1

VelocityInfNorm class-attribute instance-attribute

VelocityInfNorm = 2

RelativeVelocityInfNorm class-attribute instance-attribute

RelativeVelocityInfNorm = 3

HexMesh

vertices property

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

elements property

elements: ndarray[int32, (N, 8)]

num_nodes property

num_nodes: int

num_elems property

num_elems: int

IterReport

iter property

iter: int

energy property

energy: float

accepted_energy property

accepted_energy: float

residual property

residual: float

step_size property

step_size: float

initial_step_size property

initial_step_size: float

linear_iters property

linear_iters: int

bt_iters property

bt_iters: int

line_search_failed property

line_search_failed: bool

projected_fallback property

projected_fallback: bool

term_energies property

term_energies: list[list[tuple[str, float]]]

LinearSystemReport

iter property

iter: int

b property

b: ndarray[float64, (N,)]

x property

x: ndarray[float64, (N,)]

K property

K: csc_matrix[float]

LinearSolverType

Bases: Enum

Direct class-attribute instance-attribute

Direct = 0

Pcg class-attribute instance-attribute

Pcg = 1

LoggingObserver

ARAP

Resists only departure from a rotation, with no volume term, for shape deformation in geometry processing rather than a physical material.

Corotational

Linear elasticity in a frame that rotates with the material, for stiff bodies that rotate far but deform little.

FiberReinforced

A soft matrix stiffened along one fiber direction that resists only stretching, for tendon, ligament and other fibrous tissue.

Hencky

Linear elasticity in logarithmic strain, for stiff solids such as metals, and the elastic part of HenckyVonMises.

HenckyVonMises

Hencky elasticity with von Mises plasticity and hardening, for ductile metals such as steel and aluminium that stay deformed once they yield.

HolzapfelGasserOgden

A soft matrix stiffened exponentially along up to three fiber families with dispersion, for arterial walls, the annulus fibrosus and other layered fibrous tissue.

NeohookeanBW

The classical Bonet and Wood Neo-Hookean, for matching textbook results and other codes; its energy is infinite at zero volume, so elements cannot invert.

QuadraticVolume

Resists change of volume only, with no shear stiffness, for fluid-like material that flows freely in shape.

StableFung

Stable Neo-Hookean that stiffens exponentially as it stretches, for soft biological tissue.

StableNeoHookean

The default: a rubber-like solid that stays robust under large compression and inversion.

MaterialModel

Bases: Enum

StableNeoHookean class-attribute instance-attribute

StableNeoHookean = 0

Corotational class-attribute instance-attribute

Corotational = 1

StableFung class-attribute instance-attribute

StableFung = 2

NeohookeanBW class-attribute instance-attribute

NeohookeanBW = 3

ARAP class-attribute instance-attribute

ARAP = 4

QuadraticVolume class-attribute instance-attribute

QuadraticVolume = 5

Hencky class-attribute instance-attribute

Hencky = 6

FiberReinforced class-attribute instance-attribute

FiberReinforced = 7

HolzapfelGasserOgden class-attribute instance-attribute

HolzapfelGasserOgden = 8

HenckyVonMises class-attribute instance-attribute

HenckyVonMises = 9

NewtonConfig

max_iters property writable

max_iters: int

tolerance property writable

tolerance: float

criterion property writable

criterion: ConvergenceCriterion
line_search: bool

max_line_search_iterations property writable

max_line_search_iterations: int

linear_solver property writable

linear_solver: LinearSolverType

pcg_max_iters property writable

pcg_max_iters: int

pcg_tolerance property writable

pcg_tolerance: float

sparsity_cache_enabled property writable

sparsity_cache_enabled: bool

SolveReport

iterations property

iterations: int

lagged_iterations property

lagged_iterations: int

final_residual property

final_residual: float

converged property

converged: bool

per_iteration property

per_iteration: list[IterReport]

SolverObserver

wants_linear_system

wants_linear_system() -> bool

wants_term_energy

wants_term_energy() -> bool

on_iteration

on_iteration(report: IterReport) -> None

on_step_end

on_step_end(report: SolveReport) -> None

TetMesh

vertices property

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

elements property

elements: ndarray[int32, (N, 4)]

num_nodes property

num_nodes: int

num_elems property

num_elems: int

TimeStepping

Bases: Enum

BackwardEuler class-attribute instance-attribute

BackwardEuler = 0

BDF2 class-attribute instance-attribute

BDF2 = 1

QuasiStatic class-attribute instance-attribute

QuasiStatic = 2

Static class-attribute instance-attribute

Static = 3

World

backend property

backend: Backend

Backend the world's solver runs on.

timestep property

timestep: float

Step size dt (seconds).

gravity property

gravity: tuple[float, float, float]

Uniform body acceleration (m/s^2), as an (x, y, z) tuple.

time_stepping property

time_stepping: TimeStepping

Time integration scheme.

max_lagged_iterations property

max_lagged_iterations: int

Most solves per step; each re-freezes the lagged terms (friction) at the last one's result. A step stops early once a solve moves nothing.

step

step() -> None

last_report

last_report() -> SolveReport

The last step's solve report; a default-constructed report before the first step.

set_observer

set_observer(observer: SolverObserver) -> None

alive

alive(body: int) -> bool

Whether the handle refers to a live entity of this world. False for a destroyed entity and for an integer no factory returned; a handle from a different world is not detected.

destroy

destroy(entity: int) -> None

Destroy a live entity (a body, joint, pin, actuator, ...) and every entity that cannot outlive it. Legal between any two steps; the next step simulates the world without it.

capabilities

capabilities() -> set[str]

Return the feature capabilities compiled into this build.

library_version

library_version() -> str

Return the Trusty library version as a string.

make_beam_hex_mesh

make_beam_hex_mesh(
    size: tuple[float, float, float],
    res: tuple[int, int, int],
) -> HexMesh

Structured axis-aligned hex mesh; size is (Lx, Ly, Lz), res is (nx, ny, nz).

make_beam_tet_mesh

make_beam_tet_mesh(
    size: tuple[float, float, float],
    res: tuple[int, int, int],
) -> TetMesh

Structured axis-aligned tet mesh (6-tet Kuhn decomposition per hex cell). size is (Lx, Ly, Lz), res is (nx, ny, nz).

make_hex_mesh

make_hex_mesh(
    vertices: ndarray[float64, (N, 3)],
    hexes: ndarray[int32, (N, 8)],
) -> HexMesh

Wrap externally-built (vertices, hexes) arrays into a HexMesh. Use this when reading via meshio from Python.

make_tet_mesh

make_tet_mesh(
    vertices: ndarray[float64, (N, 3)],
    tets: ndarray[int32, (N, 4)],
) -> TetMesh

Wrap externally-built (vertices, tets) arrays into a TetMesh. Use this when reading via meshio from Python.

get_max_threads

get_max_threads() -> int

Worker threads currently available -- the machine's concurrency unless set_max_threads lowered it.

read_tet_msh

read_tet_msh(path: str) -> TetMesh

Read a Gmsh .msh file (format 2.2) and return the contained tet mesh. Only 4-node tetrahedra are extracted; orientation is fixed to det([X1-X0|X2-X0|X3-X0]) > 0.

set_max_threads

set_max_threads(num_threads: int) -> None

Cap the worker-thread count for this process. Unset by default, so a lone simulation uses every core. Set 1 when running N independent simulations in parallel (one per process, or one per thread since step() releases the GIL): their internal parallelism otherwise oversubscribes the machine and the pool loses most of what it gained. Takes effect on the next parallel region, so it can be raised or lowered at any time.

triangle_components

triangle_components(
    triangles: ndarray[int32, (N, M)],
) -> ndarray[int32, (N,)]

Connected component (through shared vertices) of each row of a (F, 3) triangle array, numbered from 0 in order of each component's first triangle. Splits a solid's boundary into its outer surface and the surface of each internal void.

write_hex_obj

write_hex_obj(path: str, mesh: HexMesh) -> None

write_tet_obj

write_tet_obj(path: str, mesh: TetMesh) -> None

generate_particle_grid

generate_particle_grid(
    lo,
    hi,
    spacing: float,
    mode: SamplingMode = "poisson",
    *,
    seed: int = 12345,
    poisson_r_factor: float = 1.0,
) -> np.ndarray

Fill an axis-aligned box with MPM particles.

Parameters:

Name Type Description Default
lo (array - like, shape(3))

Lower / upper corners of the seed box.

required
hi (array - like, shape(3))

Lower / upper corners of the seed box.

required
spacing float

Target inter-particle spacing. For mode='uniform' this is the lattice pitch. For mode='poisson' the minimum pairwise distance is spacing * poisson_r_factor.

required
mode ('poisson', 'uniform')

Sampling strategy. Default 'poisson' (Bridson blue-noise).

'poisson'
seed int

RNG seed for Poisson-disk sampling (ignored for uniform).

12345
poisson_r_factor float

Scales min_r for Poisson; smaller โ‡’ denser sampling.

1.0

Returns:

Type Description
np.ndarray of shape (N, 3), dtype float64.

add_floor_plane

add_floor_plane(
    world, z: float = 0.0, *, friction_mu: float = 0.0
)

Attach a horizontal floor plane (origin=(0,0,z), normal=(0,0,1)) to world as a contact.ContactPlane component. Returns the new entity (an int). friction_mu is the floor's Coulomb coefficient; 0 (the default) is a frictionless floor. Requires a build with contact enabled (contact.add_plane is only registered then).

save_checkpoint

save_checkpoint(world, path) -> None

Write the state world's next step starts from to the .npz file path.

load_checkpoint

load_checkpoint(world, path) -> None

Restore save_checkpoint's file into world, built by the same script, so its next step continues the saved trajectory.