GEOSX
PreconditionerBase.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 TotalEnergies
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
15 #ifndef GEOS_LINEARALGEBRA_SOLVERS_PRECONDITIONERBASE_HPP_
16 #define GEOS_LINEARALGEBRA_SOLVERS_PRECONDITIONERBASE_HPP_
17 
20 
21 namespace geos
22 {
23 
24 class DofManager;
25 
30 template< typename LAI >
31 class PreconditionerBase : public LinearOperator< typename LAI::ParallelVector >
32 {
33 public:
34 
35  PreconditionerBase() = default;
36 
37  virtual ~PreconditionerBase() = default;
38 
41 
43  using Vector = typename Base::Vector;
44 
46  using Matrix = typename LAI::ParallelMatrix;
47 
52  virtual void setup( Matrix const & mat )
53  {
54  GEOS_LAI_ASSERT( mat.ready() );
55  GEOS_LAI_ASSERT_MSG( mat.numLocalRows() == mat.numLocalCols(), "Matrix must be square" );
56  m_mat = &mat;
57  }
58 
70  virtual void clear()
71  {
72  m_mat = nullptr;
73  }
74 
79  virtual globalIndex numGlobalRows() const override
80  {
81  return m_mat->numGlobalRows();
82  }
83 
88  virtual globalIndex numGlobalCols() const override
89  {
90  return m_mat->numGlobalCols();
91  }
92 
97  virtual localIndex numLocalRows() const override
98  {
99  return m_mat->numLocalRows();
100  }
101 
106  virtual localIndex numLocalCols() const override
107  {
108  return m_mat->numLocalCols();
109  }
110 
118  virtual MPI_Comm comm() const override
119  {
120  return m_mat->comm();
121  }
122 
127  bool ready() const
128  {
129  return m_mat != nullptr;
130  }
131 
136  Matrix const & matrix() const
137  {
138  GEOS_LAI_ASSERT( ready() );
139  return *m_mat;
140  }
141 
146  virtual bool hasPreconditionerMatrix() const
147  {
148  return false;
149  }
150 
156  virtual Matrix const & preconditionerMatrix() const
157  {
158  GEOS_ERROR( "PreconditionerBase::preconditionerMatrix called. This is not supposed to happen."
159  "Check the value of hasPreconditionerMatrix() before accessing this function." );
160  // This is here just to be able to compile ...
161  return *m_mat;
162  }
163 
164 private:
165 
167  Matrix const * m_mat{};
168 };
169 
170 }
171 
172 #endif //GEOS_LINEARALGEBRA_SOLVERS_PRECONDITIONERBASE_HPP_
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:122
Abstract base class for linear operators.
VECTOR Vector
Alias for template parameter.
Common interface for preconditioning operators.
virtual void clear()
Clean up the preconditioner setup.
virtual Matrix const & preconditionerMatrix() const
Access the preconditioner in matrix form (whenever available). It must be overridden by the specific ...
virtual MPI_Comm comm() const override
Get the MPI communicator the matrix was created with.
virtual localIndex numLocalCols() const override
Get the number of local columns.
virtual bool hasPreconditionerMatrix() const
Check whether the preconditioner is available in matrix (explicit) form.
bool ready() const
Chech if preconditioner is ready to use.
virtual void setup(Matrix const &mat)
Compute the preconditioner from a matrix.
virtual globalIndex numGlobalCols() const override
Get the number of global columns.
virtual localIndex numLocalRows() const override
Get the number of local rows.
Matrix const & matrix() const
Access the matrix the preconditioner was computed from.
virtual globalIndex numGlobalRows() const override
Get the number of global rows.
typename Base::Vector Vector
Alias for vector type.
typename LAI::ParallelMatrix Matrix
Alias for matrix type.
#define GEOS_LAI_ASSERT_MSG(expr, msg)
Definition: common.hpp:40
#define GEOS_LAI_ASSERT(expr)
Definition: common.hpp:33
GEOSX_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
LAInterface::ParallelMatrix ParallelMatrix
Alias for ParallelMatrix.
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125