iMSTK
Interactive Medical Simulation Toolkit
imstkPbdModelConfig.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkPbdCollisionConstraint.h"
10 #include "imstkPbdFemConstraint.h"
11 #include "imstkPbdConstraintFunctor.h"
12 #include "imstkDataTracker.h"
13 
14 #include <unordered_map>
15 #include <unordered_set>
16 
17 namespace imstk
18 {
25 {
26 public:
33  enum class ConstraintGenType
34  {
35  Custom,
36  Distance,
37  FemTet,
38  Volume,
39  Area,
40  Bend,
41  Dihedral,
42  ConstantDensity
43  };
44 
45 public:
54  void enableConstraint(ConstraintGenType type, const double stiffness, const int bodyId = 2);
55 
61  void enableDistanceConstraint(const double stiffness, const double stretch, const int bodyId);
62 
73  void enableBendConstraint(const double stiffness, const int stride, const bool restLength0 = true, const int bodyId = 2);
74 
81  void enableConstantDensityConstraint(const double stiffness,
82  const double particleRadius, const double restDensity = 6378.0, const int bodyId = 2);
83 
90  void enableFemConstraint(PbdFemConstraint::MaterialType material, const int bodyId = 2);
91 
98  void enableFemConstraint(PbdFemConstraint::MaterialType material, double youngsModulus, double poissonRatio, const int bodyId);
99 
105 
110  void addPbdConstraintFunctor(std::shared_ptr<PbdConstraintFunctor> functor)
111  {
112  m_functors[ConstraintGenType::Custom].push_back(functor);
113  }
114 
115  void addPbdConstraintFunctor(std::function<void(PbdConstraintContainer&)> functor)
116  {
117  m_functors[ConstraintGenType::Custom].push_back(
118  std::make_shared<PbdConstraintFunctorLambda>(functor));
119  }
120 
121  std::unordered_map<ConstraintGenType, std::vector<std::shared_ptr<PbdConstraintFunctor>>>& getFunctors() { return m_functors; }
122 
130  void setBodyDamping(const int bodyId,
131  const double linearDampCoeff, const double angularDampCoeff = 0.01);
132 
139  double getLinearDamping(const int bodyId);
140  double getAngularDamping(const int bodyId);
142 
143 public:
144  double m_linearDampingCoeff = 0.01;
145  double m_angularDampingCoeff = 0.01;
146 
147  unsigned int m_iterations = 10;
148  double m_dt = 0.01;
149  bool m_doPartitioning = true;
150 
151  Vec3d m_gravity = Vec3d(0.0, -9.81, 0.0);
152 
153  std::shared_ptr<PbdFemConstraintConfig> m_femParams =
154  std::make_shared<PbdFemConstraintConfig>(PbdFemConstraintConfig
155  {
156  0.0, // Lame constant, if constraint type is FEM
157  0.0, // Lame constant, if constraint type is FEM
158  1000.0, // FEM parameter, if constraint type is FEM
159  0.2 // FEM parameter, if constraint type is FEM
160  });
161 
162  PbdConstraint::SolverType m_solverType = PbdConstraint::SolverType::xPBD;
163 
164  std::unordered_map<int, double> m_bodyLinearDampingCoeff;
165  std::unordered_map<int, double> m_bodyAngularDampingCoeff;
166 
167  std::shared_ptr<DataTracker> m_dataTracker;
168 
169 protected:
170  friend class PbdModel;
171 
172  std::unordered_map<ConstraintGenType, std::vector<std::shared_ptr<PbdConstraintFunctor>>> m_functors;
173 };
174 } // namespace imstk
This class implements the position based dynamics model. The PbdModel is a constraint based model tha...
Definition: imstkPbdModel.h:41
double m_linearDampingCoeff
Damping coefficient applied to linear velocity [0, 1].
void enableFemConstraint(PbdFemConstraint::MaterialType material, const int bodyId=2)
Enable a Fem constraint with the material provided.
Container for pbd constraints.
void computeElasticConstants()
If lame parameters (mu+lambda) are given in femParams, then youngs modulus and poissons ratio are com...
double m_angularDampingCoeff
Damping coefficient applied to angular velcoity [0, 1].
void enableBendConstraint(const double stiffness, const int stride, const bool restLength0=true, const int bodyId=2)
Enables a bend constraint with given stiffness, stride, and flag for 0 rest length You may enable mul...
double getLinearDamping(const int bodyId)
Returns global and per body damping multiplied together for a body 1.0 is fully damped/all velocity r...
Compound Geometry.
void addPbdConstraintFunctor(std::shared_ptr< PbdConstraintFunctor > functor)
Adds a functor to generate constraints.
void enableConstraint(ConstraintGenType type, const double stiffness, const int bodyId=2)
Enables a constraint of type defined by ConstraintGenType with given stiffness. If constraint of that...
unsigned int m_iterations
Internal constraints pbd solver iterations.
void setBodyDamping(const int bodyId, const double linearDampCoeff, const double angularDampCoeff=0.01)
Set damping for a specific body 1.0 is fully damped/all velocity removed, 0.0 is no damping...
void enableConstantDensityConstraint(const double stiffness, const double particleRadius, const double restDensity=6378.0, const int bodyId=2)
Enables constant density constraint given the stiffness and particleSize.
ConstraintGenType
Gives the set of standard pbd constraint generation schemes/functors provided by iMSTK. Note, these do not correspond to constraint types as there may be multiple schemes for one constraint or even multiple constraints per scheme.
std::unordered_map< int, double > m_bodyAngularDampingCoeff
Per body angular damping, Body id -> angular damping for given body [0, 1].
bool m_doPartitioning
Does graph coloring to solve in parallel.
std::unordered_map< int, double > m_bodyLinearDampingCoeff
Per body linear damping, Body id -> linear damping for given body [0, 1].
double m_dt
Time step size.
SolverType
Type of solvers.
void enableDistanceConstraint(const double stiffness, const double stretch, const int bodyId)
Enables a Distance constraint on the body Will remove an existing distance constraint on the same bod...
Gives parameters for PBD simulation.
Either mu/lambda used, may be computed from youngs modulus and poissons ratio.
Vec3d m_gravity
Gravity acceleration.