KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
eigen_dense_direct_solver.h
Go to the documentation of this file.
1 /* KRATOS _ _ ____ _
2 // | | (_)_ __ ___ __ _ _ __/ ___| ___ | |_ _____ _ __ ___
3 // | | | | '_ \ / _ \/ _` | '__\___ \ / _ \| \ \ / / _ \ '__/ __|
4 // | |___| | | | | __/ (_| | | ___) | (_) | |\ V / __/ | \__ |
5 // |_____|_|_| |_|\___|\__,_|_| |____/ \___/|_| \_/ \___|_| |___/ Application
6 //
7 // Author: Thomas Oberbichler
8 */
9 
10 #if !defined(KRATOS_EIGEN_DENSE_DIRECT_SOLVER_H_INCLUDED)
11 #define KRATOS_EIGEN_DENSE_DIRECT_SOLVER_H_INCLUDED
12 
13 // External includes
14 #include <Eigen/Core>
15 
16 // Project includes
17 #include "includes/define.h"
18 #include "linear_solvers_define.h"
22 
23 namespace Kratos {
24 
25 template <
26  class TSolverType,
27  class TSparseSpaceType = typename SpaceType<typename TSolverType::Scalar>::Local,
28  class TDenseSpaceType = typename SpaceType<typename TSolverType::Scalar>::Local,
29  class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType>>
31  : public DirectSolver<TSparseSpaceType, TDenseSpaceType, TReordererType>
32 {
33 private:
34  TSolverType m_solver;
35 
36  EigenDenseDirectSolver &operator=(const EigenDenseDirectSolver &Other);
37 
39 
40 public:
42 
44 
46 
48 
49  typedef typename TSparseSpaceType::DataType DataType;
50 
52 
54 
56  {
57  m_solver.Initialize(settings);
58  }
59 
61 
72  {
73  Eigen::Map<Kratos::EigenDynamicMatrix<DataType>> A(rA.data().begin(), rA.size1(), rA.size2());
74 
75  const bool success = m_solver.Compute(A);
76 
77  KRATOS_ERROR_IF(!success) << "Decomposition failed!" << std::endl;
78  }
79 
87  void PerformSolutionStep(MatrixType& rA, VectorType& rX, VectorType& rB) override
88  {
89  Eigen::Map<Kratos::EigenDynamicVector<DataType>> x(rX.data().begin(), rX.size());
90  Eigen::Map<Kratos::EigenDynamicVector<DataType>> b(rB.data().begin(), rB.size());
91 
92  const bool success = m_solver.Solve(b, x);
93 
94  KRATOS_ERROR_IF(!success) << "Solving failed!\n" << m_solver.GetSolverErrorMessages() << std::endl;
95  }
96 
104  bool Solve(MatrixType &rA, VectorType &rX, VectorType &rB) override
105  {
106  InitializeSolutionStep(rA, rX, rB);
107  PerformSolutionStep(rA, rX, rB);
108 
109  return true;
110  }
111 
118  bool Solve(MatrixType& rA, MatrixType& rX, MatrixType& rB) override
119  {
122 
123  Eigen::Map<Kratos::EigenDynamicMatrix<DataType>> X(rX.data().begin(), rX.size1(), rX.size2());
124  Eigen::Map<Kratos::EigenDynamicMatrix<DataType>> B(rB.data().begin(), rB.size1(), rB.size2());
125 
126  const bool success = m_solver.SolveMultiple(B, X);
127 
128  KRATOS_ERROR_IF(!success) << "Solving failed!\n" << m_solver.GetSolverErrorMessages() << std::endl;
129 
130  return true;
131  }
132 
136  void PrintInfo(std::ostream &rOStream) const override
137  {
138  m_solver.PrintInfo(rOStream);
139  }
140 
144  void PrintData(std::ostream &rOStream) const override
145  {
146  }
147 
149  {
151  }
152 }; // class EigenDenseDirectSolver
153 
157 template<
158  class TSolverType,
159  class TSparseSpaceType,
160  class TDenseSpaceType,
161  class TReordererType>
162 inline std::istream &operator>>(
163  std::istream &rIStream,
165 {
166  return rIStream;
167 }
168 
172 template<
173  class TSolverType,
174  class TSparseSpaceType,
175  class TDenseSpaceType,
176  class TReordererType
177  >
178 inline std::ostream &operator<<(
179  std::ostream &rOStream,
181 {
182  rThis.PrintInfo(rOStream);
183  rOStream << std::endl;
184  rThis.PrintData(rOStream);
185 
186  return rOStream;
187 }
188 
189 } // namespace Kratos
190 
191 #endif // defined(KRATOS_EIGEN_DENSE_DIRECT_SOLVER_H_INCLUDED)
Here we add the functions needed for the registration of dense linear solvers.
Definition: dense_linear_solver_factory.h:56
Definition: direct_solver.h:48
Definition: eigen_dense_direct_solver.h:32
EigenDenseDirectSolver()
Definition: eigen_dense_direct_solver.h:53
bool Solve(MatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: eigen_dense_direct_solver.h:104
KRATOS_CLASS_POINTER_DEFINITION(EigenDenseDirectSolver)
TSparseSpaceType::VectorType VectorType
Definition: eigen_dense_direct_solver.h:47
void PerformSolutionStep(MatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: eigen_dense_direct_solver.h:87
void InitializeSolutionStep(MatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: eigen_dense_direct_solver.h:71
static DenseLinearSolverFactory< TSparseSpaceType, TDenseSpaceType, EigenDenseDirectSolver > Factory()
Definition: eigen_dense_direct_solver.h:148
DirectSolver< TSparseSpaceType, TDenseSpaceType, TReordererType > BaseType
Definition: eigen_dense_direct_solver.h:43
void PrintInfo(std::ostream &rOStream) const override
Definition: eigen_dense_direct_solver.h:136
TSparseSpaceType::DataType DataType
Definition: eigen_dense_direct_solver.h:49
bool Solve(MatrixType &rA, MatrixType &rX, MatrixType &rB) override
Definition: eigen_dense_direct_solver.h:118
~EigenDenseDirectSolver() override
Definition: eigen_dense_direct_solver.h:60
EigenDenseDirectSolver(Parameters settings)
Definition: eigen_dense_direct_solver.h:55
TSparseSpaceType::MatrixType MatrixType
Definition: eigen_dense_direct_solver.h:45
TDenseSpaceType::MatrixType DenseMatrixType
Definition: eigen_dense_direct_solver.h:51
void PrintData(std::ostream &rOStream) const override
Definition: eigen_dense_direct_solver.h:144
TSparseSpaceType::VectorType VectorType
Definition: linear_solver.h:77
virtual void Initialize(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
Definition: linear_solver.h:131
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
@ Local
Definition: traits.h:20
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
dummy
Definition: script.py:194
A
Definition: sensitivityMatrix.py:70
x
Definition: sensitivityMatrix.py:49
B
Definition: sensitivityMatrix.py:76