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 
76  virtual ~PetscPreconditioner() override;
77 
82  virtual void setup( Matrix const & mat ) override;
83 
91  virtual void apply( Vector const & src, Vector & dst ) const override;
92 
93  virtual void clear() override;
94 
95 private:
96 
98  using PC = _p_PC *;
99 
100 public:
101 
106  PC const & unwrapped() const;
107 
108 private:
109 
111  using MatNullSpace = _p_MatNullSpace *;
112 
118  PetscMatrix const & setupPreconditioningMatrix( PetscMatrix const & mat );
119 
121  LinearSolverParameters m_params;
122 
124  PC m_precond;
125 
127  PetscMatrix m_precondMatrix;
128 
130  MatNullSpace m_nullsp;
131 };
132 
133 }
134 
135 #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, array1d< 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.
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
Set of parameters for a linear solver or preconditioner.