iMSTK
Interactive Medical Simulation Toolkit
imstkSOR.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 "imstkNonLinearSystem.h"
10 #include "imstkIterativeLinearSolver.h"
11 
12 #include <Eigen/IterativeLinearSolvers>
13 
14 namespace imstk
15 {
16 class LinearProjectionConstraint;
17 
23 class SOR : public IterativeLinearSolver
24 {
25 public:
26  SOR(const double relaxationFactor = 0.5) : m_relaxationFactor(relaxationFactor) { m_type = Type::SuccessiveOverRelaxation; };
27  SOR(const SparseMatrixd& A, const Vectord& rhs);
28  ~SOR() override = default;
29 
33  SOR(const SOR&) = delete;
34  SOR(const SOR&&) = delete;
35  SOR& operator=(const SOR&) = delete;
36  SOR& operator=(const SOR&&) = delete;
37 
41  //void iterate(Vectord& x, bool updateResidual = true) override {};
42 
46  void SORSolve(Vectord& x);
47 
51  void solve(Vectord& x) override;
52 
57  void solve(Vectord& x, const double tolerance);
58 
62  double getResidual(const Vectord& x) override;
63 
67  void setSystem(std::shared_ptr<LinearSystemType> newSystem) override;
68 
72  void setMaxNumIterations(const size_t maxIter) override;
73 
77  void setTolerance(const double tolerance);
78 
82  void print() const override;
83 
87  double getRelaxationFactor() const { return m_relaxationFactor; };
88 
92  void setLinearProjectors(std::vector<LinearProjectionConstraint>* f)
93  {
94  m_FixedLinearProjConstraints = f;
95  }
96 
100  std::vector<LinearProjectionConstraint>& getLinearProjectors()
101  {
102  return *m_FixedLinearProjConstraints;
103  }
104 
108  void setDynamicLinearProjectors(std::vector<LinearProjectionConstraint>* f)
109  {
110  m_DynamicLinearProjConstraints = f;
111  }
112 
116  std::vector<LinearProjectionConstraint>& getDynamicLinearProjectors()
117  {
118  return *m_DynamicLinearProjConstraints;
119  }
120 
121 private:
122  double m_relaxationFactor = 0.5;
123 
124  std::vector<LinearProjectionConstraint>* m_FixedLinearProjConstraints = nullptr;
125  std::vector<LinearProjectionConstraint>* m_DynamicLinearProjConstraints = nullptr;
126 };
127 } // namespace imstk
Base class for iterative linear solvers.
void solve(Vectord &x) override
Solve the system of equations.
Definition: imstkSOR.cpp:19
std::vector< LinearProjectionConstraint > & getLinearProjectors()
Get the vector denoting the filter.
Definition: imstkSOR.h:100
void setTolerance(const double tolerance)
Set solver tolerance.
Definition: imstkSOR.cpp:94
Compound Geometry.
std::vector< LinearProjectionConstraint > & getDynamicLinearProjectors()
Get the vector denoting the filter.
Definition: imstkSOR.h:116
double getRelaxationFactor() const
Return the relaxation factor.
Definition: imstkSOR.h:87
void setDynamicLinearProjectors(std::vector< LinearProjectionConstraint > *f)
Get the vector denoting the filter.
Definition: imstkSOR.h:108
void print() const override
Print solver information.
Definition: imstkSOR.cpp:112
double getResidual(const Vectord &x) override
Return the error calculated by the solver.
Definition: imstkSOR.cpp:88
void SORSolve(Vectord &x)
Do one iteration of the method.
Definition: imstkSOR.cpp:45
Type m_type
Type of the scene object.
void setLinearProjectors(std::vector< LinearProjectionConstraint > *f)
Get the vector denoting the filter.
Definition: imstkSOR.h:92
void setMaxNumIterations(const size_t maxIter) override
set/get the maximum number of iterations for the iterative solver.
Definition: imstkSOR.cpp:100
Successive Over Relaxation (SOR) sparse linear solver.
Definition: imstkSOR.h:23
void setSystem(std::shared_ptr< LinearSystemType > newSystem) override
Sets the system. System of linear equations.
Definition: imstkSOR.cpp:106