newton.solvers.SolverStyle3D#

class newton.solvers.SolverStyle3D(model, *, config=None, iterations=_LEGACY_UNSET, linear_iterations=_LEGACY_UNSET, drag_spring_stiff=_LEGACY_UNSET, enable_mouse_dragging=_LEGACY_UNSET)[source]#

Bases: SolverBase

Projective dynamics based cloth solver.

References

  1. Baraff, D. & Witkin, A. “Large Steps in Cloth Simulation.”

  2. Liu, T. et al. “Fast Simulation of Mass-Spring Systems.”

Implicit-Euler method solves the following non-linear equation:

\[\begin{split}(M / dt^2 + H(x)) \cdot dx &= (M / dt^2) \cdot (x_{prev} + v_{prev} \cdot dt - x) + f_{ext}(x) + f_{int}(x) \\ &= (M / dt^2) \cdot (x_{prev} + v_{prev} \cdot dt + (dt^2 / M) \cdot f_{ext}(x) - x) + f_{int}(x) \\ &= (M / dt^2) \cdot (x_{inertia} - x) + f_{int}(x)\end{split}\]
Notations:
  • \(M\): mass matrix

  • \(x\): unsolved particle position

  • \(H\): Hessian matrix (function of x)

  • \(P\): PD-approximated Hessian matrix (constant)

  • \(A\): \(M / dt^2 + H(x)\) or \(M / dt^2 + P\)

  • \(rhs\): Right hand side of the equation: \((M / dt^2) \cdot (x_{inertia} - x) + f_{int}(x)\)

  • \(res\): Residual: \(rhs - A \cdot dx_{init}\), or rhs if \(dx_{init} = 0\)

See also

newton.solvers.style3d exposes helper functions that populate Style3D cloth data on a ModelBuilder.

Example

Build a mesh-based cloth with newton.solvers.style3d.add_cloth_mesh():

from newton.solvers import style3d

builder = newton.ModelBuilder()
SolverStyle3D.register_custom_attributes(builder)
style3d.add_cloth_mesh(
    builder,
    pos=wp.vec3(0.0, 0.0, 0.0),
    rot=wp.quat_identity(),
    vel=wp.vec3(0.0, 0.0, 0.0),
    vertices=mesh.vertices.tolist(),
    indices=mesh.indices.tolist(),
    density=0.3,
    tri_aniso_ke=wp.vec3(1.0e2, 1.0e2, 1.0e1),
    edge_aniso_ke=wp.vec3(2.0e-5, 1.0e-5, 5.0e-6),
)

Or build a grid with newton.solvers.style3d.add_cloth_grid():

style3d.add_cloth_grid(
    builder,
    pos=wp.vec3(-0.5, 0.0, 2.0),
    rot=wp.quat_identity(),
    dim_x=64,
    dim_y=32,
    cell_x=0.1,
    cell_y=0.1,
    vel=wp.vec3(0.0, 0.0, 0.0),
    mass=0.1,
    tri_aniso_ke=wp.vec3(1.0e2, 1.0e2, 1.0e1),
    edge_aniso_ke=wp.vec3(2.0e-4, 1.0e-4, 5.0e-5),
)
class Config(*, iterations=10, linear_iterations=10, drag_spring_stiff=100.0, enable_mouse_dragging=False)#

Bases: object

Runtime options for SolverStyle3D.

The solver keeps the supplied object as SolverStyle3D.config. Changes made before a subsequent SolverStyle3D.step() take effect on that step. Captured CUDA graphs must be recaptured to use updated configuration values.

Example

Configure a solver for an existing model:

config = SolverStyle3D.Config(iterations=20, linear_iterations=10)
solver = SolverStyle3D(model, config=config)
solver.config.iterations = 30
__init__(*, iterations=10, linear_iterations=10, drag_spring_stiff=100.0, enable_mouse_dragging=False)#
drag_spring_stiff: float = 100.0#

Stiffness of the mouse-dragging spring [N/m].

enable_mouse_dragging: bool = False#

Whether to enable the mouse-dragging kernel.

iterations: int = 10#

Number of non-linear iterations per step. Must be at least 1.

linear_iterations: int = 10#

Number of PCG iterations per non-linear iteration, capped by PCG capacity (999 by default).

classmethod register_custom_attributes(builder)#

Declare Style3D custom attributes under the style3d namespace.

See also

Custom Attributes for the custom attribute system overview.

__init__(model, *, config=None, iterations=_LEGACY_UNSET, linear_iterations=_LEGACY_UNSET, drag_spring_stiff=_LEGACY_UNSET, enable_mouse_dragging=_LEGACY_UNSET)#

Initialize the Style3D solver.

Deprecated since version 1.8: The iterations, linear_iterations, drag_spring_stiff, and enable_mouse_dragging keyword arguments are deprecated. Pass their values through config=SolverStyle3D.Config(...) instead.

Parameters:
Raises:

TypeError – If config is not a Config or None, or if a configuration is combined with legacy keyword options.

step(state_in, state_out, control, contacts, dt, *, observables=None)#

Advance the Style3D solver by one time step.

The solver performs non-linear projective dynamics iterations with optional collision handling. During the solve, positions in state_in are updated in-place to the current iterate; the final positions and velocities are written to state_out.

Parameters:
Raises:

ValueError – If Config.iterations is less than 1. Neither input nor output state is modified in this case.

config: Config#

Live solver options, retained by reference when supplied at construction.

Edit fields or replace this object with a Config between calls to step(). Captured CUDA graphs must be recaptured after changes.

property drag_spring_stiff: float#

Legacy alias for Config.drag_spring_stiff.

Deprecated since version 1.8: Use solver.config.drag_spring_stiff instead.

property enable_mouse_dragging: bool#

Legacy alias for Config.enable_mouse_dragging.

Deprecated since version 1.8: Use solver.config.enable_mouse_dragging instead.

property linear_iterations: int#

Legacy alias for Config.linear_iterations.

Deprecated since version 1.8: Use solver.config.linear_iterations instead.

property nonlinear_iterations: int#

Legacy alias for Config.iterations.

Deprecated since version 1.8: Use solver.config.iterations instead.