iMSTK
Interactive Medical Simulation Toolkit
imstkLinearSolver.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 "imstkLinearSystem.h"
10 #include "imstkMath.h"
11 
12 namespace imstk
13 {
19 template<typename SystemMatrixType>
21 {
22 public:
23  using MatrixType = SystemMatrixType;
25 
26  enum class Type
27  {
29  LUFactorization,
31  SuccessiveOverRelaxation,
32  Jacobi,
33  GMRES,
34  None
35  };
36 
40  LinearSolver() : m_linearSystem(nullptr) { }
41  virtual ~LinearSolver() = default;
42 
46  virtual void solve(Vectord& x) = 0;
47 
51  virtual void setSystem(std::shared_ptr<LinearSystemType> newSystem)
52  {
53  m_linearSystem.reset();
54  m_linearSystem = newSystem;
55  }
56 
57  std::shared_ptr<LinearSystemType> getSystem() const
58  {
59  return m_linearSystem;
60  }
61 
65  void setTolerance(const double tolerance)
66  {
67  m_tolerance = tolerance;
68  }
69 
73  double getTolerance() const
74  {
75  return m_tolerance;
76  }
77 
81  virtual void print() const
82  {
83  //LOG(INFO) << "Solver type (broad): Linear";
84  }
85 
89  virtual bool isIterative() const = 0;
90 
94  Type getType() { return m_type; }
95 
96 protected:
97  Type m_type = Type::None;
98  double m_tolerance = 1.0e-4;
99  std::shared_ptr<LinearSystemType> m_linearSystem;
100 };
101 } // namespace imstk
double getTolerance() const
Get solver tolerance.
void setTolerance(const double tolerance)
Set solver tolerance.
Type getType()
Return the type of the solver.
Gauss-Seidel sparse linear solver.
double m_tolerance
default tolerance
Jacobi sparse linear solver.
Definition: imstkJacobi.h:20
Compound Geometry.
Represents the linear system of the form .
Base class for linear solvers.
Type m_type
Type of the scene object.
virtual bool isIterative() const =0
Returns true if the solver is iterative.
virtual void print() const
Print solver information.
virtual void setSystem(std::shared_ptr< LinearSystemType > newSystem)
Set/get the system. Replaces/Returns the stored linear system of equations.
LinearSolver()
Default constructor/destructor.
Conjugate gradient sparse linear solver for Spd matrices.
std::shared_ptr< LinearSystemType > m_linearSystem
Linear system of equations.
virtual void solve(Vectord &x)=0
Main solve routine.