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 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 
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 
80  virtual globalIndex numGlobalRows() const = 0;
81 
86  virtual globalIndex numGlobalCols() const = 0;
87 
92  virtual localIndex numLocalRows() const = 0;
93 
102  virtual localIndex numLocalCols() const = 0;
103 
111  virtual MPI_Comm comm() const = 0;
112 };
113 
114 }
115 
116 #endif //GEOS_LINEARALGEBRA_INTERFACES_LINEAROPERATOR_HPP_
Abstract base class for linear operators.
virtual globalIndex numGlobalCols() const =0
Get the number of global columns.
VECTOR Vector
Alias for template parameter.
LinearOperator()=default
Constructor.
virtual globalIndex numGlobalRows() const =0
Get the number of global rows.
virtual void residual(Vector const &x, Vector const &b, Vector &r) const
Compute residual r = b - this(x).
virtual localIndex numLocalRows() const =0
Get the number of local rows.
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
Get the number of local columns.
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:88
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85