G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsLinearAlgebra.h
Go to the documentation of this file.
1 
15 # pragma once
16 
17 #include <gsCore/gsMath.h>
18 
19 // Eigen linear algebra library (http://eigen.tuxfamily.org)
20 
21 #define Eigen gsEigen
22 // Make Eigen use GISMO_ASSERT which throws exceptions
23 //
24 // Must be defined before including Eigen headers
25 // http://eigen.tuxfamily.org/dox-3.2/TopicPreprocessorDirectives.html
26 #define eigen_assert( cond ) GISMO_ASSERT( cond, "" )
27 
28 // Plugin provides extra members
29 #define EIGEN_MATRIXBASE_PLUGIN <gsMatrix/gsMatrixAddons.h>
30 #define EIGEN_PLAINOBJECTBASE_PLUGIN <gsMatrix/gsPlainObjectBaseAddons.h>
32 
33 #include <gsEigen/Core>
34 
35 #if defined(gsMpfr_ENABLED)
36 #include <unsupported/Eigen/MPRealSupport>
37 #endif
38 
39 #if defined(gsGmp_ENABLED)
40 #include <unsupported/Eigen/MPQClassSupport>
41 #endif
42 
43 #include <gsEigen/Dense>
44 #include <gsEigen/Sparse>
45 #include <gsEigen/StdVector>
46 #include <gsEigen/Geometry>
47 
48 // Extra Eigen code
49 #include <gsMatrix/Adjugate.h>
50 #include <gsMatrix/BlockDiag.h>
52 //#include <gsMatrix/RowSelection.h>
53 
54 #ifdef GISMO_WITH_SUPERLU
55 #include <gsEigen/SuperLUSupport>
56 #endif
57 
58 #ifdef GISMO_WITH_PARDISO
59 #include <gsEigen/PardisoSupport>
60 #endif
61 
62 #ifdef GISMO_WITH_PASTIX
63 #include <gsEigen/PaStiXSupport>
64 #endif
65 
66 // sparsesuite
67 //#include <gsEigen/UmfPackSupport>
68 //#include <gsEigen/SPQRSupport>
69 //#include <gsEigen/CholmodSupport>
70 
71 // METIS
72 //#include <gsEigen/MetisSupport>
73 
74 // PaStiX
75 //#include <gsEigen/PaStiXSupport>
76 
77 #ifdef GISMO_WITH_PYBIND11
78 #include <pybind11/eigen.h>
79 #endif
80 
81 #undef Eigen
82 #undef eigen_assert
83 #undef EIGEN_MATRIXBASE_PLUGIN
84 #undef EIGEN_PLAINOBJECTBASE_PLUGIN
85 
86 
87 namespace gismo
88 {
89 
90 using gsEigen::internal::cast; // from Core/MathFunctions.h
91 
99 template<typename Derived>
100 inline bool (isnumber)(const gsEigen::MatrixBase<Derived>& x)
101 { return ((x.array() == x.array())).all(); }
102 
108 template<typename Derived>
109 inline bool isfinite(const gsEigen::MatrixBase<Derived>& x)
110 { return ( (x - x).array() == (x - x).array()).all(); }
111 
112 
113 
114 //Constantss related to gsMatrix
115 //( see also external/Eigen/src/Core/util/Constants.h )
116 using gsEigen::Dynamic ;//=-1
117 
118 using gsEigen::Lower;//=1
119 using gsEigen::Upper;//=2
120 
121 // Values for matrix align options
122 using gsEigen::RowMajor;//=0
123 using gsEigen::ColMajor;//=1
124 using gsEigen::AutoAlign;//=0
125 
126 template<class T, int _Rows, int _Cols> class gsAsMatrix ;
127 template<class T, int _Rows, int _Cols> class gsAsConstMatrix ;
128 
129 template<class T, int _Rows> class gsAsVector ;
130 template<class T, int _Rows> class gsAsConstVector ;
131 
132 // helper template for changing the dimension of a matrix
133 template <int Dim, int Change>
134 struct ChangeDim
135 {
136  enum { D = Change+Dim<0 ? 0 : Dim + Change };
137 };
138 template <int Change>
139 struct ChangeDim<Dynamic, Change>
140 {
141  enum { D = Dynamic };
142 };
143 
144 
148 template<typename T>
150 {
151 public:
152  // Note: IncompleteILU is not compatible with
153  // gsEigen::ConjugateGradient because this preconditionner does not
154  // preserve symmetry.
155 
157  typedef gsEigen::ConjugateGradient<gsEigen::SparseMatrix<T,0,index_t>,
158  gsEigen::Lower|gsEigen::Upper, gsEigen::IdentityPreconditioner> CGIdentity;
159 
161  typedef gsEigen::ConjugateGradient<gsEigen::SparseMatrix<T,0,index_t>,
162  gsEigen::Lower|gsEigen::Upper, gsEigen::DiagonalPreconditioner<T> > CGDiagonal;
163 
165  typedef gsEigen::BiCGSTAB<gsEigen::SparseMatrix<T,0,index_t>,
166  gsEigen::IncompleteLUT<T, index_t> > BiCGSTABILUT;
167 
169  typedef gsEigen::BiCGSTAB<gsEigen::SparseMatrix<T,0,index_t>,
170  gsEigen::DiagonalPreconditioner<T> > BiCGSTABDiagonal;
171 
173  typedef gsEigen::BiCGSTAB<gsEigen::SparseMatrix<T,0,index_t>,
174  gsEigen::IdentityPreconditioner > BiCGSTABIdentity;
175 
177  typedef gsEigen::SimplicialLDLT<gsEigen::SparseMatrix<T,0,index_t> > SimplicialLDLT;
178 
180  typedef gsEigen::SimplicialLLT<gsEigen::SparseMatrix<T,0,index_t> > SimplicialLLT;
181 
183  typedef gsEigen::SparseLU<gsEigen::SparseMatrix<T,0,index_t>,
184  gsEigen::COLAMDOrdering<index_t> > SparseLU;
185 
187  typedef gsEigen::SparseQR<gsEigen::SparseMatrix<T,0,index_t>,
188  gsEigen::COLAMDOrdering<index_t> > SparseQR;
189 
190  #ifdef GISMO_WITH_SUPERLU
191  typedef gsEigen::SuperLU<gsEigen::SparseMatrix<T,0,index_t> > SuperLU;
193  #endif
194 
195  #ifdef GISMO_WITH_PARDISO
196  typedef gsEigen::PardisoLDLT<gsEigen::SparseMatrix<T,0,int> > PardisoLDLT;
198  typedef gsEigen::PardisoLLT <gsEigen::SparseMatrix<T,0,int> > PardisoLLT;
199  typedef gsEigen::PardisoLU <gsEigen::SparseMatrix<T,0,int> > PardisoLU;
200  #endif
201 
202 };
203 
204 } // namespace gismo
205 
206 
208 #include <gsMatrix/gsMatrix.h>
209 #include <gsMatrix/gsVector.h>
210 #include <gsMatrix/gsAsMatrix.h>
211 #include <gsMatrix/gsSparseMatrix.h>
212 #include <gsMatrix/gsSparseVector.h>
213 #include <gsMatrix/gsSparseSolver.h>
214 #include <gsMatrix/gsPoint.h>
Provides declaration of Matrix class.
Provides declaration of the gsSparseMatrix class.
Provides declaration of Point class.
Creates a mapped object or data pointer to a matrix without copying data.
Definition: gsLinearAlgebra.h:126
bool() isnumber(const gsEigen::MatrixBase< Derived > &x)
Check if all the entires if the matrix x are not NAN (not a number)
Definition: gsLinearAlgebra.h:100
gsEigen::SparseQR< gsEigen::SparseMatrix< T, 0, index_t >, gsEigen::COLAMDOrdering< index_t > > SparseQR
Sparse QR solver.
Definition: gsLinearAlgebra.h:188
Provides declaration of Vector class.
gsEigen::SimplicialLDLT< gsEigen::SparseMatrix< T, 0, index_t > > SimplicialLDLT
Direct LDLt factorization.
Definition: gsLinearAlgebra.h:177
abstract interfaces for solvers and wrapper around Eigen solvers
gsEigen::BiCGSTAB< gsEigen::SparseMatrix< T, 0, index_t >, gsEigen::IdentityPreconditioner > BiCGSTABIdentity
BiCGSTAB without preconditioner (identity as preconditioner)
Definition: gsLinearAlgebra.h:174
Wraps pointers as matrix objects.
gsEigen::ConjugateGradient< gsEigen::SparseMatrix< T, 0, index_t >, gsEigen::Lower|gsEigen::Upper, gsEigen::DiagonalPreconditioner< T > > CGDiagonal
Congugate gradient with diagonal (Jacobi) preconditioner.
Definition: gsLinearAlgebra.h:162
Creates a mapped object or data pointer to a vector without copying data.
Definition: gsLinearAlgebra.h:129
Mathematical functions for use in G+Smo.
gsEigen::SparseLU< gsEigen::SparseMatrix< T, 0, index_t >, gsEigen::COLAMDOrdering< index_t > > SparseLU
Sparse LU solver.
Definition: gsLinearAlgebra.h:184
bool isfinite(const gsEigen::MatrixBase< Derived > &x)
Check if all the entires if the matrix x are not INF (infinite)
Definition: gsLinearAlgebra.h:109
Adjugate extension for Eigen matrix objects.
Wraps a matrix and attaches a block structure to it.
Creates a mapped object or data pointer to a const matrix without copying data.
Definition: gsLinearAlgebra.h:127
BlockTranspose extension for Eigen matrix objects.
gsEigen::BiCGSTAB< gsEigen::SparseMatrix< T, 0, index_t >, gsEigen::IncompleteLUT< T, index_t > > BiCGSTABILUT
BiCGSTAB with Incomplete LU factorization with dual-threshold strategy.
Definition: gsLinearAlgebra.h:166
gsEigen::BiCGSTAB< gsEigen::SparseMatrix< T, 0, index_t >, gsEigen::DiagonalPreconditioner< T > > BiCGSTABDiagonal
BiCGSTAB with Diagonal (Jacobi) preconditioner.
Definition: gsLinearAlgebra.h:170
Creates a mapped object or data pointer to a const vector without copying data.
Definition: gsLinearAlgebra.h:130
gsEigen::SimplicialLLT< gsEigen::SparseMatrix< T, 0, index_t > > SimplicialLLT
Direct LLt factorization.
Definition: gsLinearAlgebra.h:180
Adaptor for Eigen types.
Definition: gsLinearAlgebra.h:149
BlockDiag extension for Eigen matrix objects.
gsEigen::ConjugateGradient< gsEigen::SparseMatrix< T, 0, index_t >, gsEigen::Lower|gsEigen::Upper, gsEigen::IdentityPreconditioner > CGIdentity
Congugate gradient without preconditioner (identity as preconditioner)
Definition: gsLinearAlgebra.h:158
Provides declaration of SparseVector class (wrapping Eigen)
Extra forward declarations related to the Eigen library.