GEOS
PreconditionerJacobi.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 #ifndef GEOS_LINEARALGEBRA_SOLVERS_PRECONDITIONERJACOBI_HPP_
17 #define GEOS_LINEARALGEBRA_SOLVERS_PRECONDITIONERJACOBI_HPP_
18 
20 #include "linearAlgebra/common/PreconditionerBase.hpp"
21 
22 namespace geos
23 {
24 
29 template< typename LAI >
31 {
32 public:
33 
36 
38  using Vector = typename Base::Vector;
39 
41  using Matrix = typename Base::Matrix;
42 
47  virtual void setup( Matrix const & mat ) override
48  {
49  GEOS_LAI_ASSERT( mat.ready() );
50  m_diagInv.createWithLocalSize( mat.numLocalRows(), mat.comm() );
51  mat.extractDiagonal( m_diagInv );
52  m_diagInv.reciprocal();
53  }
54 
66  virtual void clear() override
67  {
68  m_diagInv.reset();
69  }
70 
75  virtual globalIndex numGlobalRows() const override final
76  {
77  GEOS_LAI_ASSERT( m_diagInv.ready() );
78  return m_diagInv.globalSize();
79  }
80 
85  virtual globalIndex numGlobalCols() const override final
86  {
87  GEOS_LAI_ASSERT( m_diagInv.ready() );
88  return m_diagInv.globalSize();
89  }
90 
97  virtual void apply( Vector const & src,
98  Vector & dst ) const override
99  {
100  GEOS_LAI_ASSERT( m_diagInv.ready() );
101  GEOS_LAI_ASSERT_EQ( this->numGlobalRows(), dst.globalSize() );
102  GEOS_LAI_ASSERT_EQ( this->numGlobalCols(), src.globalSize() );
103 
104  m_diagInv.pointwiseProduct( src, dst );
105  }
106 
107 private:
108 
110  Vector m_diagInv;
111 };
112 
113 }
114 
115 #endif //GEOS_LINEARALGEBRA_SOLVERS_PRECONDITIONERJACOBI_HPP_
Abstract base class for linear operators.
Common interface for preconditioning operators.
typename Base::Vector Vector
Alias for vector type.
typename LAI::ParallelMatrix Matrix
Alias for matrix type.
Common interface for identity preconditioning operator.
virtual globalIndex numGlobalRows() const override final
Get the number of global rows.
typename Base::Vector Vector
Alias for vector type.
virtual void setup(Matrix const &mat) override
Compute the preconditioner from a matrix.
virtual void clear() override
Clean up the preconditioner setup.
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.
#define GEOS_LAI_ASSERT_EQ(lhs, rhs)
Definition: common.hpp:49
#define GEOS_LAI_ASSERT(expr)
Definition: common.hpp:35
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:88