G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsSparseSolver.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 namespace gismo {
17 
18 // forward declarations
19 template<typename T> class gsEigenCGIdentity;
20 template<typename T> class gsEigenCGDiagonal;
21 template<typename T> class gsEigenBiCGSTABIdentity;
22 template<typename T> class gsEigenBiCGSTABDiagonal;
23 template<typename T> class gsEigenBiCGSTABILUT;
24 template<typename T> class gsEigenSparseLU;
25 template<typename T> class gsEigenSparseQR;
26 template<typename T> class gsEigenSimplicialLDLT;
27 template<typename T> class gsEigenSimplicialDLT;
28 
29 template<typename T> class gsEigenSuperLU;
30 template<typename T> class gsEigenPardisoLDLT;
31 template<typename T> class gsEigenPardisoLLT;
32 template<typename T> class gsEigenPardisoLU;
33 
34 template<typename T> class gsEigenMINRES;
35 template<typename T> class gsEigenGMRES;
36 template<typename T> class gsEigenDGMRES;
37 
65 template <typename T = real_t>
67 {
68 public:
69  typedef memory::unique_ptr<gsSparseSolver> uPtr;
70 
71  typedef gsEigenCGIdentity<T> CGIdentity ;
72  typedef gsEigenCGDiagonal<T> CGDiagonal;
73  typedef gsEigenBiCGSTABDiagonal<T> BiCGSTABDiagonal;
74  typedef gsEigenBiCGSTABIdentity<T> BiCGSTABIdentity;
75  typedef gsEigenBiCGSTABILUT<T> BiCGSTABILUT;
76  typedef gsEigenSparseLU<T> LU;
77  typedef gsEigenSparseQR<T> QR;
78  typedef gsEigenSimplicialLDLT<T> SimplicialLDLT;
79  typedef gsEigenSimplicialLDLT<T> SimplicialLLT;
80 
81  // optionals
82  typedef gsEigenSuperLU<T> SuperLU;
83  typedef gsEigenPardisoLDLT<T> PardisoLDLT;
84  typedef gsEigenPardisoLLT<T> PardisoLLT;
85  typedef gsEigenPardisoLU<T> PardisoLU;
86 
87  typedef gsEigenMINRES<T> MINRES;
88  typedef gsEigenGMRES<T> GMRES;
89  typedef gsEigenDGMRES<T> DGMRES;
90 
91 public:
92  typedef gsSparseMatrix<T> MatrixT;
93  typedef gsMatrix<T> VectorT;
94 
95 public:
96  virtual ~gsSparseSolver(){}
97 
98  virtual gsSparseSolver& compute (const MatrixT &matrix) = 0;
99 
100  virtual VectorT solve (const VectorT &rhs) const = 0;
101 
102  virtual bool succeed () const = 0;
103 
104  virtual int info() const = 0;
105 
107  virtual std::ostream &print(std::ostream &os) const
108  {
109  os << "gsSparseSolver\n";
110  return os;
111  }
112 
114  virtual std::string detail() const
115  {
116  std::ostringstream os;
117  print(os);
118  return os.str();
119  }
120 
121  static uPtr get(const std::string & slv)
122  {
123  if (slv=="CGDiagonal") return uPtr(new CGDiagonal());
124  if (slv=="SimplicialLDLT") return uPtr(new SimplicialLDLT());
125  if (slv=="SimplicialLLT") return uPtr(new SimplicialLLT());
126 # ifdef GISMO_WITH_PARDISO
127  if (slv=="PardisoLU") return uPtr(new PardisoLU());
128  if (slv=="PardisoLDLT") return uPtr(new PardisoLDLT());
129  if (slv=="PardisoLLT") return uPtr(new PardisoLLT());
130 # endif
131 # ifdef GISMO_WITH_SUPERLU
132  if (slv=="SuperLU") return uPtr(new SuperLU());
133 # endif
134  if (slv=="BiCGSTABILUT") return uPtr(new BiCGSTABILUT());
135  if (slv=="BiCGSTABDiagonal") return uPtr(new BiCGSTABDiagonal());
136  if (slv=="QR") return uPtr(new QR());
137  if (slv=="LU") return uPtr(new LU());
138  if (slv=="CGIdentity") return uPtr(new CGIdentity());
139  if (slv=="BiCGSTABIdentity") return uPtr(new BiCGSTABIdentity());
140  // if (slv=="MINRES") return uPtr(new MINRES());
141  // if (slv=="GMRES") return uPtr(new GMRES());
142  // if (slv=="DGMRES") return uPtr(new DGMRES());
143  GISMO_ERROR("Solver \'"<< slv << "\' not known to G+Smo");
144  }
145 };
146 
148 template<class T>
149 std::ostream &operator<<(std::ostream &os, const gsSparseSolver<T>& b)
150 {return b.print(os); }
151 
152 #define GISMO_EIGEN_SPARSE_SOLVER(gsname, eigenName) \
153  template<typename T> \
154  class gsname : public gsSparseSolver<T>, public gsEigenAdaptor<T>::eigenName \
155  { \
156  typedef typename gsSparseSolver<T>::MatrixT MatrixT; \
157  typedef typename gsSparseSolver<T>::VectorT VectorT; \
158  protected: \
159  index_t m_rows; \
160  index_t m_cols; \
161  public: \
162  gsname() \
163  : m_rows(0),m_cols(0) \
164  {} \
165  gsname(const MatrixT &matrix) \
166  : gsEigenAdaptor<T>::eigenName(matrix), m_rows(matrix.rows()),m_cols(matrix.cols()) \
167  {} \
168  gsname& compute (const MatrixT &matrix) \
169  { \
170  m_rows=matrix.rows(); \
171  m_cols=matrix.cols(); \
172  gsEigenAdaptor<T>::eigenName::compute(matrix); \
173  return *this; \
174  } \
175  VectorT solve (const VectorT &rhs) const \
176  { \
177  return gsEigenAdaptor<T>::eigenName::solve(rhs); \
178  } \
179  bool succeed() const \
180  { return gsEigenAdaptor<T>::eigenName::info()==gsEigen::Success;} \
181  int info() const \
182  { return gsEigenAdaptor<T>::eigenName::info();} \
183  index_t rows() const {return m_rows;} \
184  index_t cols() const {return m_cols;} \
185  std::ostream &print(std::ostream &os) const \
186  { \
187  os <<STRINGIFY(eigenName); \
188  return os; \
189  } \
190  };
191 
192 GISMO_EIGEN_SPARSE_SOLVER (gsEigenCGIdentity, CGIdentity)
193 GISMO_EIGEN_SPARSE_SOLVER (gsEigenCGDiagonal, CGDiagonal)
194 GISMO_EIGEN_SPARSE_SOLVER (gsEigenBiCGSTABIdentity, BiCGSTABIdentity)
195 GISMO_EIGEN_SPARSE_SOLVER (gsEigenBiCGSTABDiagonal, BiCGSTABDiagonal)
196 GISMO_EIGEN_SPARSE_SOLVER (gsEigenBiCGSTABILUT, BiCGSTABILUT)
197 GISMO_EIGEN_SPARSE_SOLVER (gsEigenSparseLU, SparseLU)
198 GISMO_EIGEN_SPARSE_SOLVER (gsEigenSparseQR, SparseQR)
199 GISMO_EIGEN_SPARSE_SOLVER (gsEigenSimplicialLDLT, SimplicialLDLT)
200 GISMO_EIGEN_SPARSE_SOLVER (gsEigenSimplicialLLT, SimplicialLLT)
201 
202 #ifdef GISMO_WITH_SUPERLU
203  GISMO_EIGEN_SPARSE_SOLVER (gsEigenSuperLU, SuperLU)
204 #endif
205 
206 #ifdef GISMO_WITH_PARDISO
207  GISMO_EIGEN_SPARSE_SOLVER (gsEigenPardisoLDLT, PardisoLDLT)
208  GISMO_EIGEN_SPARSE_SOLVER (gsEigenPardisoLLT, PardisoLLT)
209  GISMO_EIGEN_SPARSE_SOLVER (gsEigenPardisoLU, PardisoLU)
210 #endif
211 
212 //GISMO_EIGEN_SPARSE_SOLVER (gsEigenMINRES, MINRES)
213 //GISMO_EIGEN_SPARSE_SOLVER (gsEigenGMRES, GMRES)
214 //GISMO_EIGEN_SPARSE_SOLVER (gsEigenDGMRES, DGMRES)
215 
216 
217 #undef GISMO_EIGEN_SPARSE_SOLVER
218 
219 }
virtual std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsSparseSolver.h:107
virtual std::string detail() const
Prints the object as a string with extended details.
Definition: gsSparseSolver.h:114
Abstract class for solvers. The solver interface is base on 3 methods: -compute set the system matrix...
Definition: gsSparseSolver.h:66
#define GISMO_ERROR(message)
Definition: gsDebug.h:118