GEOS
PetscPreconditioner.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_PETSCPRECONDITIONER_HPP_
21 #define GEOS_LINEARALGEBRA_INTERFACES_PETSCPRECONDITIONER_HPP_
22 
23 #include "common/PreconditionerBase.hpp"
26 
34 
36 extern "C" struct _p_PC;
37 extern "C" struct _p_MatNullSpace;
38 
40 
41 namespace geos
42 {
43 
47 class PetscPreconditioner final : public PreconditionerBase< PetscInterface >
48 {
49 public:
50 
53 
55  using Vector = typename Base::Vector;
56 
58  using Matrix = typename Base::Matrix;
59 
65 
72  arrayView1d< Vector const > nearNullKernel );
73 
77  virtual ~PetscPreconditioner() override;
78 
83  virtual void setup( Matrix const & mat ) override;
84 
92  virtual void apply( Vector const & src, Vector & dst ) const override;
93 
94  virtual void clear() override;
95 
96 private:
97 
99  using PC = _p_PC *;
100 
101 public:
102 
107  PC const & unwrapped() const;
108 
109 private:
110 
112  using MatNullSpace = _p_MatNullSpace *;
113 
119  PetscMatrix const & setupPreconditioningMatrix( PetscMatrix const & mat );
120 
122  LinearSolverParameters m_params;
123 
125  PC m_precond;
126 
128  PetscMatrix m_precondMatrix;
129 
131  MatNullSpace m_nullsp;
132 };
133 
134 }
135 
136 #endif //GEOS_LINEARALGEBRA_INTERFACES_PETSCPRECONDITIONER_HPP_
This class creates and provides basic support for the Mat matrix object type used in PETSc.
Definition: PetscMatrix.hpp:51
Wrapper around PETSc-based preconditioners.
virtual void clear() override
Clean up the preconditioner setup.
typename Base::Matrix Matrix
Alias for matrix type.
typename Base::Vector Vector
Alias for vector type.
PC const & unwrapped() const
Access the underlying implementation.
PetscPreconditioner(LinearSolverParameters params)
Constructor.
virtual void setup(Matrix const &mat) override
Compute the preconditioner from a matrix.
PetscPreconditioner(LinearSolverParameters params, arrayView1d< Vector const > nearNullKernel)
Constructor.
virtual ~PetscPreconditioner() override
Destructor.
virtual void apply(Vector const &src, Vector &dst) const override
Apply operator to a vector.
Common interface for preconditioning operators.
typename Base::Vector Vector
Alias for vector type.
typename LAI::ParallelMatrix Matrix
Alias for matrix type.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
Set of parameters for a linear solver or preconditioner.