GEOS
InverseNormalOperator.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 
19 #ifndef GEOS_LINEARALGEBRA_UTILITIES_INVERSENORMALOPERATOR_HPP_
20 #define GEOS_LINEARALGEBRA_UTILITIES_INVERSENORMALOPERATOR_HPP_
21 
23 #include "common/PreconditionerBase.hpp"
24 #include "common/traits.hpp"
25 
26 namespace geos
27 {
28 
29 namespace internal
30 {
31 
32 template< typename LAI, template< typename > class SOLVER >
33 bool constexpr HasApplyTranspose = traits::VectorBasedTraits< typename LAI::ParallelVector >::template HasMemberFunction_applyTranspose< SOLVER< LAI > >;
34 
35 template< typename LAI, template< typename > class SOLVER >
36 class ExplicitTransposeInverse
37 {
38 public:
39 
40  using Matrix = typename LAI::ParallelMatrix;
41  using Vector = typename LAI::ParallelVector;
42  using Solver = SOLVER< LAI >;
43 
44  ExplicitTransposeInverse( Matrix const & matrix, Solver const & solver ):
45  m_transposeSolver( solver.parameters() )
46  {
47  matrix.transpose( m_transposeMatrix );
48  m_transposeSolver.setup( m_transposeMatrix );
49  }
50 
51  void apply( Solver const &, Vector const & src, Vector & dst ) const
52  {
53  m_transposeSolver.apply( src, dst );
54  }
55 
56 public:
57 
58  Matrix m_transposeMatrix;
59  Solver m_transposeSolver;
60 };
61 
62 template< typename LAI, template< typename > class SOLVER >
63 class ImplicitTransposeInverse
64 {
65 protected:
66 
67  using Matrix = typename LAI::ParallelMatrix;
68  using Vector = typename LAI::ParallelVector;
69  using Solver = SOLVER< LAI >;
70 
71  ImplicitTransposeInverse( Matrix const &, Solver const & )
72  {}
73 
74  void apply( Solver const & solver, Vector const & src, Vector & dst ) const
75  {
76  solver.applyTranspose( src, dst );
77  }
78 };
79 
80 template< typename LAI, template< typename > class SOLVER >
81 using TransposeInverse = std::conditional_t< HasApplyTranspose< LAI, SOLVER >,
82  ImplicitTransposeInverse< LAI, SOLVER >,
83  ExplicitTransposeInverse< LAI, SOLVER > >;
84 
85 }
86 
92 template< typename LAI, template< typename > class SOLVER >
93 class InverseNormalOperator : public LinearOperator< typename LAI::ParallelVector >
94 {
95 public:
96 
99 
101  using Matrix = typename LAI::ParallelMatrix;
102 
104  using Vector = typename Base::Vector;
105 
107  using Solver = SOLVER< LAI >;
108 
114  explicit InverseNormalOperator( Matrix const & mat,
115  Solver const & solver ):
116  m_matrix( mat ),
117  m_solver( solver ),
118  m_transposeInverse( mat, solver )
119  {}
120 
124  virtual ~InverseNormalOperator() override = default;
125 
133  void apply( Vector const & src, Vector & dst ) const override
134  {
135  m_solver.apply( src, dst );
136  m_transposeInverse.apply( m_solver, dst, dst );
137  }
138 
142  globalIndex numGlobalRows() const override
143  {
144  return m_matrix.numGlobalCols();
145  }
146 
150  globalIndex numGlobalCols() const override
151  {
152  return m_matrix.numGlobalCols();
153  }
154 
158  localIndex numLocalRows() const override
159  {
160  return m_matrix.numLocalCols();
161  }
162 
166  localIndex numLocalCols() const override
167  {
168  return m_matrix.numLocalCols();
169  }
170 
174  MPI_Comm comm() const override
175  {
176  return m_matrix.comm();
177  }
178 
179 private:
180 
182  using TransposeInverse = internal::TransposeInverse< LAI, SOLVER >;
183 
185  Matrix const & m_matrix;
186 
188  Solver const & m_solver;
189 
191  TransposeInverse m_transposeInverse;
192 };
193 
194 } // namespace geos
195 
196 #endif //GEOS_LINEARALGEBRA_UTILITIES_INVERSENORMALOPERATOR_HPP_
Wraps a matrix A and represents A^{-1} * A^{-T} as a linear operator.
MPI_Comm comm() const override
InverseNormalOperator(Matrix const &mat, Solver const &solver)
Constructor.
typename Base::Vector Vector
Alias for vector type.
SOLVER< LAI > Solver
Alias for solver type.
globalIndex numGlobalRows() const override
globalIndex numGlobalCols() const override
localIndex numLocalCols() const override
typename LAI::ParallelMatrix Matrix
Alias for matrix type.
localIndex numLocalRows() const override
virtual ~InverseNormalOperator() override=default
Destructor.
void apply(Vector const &src, Vector &dst) const override
Apply operator to a vector.
Abstract base class for linear operators.
VECTOR Vector
Alias for template parameter.
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
LAInterface::ParallelMatrix ParallelMatrix
Alias for ParallelMatrix.
LAInterface::ParallelVector ParallelVector
Alias for ParallelVector.