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 Total, S.A
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 GEOSX_LINEARALGEBRA_SOLVERS_PRECONDITIONERBASE_HPP_
16 #define GEOSX_LINEARALGEBRA_SOLVERS_PRECONDITIONERBASE_HPP_
17 
18 #include "linearAlgebra/common.hpp"
20 
21 namespace geosx
22 {
23 
24 class DofManager;
25 
30 template< typename LAI >
31 class PreconditionerBase : public LinearOperator< typename LAI::ParallelVector >
32 {
33 public:
34 
36  : m_mat{}
37  {}
38 
39  virtual ~PreconditionerBase() = default;
40 
43 
45  using Vector = typename Base::Vector;
46 
48  using Matrix = typename LAI::ParallelMatrix;
49 
54  virtual void compute( Matrix const & mat )
55  {
56  GEOSX_LAI_ASSERT( mat.ready() );
57  m_mat = &mat;
58  }
59 
65  virtual void compute( Matrix const & mat,
66  DofManager const & dofManager )
67  {
68  GEOSX_UNUSED_VAR( dofManager );
69  compute( mat );
70  }
71 
83  virtual void clear()
84  {
85  m_mat = nullptr;
86  }
87 
92  virtual globalIndex numGlobalRows() const override
93  {
94  return m_mat->numGlobalRows();
95  }
96 
101  virtual globalIndex numGlobalCols() const override
102  {
103  return m_mat->numGlobalCols();
104  }
105 
110  bool ready() const
111  {
112  return m_mat != nullptr;
113  }
114 
119  Matrix const & matrix() const
120  {
121  GEOSX_LAI_ASSERT( ready() );
122  return *m_mat;
123  }
124 
129  virtual bool hasPreconditionerMatrix() const
130  {
131  return false;
132  }
133 
139  virtual Matrix const & preconditionerMatrix() const
140  {
141  GEOSX_ERROR( "PreconditionerBase::preconditionerMatrix called!. Should be overridden." );
142  // This is here just to be able to compile ...
143  return *m_mat;
144  }
145 
146 private:
147 
149  Matrix const * m_mat;
150 };
151 
152 }
153 
154 #endif //GEOSX_LINEARALGEBRA_SOLVERS_PRECONDITIONERBASE_HPP_
virtual globalIndex numGlobalRows() const override
Get the number of global rows.
Common interface for preconditioning operators.
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
virtual void compute(Matrix const &mat, DofManager const &dofManager)
Compute the preconditioner from a matrix.
virtual globalIndex numGlobalCols() const override
Get the number of global columns.
virtual void compute(Matrix const &mat)
Compute the preconditioner from a matrix.
virtual bool hasPreconditionerMatrix() const
Check whether the preconditioner is available in matrix (explicit) form.
virtual Matrix const & preconditionerMatrix() const
Access the preconditioner in matrix form (whenever available). It must be overridden by the specific ...
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns, and generally simplifying the interaction between PhysicsSolvers and linear algebra operations.
Definition: DofManager.hpp:42
virtual void clear()
Clean up the preconditioner setup.
typename TrilinosInterface ::ParallelMatrix Matrix
Alias for matrix type.
bool ready() const
Chech if preconditioner is ready to use.
#define GEOSX_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:110
Matrix const & matrix() const
Access the matrix the preconditioner was computed from.
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:78
#define GEOSX_LAI_ASSERT(expr)
Definition: common.hpp:33
LAInterface::ParallelMatrix ParallelMatrix
Alias for ParallelMatrix.
Abstract base class for linear operators.
TrilinosInterface ::ParallelVector Vector
Alias for template parameter.