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

HexMesh

vertices property

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

hexes property

hexes: 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

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]

FungParams

StableFung's parameters: the ground state (mu0, lam) plus the exponential-hardening pair (mu1, gamma).

mu0 property writable

mu0: float

lam property writable

lam: float

mu1 property writable

mu1: float

gamma property writable

gamma: float

from_young_poisson staticmethod

from_young_poisson(E: float, nu: float) -> FungParams

The set at Young's modulus E (Pa) and Poisson's ratio nu.

FungParamsGrid

A regular axis-aligned grid of the parameters a law reads, over a body's rest space. Sampling clamps to the edge outside the box.

GridInterpolation

Bases: Enum

Linear class-attribute instance-attribute

Linear = 0

Nearest class-attribute instance-attribute

Nearest = 1

LameParams

Isotropic Lame pair (Pa) -- the parameters of every (mu, lam) model.

mu property writable

mu: float

lam property writable

lam: float

from_young_poisson staticmethod

from_young_poisson(E: float, nu: float) -> LameParams

The set at Young's modulus E (Pa) and Poisson's ratio nu.

LameParamsGrid

A regular axis-aligned grid of the parameters a law reads, over a body's rest space. Sampling clamps to the edge outside the box.

LinearSolverType

Bases: Enum

Direct class-attribute instance-attribute

Direct = 0

Pcg class-attribute instance-attribute

Pcg = 1

LoggingObserver

ARAP

Corotational

NeohookeanBW

QuadraticVolume

StableFung

StableNeoHookean

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

NewtonConfig

max_iters property writable

max_iters: int

tolerance property writable

tolerance: float

criterion property writable

criterion: ConvergenceCriterion
line_search: bool

project_positive_definite property writable

project_positive_definite: 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

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)]

tets property

tets: 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.

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.

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 (TetMesh has no Python constructor for the underlying connectivity).

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.

check_capabilities

check_capabilities(*names: str) -> None

Raise RuntimeError if any named capability is missing from this build of trusty. Use at the top of examples to fail fast with a clear message instead of dying inside a builder later.

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).