MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
filteredsolver.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_FILTEREDSOLVER
13#define MFEM_FILTEREDSOLVER
14
15#include "../config/config.hpp"
16#include "operator.hpp"
17#include "handle.hpp"
18#include <memory>
19
20namespace mfem
21{
22/**
23* @class FilteredSolver
24* @brief Base class for solvers with filtering (subspace correction).
25*
26* FilteredSolver is designed to augment an existing solver with an additional
27* filtering step that targets small subspaces where the solver is less
28* effective. The filtered subspace is defined by a transfer operator @p P,
29* which maps the subspace into the full space.
30*
31* ### Typical usage
32* 1. Call SetOperator() to define the operator @p A that acts on the full space.
33* 2. Call SetSolver() to provide the underlying solver @p B for the full-space operator.
34* 3. Call SetFilteredSubspaceTransferOperator() to set transfer operator @p P.
35* 4. Call SetFilteredSubspaceSolver() to set the subspace solver @p S.
36* 5. Use Mult() to apply the solver.
37*
38* ---
39*
40* The preconditioner applied by Mult() is
41* $$
42* M = B + P S P^T (I - A B) + B (I - A P S P^T) (I- A B),
43* $$
44* and the corresponding iteration matrix is
45* $$
46* I - M A = (I - B A) (I - P S P^T A) (I - B A).
47* $$
48*/
49class FilteredSolver : public Solver
50{
51public:
52 /// Construct an empty filtered solver. Must set operator and solver before use.
54
55 /// Set the system operator @a A.
56 virtual void SetOperator(const Operator &A) override;
57
58 /// Set the solver @a B that operates on the full space.
59 virtual void SetSolver(Solver &B);
60
61 /// Set the transfer operator @a P from filtered subspace to the full space.
63
64 /// Set a solver @a S that operates on the filtered subspace operator $ P^T A P $.
66
67 /// Apply the filtered solver
68 void Mult(const Vector &x, Vector &y) const override;
69
70 virtual ~FilteredSolver() = default;
71
76
77protected:
78 /// System operator (not owned).
79 const Operator * A = nullptr;
80 /// Transfer operator (not owned).
81 const Operator * P = nullptr;
82 /// Base solver (not owned).
83 Solver * B = nullptr;
84 /// Subspace solver (not owned).
85 Solver * S = nullptr;
86 /// Projected operator.
87 mutable std::unique_ptr<const Operator> PtAP = nullptr;
88 /// Initialize work vectors.
89 void InitVectors() const;
90 bool mutable solver_set = false;
91private:
92
93 /// Build and/or return cached projected operator $ P^T A P $.
94 std::unique_ptr<const Operator> GetPtAP(const Operator *Aop,
95 const Operator *Pop) const;
96 /// Finalize solver
97 void MakeSolver() const;
98
99 // Work vectors used in Mult.
100 mutable Vector z;
101 mutable Vector rf;
102 mutable Vector xf;
103 mutable Vector r;
104
105}; // mfem::FilteredSolver class
106
107
108#ifdef MFEM_USE_MPI
109/**
110* @class AMGFSolver
111* @brief AMG with Filtering: specialization of FilteredSolver.
112*
113* AMGFSolver is a convenience wrapper that fixes the base solver @a B of a
114* FilteredSolver to HypreBoomerAMG.
115* AMGF is particularly effective for constrained optimization
116* problems such as frictionless contact. For more details, see:
117* [AMG with Filtering: An Efficient Preconditioner for Interior Point Methods in Large-Scale Contact Mechanics Optimization](https://arxiv.org/abs/2505.18576)
118*
119* The internal HypreBoomerAMG instance can be accessed and configured via AMG().
120*/
122{
123private:
124 /// Owned HypreBoomerAMG instance.
125 std::unique_ptr<HypreBoomerAMG> amg;
126public:
127 /// Construct AMGF solver with default HypreBoomerAMG.
129 {
130 amg = std::make_unique<HypreBoomerAMG>();
132 }
133
134 /// Set the system operator @a A.
135 virtual void SetOperator(const Operator &A) override;
136
137 /// Access to the internal HypreBoomerAMG instance.
138 HypreBoomerAMG& GetAMG() { return *amg; }
139
140 /// Const access to the internal HypreBoomerAMG instance.
141 const HypreBoomerAMG& GetAMG() const { return *amg; }
142
143 void SetSolver(Solver &B) override
144 {
145 MFEM_ABORT("SetSolver is not supported in AMGFSolver. It is set to AMG by default");
146 }
147
148 /// Set the parallel transfer operator @a P for the filtered subspace.
150
151 /// Destructor.
152 ~AMGFSolver() override = default;
153
154};
155#endif
156
157
158} // namespace mfem
159
160#endif
AMG with Filtering: specialization of FilteredSolver.
const HypreBoomerAMG & GetAMG() const
Const access to the internal HypreBoomerAMG instance.
AMGFSolver()
Construct AMGF solver with default HypreBoomerAMG.
void SetSolver(Solver &B) override
Set the solver B that operates on the full space.
~AMGFSolver() override=default
Destructor.
void SetFilteredSubspaceTransferOperator(const HypreParMatrix &Pop)
Set the parallel transfer operator P for the filtered subspace.
HypreBoomerAMG & GetAMG()
Access to the internal HypreBoomerAMG instance.
virtual void SetOperator(const Operator &A) override
Set the system operator A.
Base class for solvers with filtering (subspace correction).
std::unique_ptr< const Operator > PtAP
Projected operator.
void Mult(const Vector &x, Vector &y) const override
Apply the filtered solver.
virtual ~FilteredSolver()=default
FilteredSolver & operator=(FilteredSolver &&)=default
FilteredSolver(const FilteredSolver &)=delete
const Operator * P
Transfer operator (not owned).
virtual void SetOperator(const Operator &A) override
Set the system operator A.
void SetFilteredSubspaceTransferOperator(const Operator &P)
Set the transfer operator P from filtered subspace to the full space.
Solver * B
Base solver (not owned).
Solver * S
Subspace solver (not owned).
void InitVectors() const
Initialize work vectors.
void SetFilteredSubspaceSolver(Solver &S)
Set a solver S that operates on the filtered subspace operator .
const Operator * A
System operator (not owned).
FilteredSolver & operator=(const FilteredSolver &)=delete
virtual void SetSolver(Solver &B)
Set the solver B that operates on the full space.
FilteredSolver()
Construct an empty filtered solver. Must set operator and solver before use.
FilteredSolver(FilteredSolver &&)=default
The BoomerAMG solver in hypre.
Definition hypre.hpp:1737
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:419
Abstract operator.
Definition operator.hpp:25
Base class for solvers.
Definition operator.hpp:792
Vector data type.
Definition vector.hpp:82