GEOSX
LinearOperator.hpp
Go to the documentation of this file.
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 TotalEnergies
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 
19 #ifndef GEOS_LINEARALGEBRA_INTERFACES_LINEAROPERATOR_HPP_
20 #define GEOS_LINEARALGEBRA_INTERFACES_LINEAROPERATOR_HPP_
21 
22 #include "common/DataTypes.hpp"
23 
24 namespace geos
25 {
26 
32 template< typename VECTOR >
34 {
35 public:
36 
38  using Vector = VECTOR;
39 
43  LinearOperator() = default;
44 
48  virtual ~LinearOperator() = default;
49 
57  virtual void apply( Vector const & src, Vector & dst ) const = 0;
58 
69  virtual void residual( Vector const & x, Vector const & b, Vector & r ) const
70  {
71  this->apply( x, r );
72  r.axpby( 1.0, b, -1.0 );
73  }
74 
79  virtual globalIndex numGlobalRows() const = 0;
80 
85  virtual globalIndex numGlobalCols() const = 0;
86 
91  virtual localIndex numLocalRows() const = 0;
92 
101  virtual localIndex numLocalCols() const = 0;
102 
110  virtual MPI_Comm comm() const = 0;
111 };
112 
113 }
114 
115 #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.
GEOSX_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125