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.
linear_solver.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 // Riccardo Rossi
12 //
13 //
14 
15 
16 #if !defined(KRATOS_LINEAR_SOLVER_H_INCLUDED )
17 #define KRATOS_LINEAR_SOLVER_H_INCLUDED
18 
19 
20 // System includes
21 
22 
23 // External includes
24 
25 // Project includes
26 #include "includes/define.h"
27 #include "reorderer.h"
28 #include "includes/model_part.h"
29 
30 namespace Kratos
31 {
32 
35 
39 
43 
47 
51 
53 
63 template<class TSparseSpaceType, class TDenseSpaceType, class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
65 {
66 public:
69 
72 
74 
75  typedef typename TSparseSpaceType::MatrixPointerType SparseMatrixPointerType;
76 
78 
79  typedef typename TSparseSpaceType::VectorPointerType VectorPointerType;
80 
82 
84 
85  typedef std::size_t SizeType;
86 
89 
93 
95  LinearSolver() : mpReorderer(new TReordererType()) {}
96 
98  LinearSolver(TReordererType NewReorderer) : mpReorderer(NewReorderer) {}
99 
101  LinearSolver(const LinearSolver& Other) : mpReorderer(Other.mpReorderer) {}
102 
104  virtual ~LinearSolver() {}
105 
106 
110 
113  {
114  mpReorderer = Other.mpReorderer;
115 
116  return *this;
117  }
118 
119 
123 
131  virtual void Initialize(SparseMatrixType& rA, VectorType& rX, VectorType& rB)
132  {
133  mpReorderer->Initialize(rA, rX, rB);
134  }
135 
145  {
146  }
147 
155  {
156  KRATOS_ERROR << "Calling linear solver base class" << std::endl;
157  }
158 
166  {
167  }
168 
173  virtual void Clear()
174  {
175  }
176 
177 
186  virtual bool Solve(SparseMatrixType& rA, VectorType& rX, VectorType& rB)
187  {
188  KRATOS_ERROR << "Calling linear solver base class" << std::endl;
189  return false;
190  }
191 
201  {
202  KRATOS_ERROR << "Calling linear solver base class" << std::endl;
203  return false;
204  }
205 
212  virtual void Solve(SparseMatrixType& K,
213  SparseMatrixType& M,
214  DenseVectorType& Eigenvalues,
215  DenseMatrixType& Eigenvectors)
216  {
217  KRATOS_ERROR << "Calling linear solver base class" << std::endl;
218  }
219 
227  {
228  return false;
229  }
230 
237  virtual void ProvideAdditionalData(
238  SparseMatrixType& rA,
239  VectorType& rX,
240  VectorType& rB,
241  typename ModelPart::DofsArrayType& rDoFSet,
242  ModelPart& rModelPart
243  )
244  {}
245 
249 
250  virtual typename TReordererType::Pointer GetReorderer()
251  {
252  return mpReorderer;
253  }
254 
255  virtual void SetReorderer(typename TReordererType::Pointer pNewReorderer)
256  {
257  mpReorderer = pNewReorderer;
258  }
259 
264  virtual void SetTolerance(double NewTolerance)
265  {
266  KRATOS_WARNING("LinearSolver") << "Accessed base function \"SetTolerance\". This does nothing !" << std::endl;
267  }
268 
273  virtual double GetTolerance()
274  {
275  KRATOS_WARNING("LinearSolver") << "Accessed base function \"GetTolerance\". No tolerance defined, returning 0 !" << std::endl ;
276  return 0;
277  }
278 
280  {
281  KRATOS_WARNING("LinearSolver") << "Accessed base function \"GetIterationsNumber\", returning 0 !" << std::endl ;
282 
283  return 0;
284  }
285 
289 
297  virtual bool IsConsistent(
298  SparseMatrixType& rA,
299  VectorType& rX,
300  VectorType& rB
301  )
302  {
303  const SizeType size = TSparseSpaceType::Size1(rA);
304  const SizeType size_a = TSparseSpaceType::Size2(rA);
305  const SizeType size_x = TSparseSpaceType::Size(rX);
306  const SizeType size_b = TSparseSpaceType::Size(rB);
307 
308  return ((size == size_a) &&
309  (size == size_x) &&
310  (size == size_b));
311  }
312 
320  virtual bool IsConsistent(
321  SparseMatrixType& rA,
322  DenseMatrixType& rX,
323  DenseMatrixType& rB
324  )
325  {
326  const SizeType size = TSparseSpaceType::Size1(rA);
327  const SizeType size_a = TSparseSpaceType::Size2(rA);
328  const SizeType size_1_x = TDenseSpaceType::Size1(rX);
329  const SizeType size_1_b = TDenseSpaceType::Size1(rB);
330  const SizeType size_2_x = TDenseSpaceType::Size2(rX);
331  const SizeType size_2_b = TDenseSpaceType::Size2(rB);
332 
333  return ((size == size_a) &&
334  (size == size_1_x) &&
335  (size == size_1_b) &&
336  (size_2_x == size_2_b));
337  }
338 
346  virtual bool IsNotConsistent(
347  SparseMatrixType& rA,
348  VectorType& rX,
349  VectorType& rB
350  )
351  {
352  return (!IsConsistent(rA, rX, rB));
353  }
354 
362  virtual bool IsNotConsistent(
363  SparseMatrixType& rA,
364  DenseMatrixType& rX,
365  DenseMatrixType& rB
366  )
367  {
368  return (!IsConsistent(rA, rX, rB));
369  }
370 
374 
376  virtual std::string Info() const
377  {
378  return "Linear solver";
379  }
380 
382  virtual void PrintInfo(std::ostream& rOStream) const
383  {
384  rOStream << "Linear solver";
385  }
386 
388  virtual void PrintData(std::ostream& rOStream) const
389  {
390  }
391 
395 
396 
398 
399 protected:
402 
403 
407 
408 
412 
413 
417 
418 
422 
423 
427 
428 
432 
433 
435 
436 private:
439 
440 
444 
446  typename TReordererType::Pointer mpReorderer;
447 
451 
452 
456 
457 
461 
462 
466 
467 
471 
472 
474 
475 };
476 
478 
481 
482 
486 
487 
489 template<class TSparseSpaceType, class TDenseSpaceType, class TReordererType>
490 inline std::istream& operator >> (std::istream& IStream,
492 {
493  return IStream;
494 }
495 
497 template<class TSparseSpaceType, class TDenseSpaceType, class TReordererType>
498 inline std::ostream& operator << (std::ostream& rOStream,
500 {
501  rThis.PrintInfo(rOStream);
502  rOStream << std::endl;
503  rThis.PrintData(rOStream);
504 
505  return rOStream;
506 }
508 
509 
510 } // namespace Kratos.
511 
512 #endif // KRATOS_LINEAR_SOLVER_H_INCLUDED defined
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
virtual void FinalizeSolutionStep(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
Definition: linear_solver.h:165
TSparseSpaceType::MatrixType SparseMatrixType
Definition: linear_solver.h:73
std::size_t SizeType
Definition: linear_solver.h:85
TSparseSpaceType::IndexType IndexType
The index type definition to be consistent.
Definition: linear_solver.h:88
virtual void InitializeSolutionStep(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
Definition: linear_solver.h:144
TSparseSpaceType::VectorPointerType VectorPointerType
Definition: linear_solver.h:79
TDenseSpaceType::VectorType DenseVectorType
Definition: linear_solver.h:83
virtual double GetTolerance()
This method allows to get the tolerance in the linear solver.
Definition: linear_solver.h:273
TDenseSpaceType::MatrixType DenseMatrixType
Definition: linear_solver.h:81
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: linear_solver.h:388
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: linear_solver.h:382
virtual bool Solve(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB)
Definition: linear_solver.h:200
virtual void Solve(SparseMatrixType &K, SparseMatrixType &M, DenseVectorType &Eigenvalues, DenseMatrixType &Eigenvectors)
Definition: linear_solver.h:212
virtual void SetReorderer(typename TReordererType::Pointer pNewReorderer)
Definition: linear_solver.h:255
virtual TReordererType::Pointer GetReorderer()
Definition: linear_solver.h:250
TSparseSpaceType::MatrixPointerType SparseMatrixPointerType
Definition: linear_solver.h:75
LinearSolver(const LinearSolver &Other)
Copy constructor.
Definition: linear_solver.h:101
LinearSolver(TReordererType NewReorderer)
Constructor with specific reorderer.
Definition: linear_solver.h:98
LinearSolver()
Default constructor.
Definition: linear_solver.h:95
LinearSolver & operator=(const LinearSolver &Other)
Assignment operator.
Definition: linear_solver.h:112
virtual bool AdditionalPhysicalDataIsNeeded()
Definition: linear_solver.h:226
virtual std::string Info() const
Turn back information as a string.
Definition: linear_solver.h:376
TSparseSpaceType::VectorType VectorType
Definition: linear_solver.h:77
virtual bool IsNotConsistent(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
This method checks if the dimensions of the system of equations are not consistent.
Definition: linear_solver.h:346
virtual void PerformSolutionStep(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
Definition: linear_solver.h:154
virtual bool Solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
Definition: linear_solver.h:186
KRATOS_CLASS_POINTER_DEFINITION(LinearSolver)
Pointer definition of LinearSolver.
virtual void ProvideAdditionalData(SparseMatrixType &rA, VectorType &rX, VectorType &rB, typename ModelPart::DofsArrayType &rDoFSet, ModelPart &rModelPart)
Definition: linear_solver.h:237
virtual bool IsConsistent(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB)
This method checks if the dimensions of the system of equations are consistent (dense matrix for RHS ...
Definition: linear_solver.h:320
virtual void Clear()
Definition: linear_solver.h:173
virtual void Initialize(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
Definition: linear_solver.h:131
virtual bool IsNotConsistent(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB)
This method checks if the dimensions of the system of equations are not consistent.
Definition: linear_solver.h:362
virtual ~LinearSolver()
Destructor.
Definition: linear_solver.h:104
virtual bool IsConsistent(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
This method checks if the dimensions of the system of equations are consistent.
Definition: linear_solver.h:297
virtual IndexType GetIterationsNumber()
Definition: linear_solver.h:279
virtual void SetTolerance(double NewTolerance)
This method allows to set the tolerance in the linear solver.
Definition: linear_solver.h:264
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_WARNING(label)
Definition: logger.h:265
std::size_t IndexType
Definition: binary_expression.cpp:25
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
TSpaceType::IndexType Size1(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:117
TSpaceType::IndexType Size2(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:123
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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
K
Definition: sensitivityMatrix.py:73