iMSTK
Interactive Medical Simulation Toolkit
imstkGaussSeidel.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 "imstkIterativeLinearSolver.h"
10 
11 namespace imstk
12 {
13 class LinearProjectionConstraint;
14 
21 {
22 public:
23  GaussSeidel() { m_type = Type::GaussSeidel; };
24  GaussSeidel(const SparseMatrixd& A, const Vectord& rhs);
25  ~GaussSeidel() override = default;
26 
30  GaussSeidel(const GaussSeidel&) = delete;
31  GaussSeidel(const GaussSeidel&&) = delete;
32  GaussSeidel& operator=(const GaussSeidel&) = delete;
33  GaussSeidel& operator=(const GaussSeidel&&) = delete;
34 
38  //void iterate(Vectord& x, bool updateResidual = true) override {};
39 
43  void gaussSeidelSolve(Vectord& x);
44 
48  void solve(Vectord& x) override;
49 
54  void solve(Vectord& x, const double tolerance);
55 
59  double getResidual(const Vectord& x) override;
60 
64  void setSystem(std::shared_ptr<LinearSystemType> newSystem) override;
65 
69  virtual void setMaxNumIterations(const size_t maxIter) override;
70 
74  void setTolerance(const double tolerance);
75 
79  void print() const override;
80 
84  void setLinearProjectors(std::vector<LinearProjectionConstraint>* f)
85  {
86  m_FixedLinearProjConstraints = f;
87  }
88 
92  std::vector<LinearProjectionConstraint>& getLinearProjectors()
93  {
94  return *m_FixedLinearProjConstraints;
95  }
96 
100  void setDynamicLinearProjectors(std::vector<LinearProjectionConstraint>* f)
101  {
102  m_DynamicLinearProjConstraints = f;
103  }
104 
108  std::vector<LinearProjectionConstraint>& getDynamicLinearProjectors()
109  {
110  return *m_DynamicLinearProjConstraints;
111  }
112 
113 private:
114  std::vector<LinearProjectionConstraint>* m_FixedLinearProjConstraints = nullptr;
115  std::vector<LinearProjectionConstraint>* m_DynamicLinearProjConstraints = nullptr;
116 };
117 } // namespace imstk
Base class for iterative linear solvers.
void setDynamicLinearProjectors(std::vector< LinearProjectionConstraint > *f)
Get the vector denoting the filter.
void setSystem(std::shared_ptr< LinearSystemType > newSystem) override
Sets the system. System of linear equations.
virtual void setMaxNumIterations(const size_t maxIter) override
set/get the maximum number of iterations for the iterative solver.
Gauss-Seidel sparse linear solver.
void print() const override
Print solver information.
std::vector< LinearProjectionConstraint > & getLinearProjectors()
Get the vector denoting the filter.
Compound Geometry.
void gaussSeidelSolve(Vectord &x)
Do one iteration of the method.
std::vector< LinearProjectionConstraint > & getDynamicLinearProjectors()
Get the vector denoting the filter.
void solve(Vectord &x) override
Solve the system of equations.
void setTolerance(const double tolerance)
Set solver tolerance.
void setLinearProjectors(std::vector< LinearProjectionConstraint > *f)
Get the vector denoting the filter.
Type m_type
Type of the scene object.
double getResidual(const Vectord &x) override
Return the error calculated by the solver.