newton.Model#
- class newton.Model(device=None)#
Holds the definition of the simulation model
This class holds the non-time varying description of the system, i.e.: all geometry, constraints, and parameters used to describe the simulation.
Note
It is strongly recommended to use the ModelBuilder to construct a simulation rather than creating your own Model object directly, however it is possible to do so if desired.
Methods
__init__
([device])Initializes the Model object.
control
([requires_grad, clone_variables])Returns a control object for the model.
Counts the maximum number of rigid contact points that need to be allocated.
state
([requires_grad])Returns a state object for the model
Attributes
Maximum number of soft contacts that can be registered
Indicates whether the model was finalized (see
ModelBuilder.finalize()
) with gradient computation enabled.Number of articulation environments that were added to the ModelBuilder via add_builder.
Particle positions, shape [particle_count, 3], float.
Particle velocities, shape [particle_count, 3], float.
Particle mass, shape [particle_count], float.
Particle inverse mass, shape [particle_count], float.
Particle radius, shape [particle_count], float.
Maximum particle radius (useful for HashGrid construction).
Particle normal contact stiffness (used by
SemiImplicitSolver
).Particle normal contact damping (used by
SemiImplicitSolver
).Particle friction force stiffness (used by
SemiImplicitSolver
).Particle friction coefficient.
Particle cohesion strength.
Particle adhesion strength.
HashGrid instance used for accelerated simulation of particle interactions.
Particle enabled state, shape [particle_count], bool.
Maximum particle velocity (to prevent instability).
List of keys for each shape.
Rigid shape transforms, shape [shape_count, 7], float.
Rigid shape body index, shape [shape_count], int.
Rigid shape flags, shape [shape_count], uint32.
Mapping from body index to list of attached shape indices.
Rigid shape contact materials.
Shape geometry properties (geo type, scale, thickness, etc.).
List of source geometry objects (e.g., wp.Mesh, SDF) used for rendering and broadphase.
List of finalized wp.Mesh objects.
List of finalized SDF objects.
Parameters used to define the ground plane, typically set by ModelBuilder.
Collision group of each shape, shape [shape_count], int.
Mapping from collision group to list of shape indices.
Pairs of shape indices that should not collide.
Collision radius of each shape used for bounding sphere broadphase collision checking, shape [shape_count], float.
Pairs of shape indices that may collide, shape [contact_pair_count, 2], int.
Pairs of shape, ground indices that may collide, shape [ground_contact_pair_count, 2], int.
Number of potential shape-shape contact pairs.
Number of potential shape-ground contact pairs.
Particle spring indices, shape [spring_count*2], int.
Particle spring rest length, shape [spring_count], float.
Particle spring stiffness, shape [spring_count], float.
Particle spring damping, shape [spring_count], float.
Particle spring activation, shape [spring_count], float.
Lagrange multipliers for spring constraints (internal use).
Triangle element indices, shape [tri_count*3], int.
Triangle element rest pose, shape [tri_count, 2, 2], float.
Triangle element activations, shape [tri_count], float.
Triangle element materials, shape [tri_count, 5], float.
Triangle element rest areas, shape [tri_count], float.
Bending edge indices, shape [edge_count*4], int, each row is [o0, o1, v1, v2], where v1, v2 are on the edge.
Bending edge rest angle, shape [edge_count], float.
Bending edge rest length, shape [edge_count], float.
Bending edge stiffness and damping parameters, shape [edge_count, 2], float.
Lagrange multipliers for edge constraints (internal use).
Tetrahedral element indices, shape [tet_count*4], int.
Tetrahedral rest poses, shape [tet_count, 3, 3], float.
Tetrahedral volumetric activations, shape [tet_count], float.
Tetrahedral elastic parameters in form \(k_{mu}, k_{lambda}, k_{damp}\), shape [tet_count, 3].
Start index of the first muscle point per muscle, shape [muscle_count], int.
Muscle parameters, shape [muscle_count, 5], float.
Body indices of the muscle waypoints, int.
Local body offset of the muscle waypoints, float.
Muscle activations, shape [muscle_count], float.
Poses of rigid bodies used for state initialization, shape [body_count, 7], float.
Velocities of rigid bodies used for state initialization, shape [body_count, 6], float.
Rigid body center of mass (in local frame), shape [body_count, 3], float.
Rigid body inertia tensor (relative to COM), shape [body_count, 3, 3], float.
Rigid body inverse inertia tensor (relative to COM), shape [body_count, 3, 3], float.
Rigid body mass, shape [body_count], float.
Rigid body inverse mass, shape [body_count], float.
Rigid body keys, shape [body_count], str.
Generalized joint positions used for state initialization, shape [joint_coord_count], float.
Generalized joint velocities used for state initialization, shape [joint_dof_count], float.
Generalized joint forces used for state initialization, shape [joint_dof_count], float.
Generalized joint target inputs, shape [joint_axis_count], float.
Joint type, shape [joint_count], int.
Joint parent body indices, shape [joint_count], int.
Joint child body indices, shape [joint_count], int.
Maps from joint index to the index of the joint that has the current joint parent body as child (-1 if no such joint ancestor exists), shape [joint_count], int.
Joint transform in parent frame, shape [joint_count, 7], float.
Joint mass frame in child frame, shape [joint_count, 7], float.
Joint axis in child frame, shape [joint_axis_count, 3], float.
Armature for each joint axis (used by
MuJoCoSolver
andFeatherstoneSolver
), shape [joint_dof_count], float.Joint stiffness, shape [joint_axis_count], float.
Joint damping, shape [joint_axis_count], float.
Start index of the first axis per joint, shape [joint_count], int.
Number of linear and angular axes per joint, shape [joint_count, 2], int.
Joint axis mode, shape [joint_axis_count], int.
Controls which joint is simulated (bodies become disconnected if False), shape [joint_count], int.
Joint lower position limits, shape [joint_axis_count], float.
Joint upper position limits, shape [joint_axis_count], float.
Joint position limit stiffness (used by
SemiImplicitSolver
andFeatherstoneSolver
), shape [joint_axis_count], float.Joint position limit damping (used by
SemiImplicitSolver
andFeatherstoneSolver
), shape [joint_axis_count], float.Joint lower twist limit, shape [joint_count], float.
Joint upper twist limit, shape [joint_count], float.
Start index of the first position coordinate per joint (note the last value is an additional sentinel entry to allow for querying the q dimensionality of joint i via
joint_q_start[i+1] - joint_q_start[i]
), shape [joint_count + 1], int.Start index of the first velocity coordinate per joint (note the last value is an additional sentinel entry to allow for querying the qd dimensionality of joint i via
joint_qd_start[i+1] - joint_qd_start[i]
), shape [joint_count + 1], int.Joint keys, shape [joint_count], str.
Articulation start index, shape [articulation_count], int.
Articulation keys, shape [articulation_count], str.
Contact radius used by
VBDSolver
for self-collisions.Contact margin for generation of soft contacts.
Stiffness of soft contacts (used by
SemiImplicitSolver
andFeatherstoneSolver
).Damping of soft contacts (used by
SemiImplicitSolver
andFeatherstoneSolver
).Stiffness of friction force in soft contacts (used by
SemiImplicitSolver
andFeatherstoneSolver
).Friction coefficient of soft contacts.
Restitution coefficient of soft contacts (used by
XPBDSolver
).Number of active particle-shape contacts, shape [1], int.
Index of particle per soft contact point, shape [soft_contact_max], int.
Index of shape per soft contact point, shape [soft_contact_max], int.
Positional offset of soft contact point in body frame, shape [soft_contact_max], vec3.
Linear velocity of soft contact point in body frame, shape [soft_contact_max], vec3.
Contact surface normal of soft contact point in world space, shape [soft_contact_max], vec3.
Thread indices of the soft contact points, shape [soft_contact_max], int.
Maximum number of potential rigid body contact points to generate ignoring the rigid_mesh_contact_max limit.
Maximum number of potential rigid body contact points to generate respecting the rigid_mesh_contact_max limit.
Maximum number of rigid body contact points to generate per mesh (0 = unlimited, default).
Contact margin for generation of rigid body contacts.
Torsional friction coefficient for rigid body contacts (used by
XPBDSolver
).Rolling friction coefficient for rigid body contacts (used by
XPBDSolver
).Whether to enable triangle-triangle collisions for meshes.
Number of active shape-shape contacts, shape [1], int.
Contact point relative to frame of body 0, shape [rigid_contact_max], vec3.
Contact point relative to frame of body 1, shape [rigid_contact_max], vec3.
Contact offset due to contact thickness relative to body 0, shape [rigid_contact_max], vec3.
Contact offset due to contact thickness relative to body 1, shape [rigid_contact_max], vec3.
Contact normal in world space, shape [rigid_contact_max], vec3.
Total contact thickness, shape [rigid_contact_max], float.
Index of shape 0 per contact, shape [rigid_contact_max], int.
Index of shape 1 per contact, shape [rigid_contact_max], int.
Triangle indices of the contact points, shape [rigid_contact_max], int.
Pairwise counter for contact generation, shape [rigid_contact_max], int.
Broadphase shape index of shape 0 per contact, shape [rigid_contact_max], int.
Broadphase shape index of shape 1 per contact, shape [rigid_contact_max], int.
Contact point ID, shape [rigid_contact_max], int.
Contact point limit, shape [rigid_contact_max], int.
Whether the ground plane and ground contacts are enabled.
Ground plane 3D normal and offset, shape [4], float.
Up vector of the world, shape [3], float.
Up axis, 0 for x, 1 for y, 2 for z.
Gravity vector, shape [3], float.
Total number of particles in the system.
Total number of bodies in the system.
Total number of shapes in the system.
Total number of joints in the system.
Total number of joint axes in the system.
Total number of triangles in the system.
Total number of tetrahedra in the system.
Total number of edges in the system.
Total number of springs in the system.
Total number of muscles in the system.
Total number of articulations in the system.
Total number of velocity degrees of freedom of all joints in the system.
Total number of position degrees of freedom of all joints in the system.
The coloring of all the particles, used by
VBDSolver
for Gauss-Seidel iteration.Contains the color assignment for every particle.
Device on which the Model was allocated.
- __init__(device=None)#
Initializes the Model object.
- Parameters:
device (wp.Device) – Device on which the Model’s data will be allocated.
- requires_grad#
Indicates whether the model was finalized (see
ModelBuilder.finalize()
) with gradient computation enabled.
- num_envs#
Number of articulation environments that were added to the ModelBuilder via add_builder.
- particle_q#
Particle positions, shape [particle_count, 3], float.
- particle_qd#
Particle velocities, shape [particle_count, 3], float.
- particle_mass#
Particle mass, shape [particle_count], float.
- particle_inv_mass#
Particle inverse mass, shape [particle_count], float.
- particle_radius#
Particle radius, shape [particle_count], float.
- particle_max_radius#
Maximum particle radius (useful for HashGrid construction).
- particle_ke#
Particle normal contact stiffness (used by
SemiImplicitSolver
). Default is 1.0e3.
- particle_kd#
Particle normal contact damping (used by
SemiImplicitSolver
). Default is 1.0e2.
- particle_kf#
Particle friction force stiffness (used by
SemiImplicitSolver
). Default is 1.0e2.
- particle_mu#
Particle friction coefficient. Default is 0.5.
- particle_cohesion#
Particle cohesion strength. Default is 0.0.
- particle_adhesion#
Particle adhesion strength. Default is 0.0.
- particle_grid#
HashGrid instance used for accelerated simulation of particle interactions.
- particle_flags#
Particle enabled state, shape [particle_count], bool.
- particle_max_velocity#
Maximum particle velocity (to prevent instability). Default is 1e5.
- shape_key#
List of keys for each shape.
- shape_transform#
Rigid shape transforms, shape [shape_count, 7], float.
- shape_body#
Rigid shape body index, shape [shape_count], int.
- shape_flags#
Rigid shape flags, shape [shape_count], uint32.
- body_shapes#
Mapping from body index to list of attached shape indices.
- shape_materials#
Rigid shape contact materials.
- shape_geo#
Shape geometry properties (geo type, scale, thickness, etc.).
- shape_geo_src#
List of source geometry objects (e.g., wp.Mesh, SDF) used for rendering and broadphase.
- geo_meshes#
List of finalized wp.Mesh objects.
- geo_sdfs#
List of finalized SDF objects.
- ground_plane_params#
Parameters used to define the ground plane, typically set by ModelBuilder.
- shape_collision_group#
Collision group of each shape, shape [shape_count], int.
- shape_collision_group_map#
Mapping from collision group to list of shape indices.
- shape_collision_filter_pairs#
Pairs of shape indices that should not collide.
- shape_collision_radius#
Collision radius of each shape used for bounding sphere broadphase collision checking, shape [shape_count], float.
- shape_contact_pairs#
Pairs of shape indices that may collide, shape [contact_pair_count, 2], int.
- shape_ground_contact_pairs#
Pairs of shape, ground indices that may collide, shape [ground_contact_pair_count, 2], int.
- shape_contact_pair_count#
Number of potential shape-shape contact pairs.
- shape_ground_contact_pair_count#
Number of potential shape-ground contact pairs.
- spring_indices#
Particle spring indices, shape [spring_count*2], int.
- spring_rest_length#
Particle spring rest length, shape [spring_count], float.
- spring_stiffness#
Particle spring stiffness, shape [spring_count], float.
- spring_damping#
Particle spring damping, shape [spring_count], float.
- spring_control#
Particle spring activation, shape [spring_count], float.
- spring_constraint_lambdas#
Lagrange multipliers for spring constraints (internal use).
- tri_indices#
Triangle element indices, shape [tri_count*3], int.
- tri_poses#
Triangle element rest pose, shape [tri_count, 2, 2], float.
- tri_activations#
Triangle element activations, shape [tri_count], float.
- tri_materials#
Triangle element materials, shape [tri_count, 5], float.
- tri_areas#
Triangle element rest areas, shape [tri_count], float.
- edge_indices#
Bending edge indices, shape [edge_count*4], int, each row is [o0, o1, v1, v2], where v1, v2 are on the edge.
- edge_rest_angle#
Bending edge rest angle, shape [edge_count], float.
- edge_rest_length#
Bending edge rest length, shape [edge_count], float.
- edge_bending_properties#
Bending edge stiffness and damping parameters, shape [edge_count, 2], float.
- edge_constraint_lambdas#
Lagrange multipliers for edge constraints (internal use).
- tet_indices#
Tetrahedral element indices, shape [tet_count*4], int.
- tet_poses#
Tetrahedral rest poses, shape [tet_count, 3, 3], float.
- tet_activations#
Tetrahedral volumetric activations, shape [tet_count], float.
- tet_materials#
Tetrahedral elastic parameters in form \(k_{mu}, k_{lambda}, k_{damp}\), shape [tet_count, 3].
- muscle_start#
Start index of the first muscle point per muscle, shape [muscle_count], int.
- muscle_params#
Muscle parameters, shape [muscle_count, 5], float.
- muscle_bodies#
Body indices of the muscle waypoints, int.
- muscle_points#
Local body offset of the muscle waypoints, float.
- muscle_activations#
Muscle activations, shape [muscle_count], float.
- body_q#
Poses of rigid bodies used for state initialization, shape [body_count, 7], float.
- body_qd#
Velocities of rigid bodies used for state initialization, shape [body_count, 6], float.
- body_com#
Rigid body center of mass (in local frame), shape [body_count, 3], float.
- body_inertia#
Rigid body inertia tensor (relative to COM), shape [body_count, 3, 3], float.
- body_inv_inertia#
Rigid body inverse inertia tensor (relative to COM), shape [body_count, 3, 3], float.
- body_mass#
Rigid body mass, shape [body_count], float.
- body_inv_mass#
Rigid body inverse mass, shape [body_count], float.
- body_key#
Rigid body keys, shape [body_count], str.
- joint_q#
Generalized joint positions used for state initialization, shape [joint_coord_count], float.
- joint_qd#
Generalized joint velocities used for state initialization, shape [joint_dof_count], float.
- joint_f#
Generalized joint forces used for state initialization, shape [joint_dof_count], float.
- joint_target#
Generalized joint target inputs, shape [joint_axis_count], float.
- joint_type#
Joint type, shape [joint_count], int.
- joint_parent#
Joint parent body indices, shape [joint_count], int.
- joint_child#
Joint child body indices, shape [joint_count], int.
- joint_ancestor#
Maps from joint index to the index of the joint that has the current joint parent body as child (-1 if no such joint ancestor exists), shape [joint_count], int.
- joint_X_p#
Joint transform in parent frame, shape [joint_count, 7], float.
- joint_X_c#
Joint mass frame in child frame, shape [joint_count, 7], float.
- joint_axis#
Joint axis in child frame, shape [joint_axis_count, 3], float.
- joint_armature#
Armature for each joint axis (used by
MuJoCoSolver
andFeatherstoneSolver
), shape [joint_dof_count], float.
- joint_target_ke#
Joint stiffness, shape [joint_axis_count], float.
- joint_target_kd#
Joint damping, shape [joint_axis_count], float.
- joint_axis_start#
Start index of the first axis per joint, shape [joint_count], int.
- joint_axis_dim#
Number of linear and angular axes per joint, shape [joint_count, 2], int.
- joint_axis_mode#
Joint axis mode, shape [joint_axis_count], int.
- joint_enabled#
Controls which joint is simulated (bodies become disconnected if False), shape [joint_count], int.
- joint_limit_lower#
Joint lower position limits, shape [joint_axis_count], float.
- joint_limit_upper#
Joint upper position limits, shape [joint_axis_count], float.
- joint_limit_ke#
Joint position limit stiffness (used by
SemiImplicitSolver
andFeatherstoneSolver
), shape [joint_axis_count], float.
- joint_limit_kd#
Joint position limit damping (used by
SemiImplicitSolver
andFeatherstoneSolver
), shape [joint_axis_count], float.
- joint_twist_lower#
Joint lower twist limit, shape [joint_count], float.
- joint_twist_upper#
Joint upper twist limit, shape [joint_count], float.
- joint_q_start#
Start index of the first position coordinate per joint (note the last value is an additional sentinel entry to allow for querying the q dimensionality of joint i via
joint_q_start[i+1] - joint_q_start[i]
), shape [joint_count + 1], int.
- joint_qd_start#
Start index of the first velocity coordinate per joint (note the last value is an additional sentinel entry to allow for querying the qd dimensionality of joint i via
joint_qd_start[i+1] - joint_qd_start[i]
), shape [joint_count + 1], int.
- joint_key#
Joint keys, shape [joint_count], str.
- articulation_start#
Articulation start index, shape [articulation_count], int.
- articulation_key#
Articulation keys, shape [articulation_count], str.
- soft_contact_margin#
Contact margin for generation of soft contacts. Default is 0.2.
- soft_contact_ke#
Stiffness of soft contacts (used by
SemiImplicitSolver
andFeatherstoneSolver
). Default is 1.0e3.
- soft_contact_kd#
Damping of soft contacts (used by
SemiImplicitSolver
andFeatherstoneSolver
). Default is 10.0.
- soft_contact_kf#
Stiffness of friction force in soft contacts (used by
SemiImplicitSolver
andFeatherstoneSolver
). Default is 1.0e3.
- soft_contact_mu#
Friction coefficient of soft contacts. Default is 0.5.
- soft_contact_restitution#
Restitution coefficient of soft contacts (used by
XPBDSolver
). Default is 0.0.
- soft_contact_count#
Number of active particle-shape contacts, shape [1], int. Initialized as an int scalar.
- soft_contact_particle#
Index of particle per soft contact point, shape [soft_contact_max], int.
- soft_contact_shape#
Index of shape per soft contact point, shape [soft_contact_max], int.
- soft_contact_body_pos#
Positional offset of soft contact point in body frame, shape [soft_contact_max], vec3.
- soft_contact_body_vel#
Linear velocity of soft contact point in body frame, shape [soft_contact_max], vec3.
- soft_contact_normal#
Contact surface normal of soft contact point in world space, shape [soft_contact_max], vec3.
- soft_contact_tids#
Thread indices of the soft contact points, shape [soft_contact_max], int.
- rigid_contact_max#
Maximum number of potential rigid body contact points to generate ignoring the rigid_mesh_contact_max limit.
- rigid_contact_max_limited#
Maximum number of potential rigid body contact points to generate respecting the rigid_mesh_contact_max limit.
- rigid_mesh_contact_max#
Maximum number of rigid body contact points to generate per mesh (0 = unlimited, default).
- rigid_contact_margin#
Contact margin for generation of rigid body contacts.
- rigid_contact_torsional_friction#
Torsional friction coefficient for rigid body contacts (used by
XPBDSolver
).
- rigid_contact_rolling_friction#
Rolling friction coefficient for rigid body contacts (used by
XPBDSolver
).
- enable_tri_collisions#
Whether to enable triangle-triangle collisions for meshes.
- rigid_contact_count#
Number of active shape-shape contacts, shape [1], int.
- rigid_contact_point0#
Contact point relative to frame of body 0, shape [rigid_contact_max], vec3.
- rigid_contact_point1#
Contact point relative to frame of body 1, shape [rigid_contact_max], vec3.
- rigid_contact_offset0#
Contact offset due to contact thickness relative to body 0, shape [rigid_contact_max], vec3.
- rigid_contact_offset1#
Contact offset due to contact thickness relative to body 1, shape [rigid_contact_max], vec3.
- rigid_contact_normal#
Contact normal in world space, shape [rigid_contact_max], vec3.
- rigid_contact_thickness#
Total contact thickness, shape [rigid_contact_max], float.
- rigid_contact_shape0#
Index of shape 0 per contact, shape [rigid_contact_max], int.
- rigid_contact_shape1#
Index of shape 1 per contact, shape [rigid_contact_max], int.
- rigid_contact_tids#
Triangle indices of the contact points, shape [rigid_contact_max], int.
- rigid_contact_pairwise_counter#
Pairwise counter for contact generation, shape [rigid_contact_max], int.
- rigid_contact_broad_shape0#
Broadphase shape index of shape 0 per contact, shape [rigid_contact_max], int.
- rigid_contact_broad_shape1#
Broadphase shape index of shape 1 per contact, shape [rigid_contact_max], int.
- rigid_contact_point_id#
Contact point ID, shape [rigid_contact_max], int.
- rigid_contact_point_limit#
Contact point limit, shape [rigid_contact_max], int.
- ground#
Whether the ground plane and ground contacts are enabled.
- ground_plane#
Ground plane 3D normal and offset, shape [4], float.
- up_vector#
Up vector of the world, shape [3], float.
- up_axis#
Up axis, 0 for x, 1 for y, 2 for z.
- gravity#
Gravity vector, shape [3], float.
- particle_count#
Total number of particles in the system.
- body_count#
Total number of bodies in the system.
- shape_count#
Total number of shapes in the system.
- joint_count#
Total number of joints in the system.
- joint_axis_count#
Total number of joint axes in the system.
- tri_count#
Total number of triangles in the system.
- tet_count#
Total number of tetrahedra in the system.
- edge_count#
Total number of edges in the system.
- spring_count#
Total number of springs in the system.
- muscle_count#
Total number of muscles in the system.
- articulation_count#
Total number of articulations in the system.
- joint_dof_count#
Total number of velocity degrees of freedom of all joints in the system.
- joint_coord_count#
Total number of position degrees of freedom of all joints in the system.
- particle_color_groups#
The coloring of all the particles, used by
VBDSolver
for Gauss-Seidel iteration. Each array contains indices of particles sharing the same color.
- particle_colors#
Contains the color assignment for every particle.
- device#
Device on which the Model was allocated.
- state(requires_grad=None)#
Returns a state object for the model
The returned state will be initialized with the initial configuration given in the model description.
- Parameters:
requires_grad (bool) – Manual overwrite whether the state variables should have requires_grad enabled (defaults to None to use the model’s setting
requires_grad
)- Returns:
The state object
- Return type:
- control(requires_grad=None, clone_variables=True)#
Returns a control object for the model.
The returned control object will be initialized with the control inputs given in the model description.
- Parameters:
requires_grad (bool) – Manual overwrite whether the control variables should have requires_grad enabled (defaults to None to use the model’s setting
requires_grad
)clone_variables (bool) – Whether to clone the control inputs or use the original data
- Returns:
The control object
- Return type:
- count_contact_points()#
Counts the maximum number of rigid contact points that need to be allocated. This function returns two values corresponding to the maximum number of potential contacts excluding the limiting from Model.rigid_mesh_contact_max and the maximum number of contact points that may be generated when considering the Model.rigid_mesh_contact_max limit.
- Returns:
potential_count (int): Potential number of contact points
actual_count (int): Actual number of contact points
- property soft_contact_max#
Maximum number of soft contacts that can be registered