iMSTK
Interactive Medical Simulation Toolkit
imstkPbdSolver.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 "imstkPbdConstraint.h"
10 #include "imstkSolverBase.h"
11 
12 namespace imstk
13 {
14 class PbdConstraintContainer;
15 
23 class PbdSolver : public SolverBase
24 {
25 public:
26  PbdSolver();
27  ~PbdSolver() override = default;
28 
32  void setIterations(const size_t iterations) { this->m_iterations = iterations; }
33 
38  void setConstraints(std::shared_ptr<PbdConstraintContainer> constraints) { this->m_constraints = constraints; }
39 
44  void addConstraints(std::vector<PbdConstraint*>* constraints)
45  {
46  m_constraintLists->push_back(constraints);
47  }
48 
52  void setPbdBodies(PbdState* state) { this->m_state = state; }
53 
57  void setTimeStep(const double dt) { m_dt = dt; }
58 
62  size_t getIterations() const { return this->m_iterations; }
63 
67  void setSolverType(const PbdConstraint::SolverType& type) { m_solverType = type; }
68 
72  void solve() override;
73 
77  const std::list<std::vector<PbdConstraint*>*>& getConstraintLists() const { return *m_constraintLists; }
78 
82  void clearConstraintLists() { m_constraintLists->clear(); }
83 
84 private:
85  size_t m_iterations = 20;
86  double m_dt = 0.0;
87 
88  std::shared_ptr<PbdConstraintContainer> m_constraints = nullptr;
89 
91  std::shared_ptr<std::list<std::vector<PbdConstraint*>*>> m_constraintLists = nullptr;
92 
93  PbdState* m_state = nullptr;
94  PbdConstraint::SolverType m_solverType = PbdConstraint::SolverType::xPBD;
95 };
96 } // namespace imstk
void solve() override
Solve the non linear system of equations G(x)=0 using Newton&#39;s method.
const std::list< std::vector< PbdConstraint * > * > & getConstraintLists() const
Get all the collision constraints, read only.
void clearConstraintLists()
Clear all collision constraints.
void setSolverType(const PbdConstraint::SolverType &type)
Set the PBD solver type.
Compound Geometry.
void addConstraints(std::vector< PbdConstraint *> *constraints)
Add a constraint list to this solver to be solved, for quick addition/removal particularly collision...
void setTimeStep(const double dt)
Set time step.
void setConstraints(std::shared_ptr< PbdConstraintContainer > constraints)
Sets the constraints the solver should solve for These wil be solved sequentially.
Base class for solvers.
size_t getIterations() const
Get Iterations. Returns current nonlinear iterations.
void setPbdBodies(PbdState *state)
Sets the bodies to solve with.
SolverType
Type of solvers.
Position Based Dynamics solver This solver can solve both partitioned constraints (unordered_set of v...
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
Definition: imstkPbdBody.h:229
void setIterations(const size_t iterations)
Set Iterations. The number of nonlinear iterations.