GEOS
LinearOperator.hpp
Go to the documentation of this file.
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 TotalEnergies
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 
20 #ifndef GEOS_LINEARALGEBRA_INTERFACES_LINEAROPERATOR_HPP_
21 #define GEOS_LINEARALGEBRA_INTERFACES_LINEAROPERATOR_HPP_
22 
23 #include "common/DataTypes.hpp"
24 
25 namespace geos
26 {
27 
33 template< typename VECTOR >
35 {
36 public:
37 
39  using Vector = VECTOR;
40 
44  LinearOperator() = default;
45 
49  virtual ~LinearOperator() = default;
50 
58  virtual void apply( Vector const & src, Vector & dst ) const = 0;
59 
70  virtual void residual( Vector const & x, Vector const & b, Vector & r ) const
71  {
72  this->apply( x, r );
73  r.axpby( 1.0, b, -1.0 );
74  }
75 
79  virtual globalIndex numGlobalRows() const = 0;
80 
84  virtual globalIndex numGlobalCols() const = 0;
85 
96  {
97  return 0;
98  }
99 
103  virtual localIndex numLocalRows() const = 0;
104 
112  virtual localIndex numLocalCols() const = 0;
113 
117  virtual localIndex numLocalNonzeros() const
118  {
119  return 0;
120  }
121 
129  virtual MPI_Comm comm() const = 0;
130 };
131 
132 }
133 
134 #endif //GEOS_LINEARALGEBRA_INTERFACES_LINEAROPERATOR_HPP_
Abstract base class for linear operators.
virtual globalIndex numGlobalCols() const =0
VECTOR Vector
Alias for template parameter.
LinearOperator()=default
Constructor.
virtual globalIndex numGlobalRows() const =0
virtual void residual(Vector const &x, Vector const &b, Vector &r) const
Compute residual r = b - this(x).
virtual localIndex numLocalNonzeros() const
virtual globalIndex numGlobalNonzeros() const
virtual localIndex numLocalRows() const =0
virtual ~LinearOperator()=default
Destructor.
virtual void apply(Vector const &src, Vector &dst) const =0
Apply operator to a vector, dst = this(src).
virtual localIndex numLocalCols() const =0
virtual MPI_Comm comm() const =0
Get the MPI communicator the matrix was created with.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:87
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84