iMSTK
Interactive Medical Simulation Toolkit
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
imstk::PbdModel Class Reference

This class implements the position based dynamics model. The PbdModel is a constraint based model that iteratively solves constraints to simulate the dynamics of a body. PbdModel supports SurfaceMesh, LineMesh, or TetrahedralMesh. PointSet is also supported for PBD fluids. More...

#include <imstkPbdModel.h>

Inheritance diagram for imstk::PbdModel:
Inheritance graph
[legend]
Collaboration diagram for imstk::PbdModel:
Collaboration graph
[legend]

Public Member Functions

void resetToInitialState () override
 Reset the current state to the initial state.
 
void configure (std::shared_ptr< PbdModelConfig > params)
 Set simulation parameters.
 
std::shared_ptr< PbdBodygetBody (size_t index) const
 
PbdStategetBodies ()
 
PbdParticleId addVirtualParticle (const Vec3d &pos, const Quatd &orientation, const double mass, const Mat3d inertia, const Vec3d &velocity=Vec3d::Zero(), const Vec3d &angularVelocity=Vec3d::Zero(), const bool persist=false)
 Add a particle to a virtual pool/buffer of particles for quick removal/insertion The persist flag indicates if it should be cleared at the end of the frame or not.
 
PbdParticleId addVirtualParticle (const Vec3d &pos, const double mass, const Vec3d &velocity=Vec3d::Zero(), const bool persist=false)
 Add a particle to a virtual pool/buffer of particles for quick removal/insertion The persist flag indicates if it should be cleared at the end of the frame or not.
 
void clearVirtualParticles ()
 Resize 0 the virtual particles.
 
std::shared_ptr< PbdModelConfiggetConfig () const
 Get the simulation parameters.
 
void addConstraints (std::shared_ptr< std::unordered_set< size_t >> vertices, const int bodyId)
 Add/generate constraints for given set of vertices on the body, useful for topology changes. More...
 
void setTimeStep (const double timeStep) override
 Set the time step size.
 
double getTimeStep () const override
 Returns the time step size.
 
std::shared_ptr< PbdConstraintContainergetConstraints ()
 Return all constraints that are solved sequentially.
 
void solveConstraints ()
 Solve the internal constraints.
 
bool initialize () override
 Initialize the PBD model.
 
void setConstraintPartitionThreshold (size_t threshold)
 Set the threshold for constraint partitioning.
 
std::shared_ptr< PbdSolvergetSolver () const
 Returns the solver used for internal constraints.
 
void setSolver (std::shared_ptr< PbdSolver > solver)
 Sets the solver used for internal constraints.
 
std::shared_ptr< TaskNodegetIntegratePositionNode () const
 
std::shared_ptr< TaskNodegetSolveNode () const
 
std::shared_ptr< TaskNodegetUpdateVelocityNode () const
 
std::shared_ptr< PbdBodyaddBody ()
 Add/remove PbdBody.
 
void removeBody (std::shared_ptr< PbdBody > body)
 
void setVelocityThreshold (double velCap)
 Set/Get filter value for velocity, default is 10 in meters/second.
 
double getVelocityThreshold ()
 
void integratePosition ()
 Time integrate the position.
 
void integratePosition (PbdBody &body)
 
void updateVelocity ()
 Time integrate the velocity.
 
void updateVelocity (PbdBody &body)
 
- Public Member Functions inherited from imstk::AbstractDynamicalModel
std::shared_ptr< TaskGraphgetTaskGraph () const
 
const DynamicalModelTypegetType () const
 Get the type of the object.
 
virtual void updatePhysicsGeometry ()
 Update the geometry of the model.
 
void setModelGeometry (std::shared_ptr< Geometry > geometry)
 Sets the model geometry.
 
bool isGeometryValid (const std::shared_ptr< Geometry > geometry)
 Checks if the given geometry is a valid geometry type for the model.
 
std::shared_ptr< GeometrygetModelGeometry () const
 Gets the model geometry.
 
void initGraphEdges ()
 Initializes the edges of the graph.
 
std::size_t getNumDegreeOfFreedom () const
 Get/Set the number of degrees of freedom.
 
void setNumDegreeOfFreedom (const size_t nDof)
 
virtual void setTimeStepSizeType (const TimeSteppingType type)
 Get/Set the type of approach used to update the time step size after every frame.
 
TimeSteppingType getTimeStepSizeType () const
 

Protected Member Functions

void resizeBodyParticles (PbdBody &body, const int particleCount)
 Resize the amount of particles for a body.
 
void initGraphEdges (std::shared_ptr< TaskNode > source, std::shared_ptr< TaskNode > sink) override
 Setup the computational graph of Pbd.
 
- Protected Member Functions inherited from imstk::AbstractDynamicalModel
 AbstractDynamicalModel (DynamicalModelType type=DynamicalModelType::None)
 

Protected Attributes

size_t m_partitionThreshold = 16
 Threshold for constraint partitioning.
 
bool m_modified = true
 
int m_iterKey = 0
 Iterative key used for body ids.
 
PbdState m_initialState
 
PbdState m_state
 
std::shared_ptr< PbdSolverm_pbdSolver = nullptr
 PBD solver.
 
std::shared_ptr< PbdModelConfigm_config = nullptr
 Model parameters, must be set before simulation.
 
double m_velocityThreshold = 100000.0
 Limit on velocity, assumes units in Meters. If any component of velocity exceeds value set here it will be clamped to the value set here, this prevents instabilities and positive feedback loops for the haptics. This clamp is applied to linear and angular velocity.
 
std::shared_ptr< PbdConstraintContainerm_constraints
 The set of constraints to update/use. More...
 
std::shared_ptr< TaskNodem_integrationPositionNode = nullptr
 
std::shared_ptr< TaskNodem_solveConstraintsNode = nullptr
 
std::shared_ptr< TaskNodem_updateVelocityNode = nullptr
 
- Protected Attributes inherited from imstk::AbstractDynamicalModel
DynamicalModelType m_type
 Mathematical model type.
 
std::size_t m_numDof
 Total number of degree of freedom.
 
std::shared_ptr< Geometrym_geometry = nullptr
 Physics geometry of the model.
 
std::set< std::string > m_validGeometryTypes
 Valid geometry types of this model.
 
TimeSteppingType m_timeStepSizeType = TimeSteppingType::Fixed
 
std::shared_ptr< TaskGraphm_taskGraph = nullptr
 

Additional Inherited Members

- Public Types inherited from imstk::AbstractDynamicalModel
enum  StateUpdateType {
  Displacement, Velocity, DeltaDisplacement, DeltaVelocity,
  None
}
 Type of the update of the state of the body.
 

Detailed Description

This class implements the position based dynamics model. The PbdModel is a constraint based model that iteratively solves constraints to simulate the dynamics of a body. PbdModel supports SurfaceMesh, LineMesh, or TetrahedralMesh. PointSet is also supported for PBD fluids.

One of the distinct properties of the PbdModel is that it is first order. This means it simulates dynamics by modifying positions directly. Velocities of the model are computed after positions are solved. Velocities from the previous iteration are applied at the start of the update.

References: Matthias Muller, Bruno Heidelberger, Marcus Hennix, and John Ratcliff. 2007. Position based dynamics. Miles Macklin, Matthias Muller, and Nuttapong Chentanez 1. XPBD: position-based simulation of compliant constrained dynamics. Matthias Mullerm, Miles Macklin, Nuttapong Chentanez, Stefan Jeschke, and Tae-Yong Kim. 2020. Detailed Rigid Body Simulation with Extended Position Based Dynamics Jan Bender, Matthias Muller, Miles Macklin. 2017. A Survey on Position Based Dynamics, 2017.

Definition at line 41 of file imstkPbdModel.h.

Member Function Documentation

◆ addConstraints()

void imstk::PbdModel::addConstraints ( std::shared_ptr< std::unordered_set< size_t >>  vertices,
const int  bodyId 
)

Add/generate constraints for given set of vertices on the body, useful for topology changes.

Does not check for duplicating pre-existed constraints.

Todo:
: Move to containers and functors

Definition at line 249 of file imstkPbdModel.cpp.

◆ getBody()

std::shared_ptr< imstk::PbdBody > imstk::PbdModel::getBody ( size_t  index) const
Returns
the body with the given index nullptr otherwise

Definition at line 124 of file imstkPbdModel.cpp.

Member Data Documentation

◆ m_constraints

std::shared_ptr<PbdConstraintContainer> imstk::PbdModel::m_constraints
protected

The set of constraints to update/use.

Computational Nodes

Definition at line 187 of file imstkPbdModel.h.


The documentation for this class was generated from the following files: