GEOSX
PreconditionerJacobi.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2019 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2019 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2019 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All right reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
15 #ifndef GEOSX_LINEARALGEBRA_SOLVERS_PRECONDITIONERJACOBI_HPP_
16 #define GEOSX_LINEARALGEBRA_SOLVERS_PRECONDITIONERJACOBI_HPP_
17 
19 #include "linearAlgebra/solvers/PreconditionerBase.hpp"
20 
21 namespace geosx
22 {
23 
28 template< typename LAI >
30 {
31 public:
32 
35 
37  using Vector = typename Base::Vector;
38 
40  using Matrix = typename Base::Matrix;
41 
46  virtual void compute( Matrix const & mat ) override
47  {
48  GEOSX_LAI_ASSERT( mat.ready() );
49  m_diagInv.createWithLocalSize( mat.numLocalRows(), mat.getComm() );
50  mat.extractDiagonal( m_diagInv );
51  m_diagInv.reciprocal();
52  }
53 
59  virtual void compute( Matrix const & mat,
60  DofManager const & dofManager ) override
61  {
62  GEOSX_UNUSED_VAR( dofManager );
63  compute( mat );
64  }
65 
77  virtual void clear() override
78  {
79  m_diagInv.reset();
80  }
81 
86  virtual globalIndex numGlobalRows() const override final
87  {
88  GEOSX_LAI_ASSERT( m_diagInv.ready() );
89  return m_diagInv.globalSize();
90  }
91 
96  virtual globalIndex numGlobalCols() const override final
97  {
98  GEOSX_LAI_ASSERT( m_diagInv.ready() );
99  return m_diagInv.globalSize();
100  }
101 
108  virtual void apply( Vector const & src,
109  Vector & dst ) const override
110  {
111  GEOSX_LAI_ASSERT( m_diagInv.ready() );
112  GEOSX_LAI_ASSERT_EQ( this->numGlobalRows(), dst.globalSize() );
113  GEOSX_LAI_ASSERT_EQ( this->numGlobalCols(), src.globalSize() );
114 
115  m_diagInv.pointwiseProduct( src, dst );
116  }
117 
118 private:
119 
121  Vector m_diagInv;
122 };
123 
124 }
125 
126 #endif //GEOSX_LINEARALGEBRA_SOLVERS_PRECONDITIONERJACOBI_HPP_
virtual void compute(Matrix const &mat) override
Compute the preconditioner from a matrix.
Common interface for preconditioning operators.
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
Common interface for identity preconditioning operator.
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() override
Clean up the preconditioner setup.
virtual void compute(Matrix const &mat, DofManager const &dofManager) override
Compute the preconditioner from a matrix.
virtual globalIndex numGlobalCols() const override final
Get the number of global columns.
virtual void apply(Vector const &src, Vector &dst) const override
Apply operator to a vector.
typename LAI::ParallelMatrix Matrix
Alias for matrix type.
#define GEOSX_LAI_ASSERT_EQ(lhs, rhs)
Definition: common.hpp:47
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:78
virtual globalIndex numGlobalRows() const override final
Get the number of global rows.
#define GEOSX_LAI_ASSERT(expr)
Definition: common.hpp:33
Abstract base class for linear operators.
typename Base::Vector Vector
Alias for vector type.