gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
linearSystemEigen.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef LINEAR_SYSTEM_EIGEN_H
7 #define LINEAR_SYSTEM_EIGEN_H
8 
9 // Interface to solve a linear system with Eigen
10 
11 #include "GmshConfig.h"
12 #include "GmshMessage.h"
13 #include "linearSystem.h"
14 
15 #if defined(HAVE_EIGEN)
16 
17 #include <Eigen/Sparse>
18 
19 template <class scalar> class linearSystemEigen : public linearSystem<scalar> {
20 public:
21  linearSystemEigen()
22  {
23  Msg::Info("linearSystemEigen not implemented for this element type");
24  }
25 
26  virtual bool isAllocated() const { return false; }
27  virtual void allocate(int nbRows) {}
28  virtual void clear() {}
29  virtual void zeroMatrix() {}
30  virtual void zeroRightHandSide() {}
31  virtual void zeroSolution() {}
32  virtual int systemSolve() { return 1; }
33  virtual void insertInSparsityPattern(int row, int col) {}
34  virtual double normInfRightHandSide() const { return 0.; }
35  virtual double normInfSolution() const { return 0.; }
36 
37  virtual void addToMatrix(int row, int col, const double &val) {}
38  virtual void getFromMatrix(int row, int col, double &val) const {}
39  virtual void addToRightHandSide(int row, const scalar &val, int ith = 0) {}
40  virtual void getFromRightHandSide(int row, scalar &val) const {}
41  virtual void getFromSolution(int row, scalar &val) const {}
42  virtual void addToSolution(int row, const scalar &val) {}
43 };
44 
45 enum linearSystemEigenSolver {
46  EigenCholeskyLLT,
47  EigenCholeskyLDLT,
48  EigenSparseLU,
49  EigenSparseQR,
50  /* warning: no preconditionner for iterative solver by default, should be
51  changed */
52  EigenCG,
53  EigenCGLeastSquare,
54  EigenBiCGSTAB
55 };
56 
57 template <> class linearSystemEigen<double> : public linearSystem<double> {
58 private:
59  Eigen::VectorXd X;
60  Eigen::VectorXd B;
61  Eigen::SparseMatrix<double> A;
62  linearSystemEigenSolver solverType;
63 
64 public:
65  linearSystemEigen();
66 
67  void setSolverType(linearSystemEigenSolver solverName);
68 
69  virtual bool isAllocated() const;
70  virtual void allocate(int nbRows);
71  virtual void clear();
72  virtual void zeroMatrix();
73 
74  virtual void zeroRightHandSide();
75  virtual void zeroSolution();
76  virtual int systemSolve();
77  virtual void insertInSparsityPattern(int row, int col);
78  virtual double normInfRightHandSide() const;
79  virtual double normInfSolution() const;
80 
81  virtual void addToMatrix(int row, int col, const double &val);
82  virtual void getFromMatrix(int row, int col, double &val) const;
83  virtual void addToRightHandSide(int row, const double &val, int ith = 0);
84  virtual void getFromRightHandSide(int row, double &val) const;
85  virtual void getFromSolution(int row, double &val) const;
86  virtual void addToSolution(int row, const double &val);
87 };
88 
89 #endif
90 
91 #endif
Msg::Info
static void Info(const char *fmt,...)
Definition: GmshMessage.cpp:587
linearSystemBase::clear
virtual void clear()=0
linearSystemBase::systemSolve
virtual int systemSolve()=0
linearSystemBase::zeroRightHandSide
virtual void zeroRightHandSide()=0
GmshMessage.h
linearSystemBase::zeroSolution
virtual void zeroSolution()=0
linearSystemBase::zeroMatrix
virtual void zeroMatrix()=0
linearSystem::getFromRightHandSide
virtual void getFromRightHandSide(int _row, scalar &val) const =0
linearSystem::addToRightHandSide
virtual void addToRightHandSide(int _row, const scalar &val, int ith=0)=0
linearSystem::addToSolution
virtual void addToSolution(int _row, const scalar &val)=0
linearSystemBase::isAllocated
virtual bool isAllocated() const =0
linearSystemBase::normInfRightHandSide
virtual double normInfRightHandSide() const =0
linearSystemBase::allocate
virtual void allocate(int nbRows)=0
linearSystemBase::insertInSparsityPattern
virtual void insertInSparsityPattern(int _row, int _col)
Definition: linearSystem.h:33
linearSystemBase::normInfSolution
virtual double normInfSolution() const
Definition: linearSystem.h:35
linearSystem::getFromMatrix
virtual void getFromMatrix(int _row, int _col, scalar &val) const =0
linearSystem::getFromSolution
virtual void getFromSolution(int _row, scalar &val) const =0
linearSystem::addToMatrix
virtual void addToMatrix(int _row, int _col, const scalar &val)=0
linearSystem
Definition: linearSystem.h:38
linearSystem.h