MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
preconditioners.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, 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_DPG_PRECONDITIONERS
13#define MFEM_DPG_PRECONDITIONERS
14
15#include "mfem.hpp"
16
17namespace mfem
18{
19
20// A BlockDiagonalPreconditioner which assumes that all the blocks are symmetric
21// Convenient to use with Multigrid Class in which a MultTranspose is needed
23{
24private:
25 real_t c;
26public:
27 /// @brief Constructs a symmetric block-diagonal preconditioner
28 /// with the given block offsets and scaling factor.
29 /// @param offsets The block offsets of the block-diagonal preconditioner.
30 /// @param c_ The scaling factor to be applied to the result.
32 real_t c_ = 1.0)
33 : BlockDiagonalPreconditioner(offsets), c(c_) { }
34
35 void Mult(const Vector & x, Vector & y) const override
36 {
38 y*=c;
39 }
40
41 void MultTranspose(const Vector & x, Vector & y) const override
42 {
43 this->Mult(x,y);
44 }
45};
46
47#ifdef MFEM_USE_MPI
48
49/** @brief Creates a default solver for a given parallel FE space.
50 The default solvers are the following:
51 - For H1 and L2 spaces: HypreBoomerAMG
52 - For 3D RT spaces: HypreADS
53 - For 2D RT and ND spaces: HypreAMS
54 @param pfespace The parallel FE space for which the solver is to be created.
55 @param print_level The printing level for the solver.
56 @return a pointer to the created solver.
57 */
59 const ParFiniteElementSpace * pfespace, int print_level);
60
61
62/// Shared helper class (real/complex) p-refinement multigrid:
63/// - builds FE hierarchy
64/// - builds transfer operators
65///
67{
68public:
71 std::vector<Array<int>> ess_bdr_marker;
72 std::vector<Array<int>> ess_tdof_list;
73 ParMesh *pmesh = nullptr;
75 int maxlevels = 1;
76
77 // Owned levels: 0..maxlevels-2
78 std::vector<std::vector<std::unique_ptr<FiniteElementCollection>>> fec_owned;
79 std::vector<std::vector<std::unique_ptr<ParFiniteElementSpace>>> fes_owned;
80
81 // Transfer operators per level and block (owned here)
82 std::vector<std::vector<std::unique_ptr<PRefinementTransferOperator>>> T_level;
83
85 const std::vector<Array<int>> & ess_bdr_marker_);
86
87 const ParFiniteElementSpace* GetParFESpace(int lev, int b) const;
88
89 int GetFESpaceMinimumOrder(const ParFiniteElementSpace *pfespace) const;
90
91 /** @brief Computes orders/maxlevels and constructs fec/fes hierarchy
92 and T_level storage. */
93 void BuildSpaceHierarchy(int mgmaxlevels = -1);
94
95 /** @brief Builds block-diagonal prolongation for level lev (coarse=lev, fine=lev+1).
96 Its diagonal blocks are HypreParMatrix*
97 returned by the transfer operators stored in T_level[lev][b]. */
99};
100
101/// @brief Creates a p-refinement multigrid preconditioner for a
102/// given set of parallel finite element spaces and block operators.
104{
105private:
106 PRefinementHierarchy hierarchy;
107 const BlockOperator &Op;
108
109 std::unique_ptr<Solver> coarse_prec;
110
111public:
113 const std::vector<Array<int>> & ess_bdr_marker_,
114 const BlockOperator &Op_, int mgmaxlevels = -1,
115 real_t smoother_relax_factor = 2.0/3,
116 bool mumps_coarse_solver = false,
117 int coarse_cg_max_iter = 10,
118 real_t coarse_cg_rel_tol = 1e-3);
119
120 ~PRefinementMultigrid() override = default;
121};
122
123/// @brief Creates a p-refinement multigrid preconditioner for a
124/// given set of parallel finite element spaces and complex operators.
126{
127private:
128 // NOTE: nblocks for the hierarchy is derived from Op.real() at construction time,
129 // so we store hierarchy behind a pointer to avoid a "dummy nblocks" constructor.
130 std::unique_ptr<PRefinementHierarchy> hierarchy;
131
132 const ComplexOperator &Op;
133 std::unique_ptr<Solver> coarse_prec;
134
135public:
137 const std::vector<Array<int>> & ess_bdr_marker,
138 const ComplexOperator &Op_, int mgmaxlevels = -1,
139 real_t smoother_relax_factor = 2.0/3,
140 bool mumps_coarse_solver = false,
141 int coarse_cg_max_iter = 10,
142 real_t coarse_cg_rel_tol = 1e-3);
143
144 ~ComplexPRefinementMultigrid() override = default;
145};
146
147#endif
148
149// Applies a given real preconditioner to the real and imaginary parts of a complex vector
151{
152private:
153 const Operator *op = nullptr;
154 const Solver * prec = nullptr;
155 bool own_prec = false;
156
157public:
158 ComplexPreconditioner(const Solver * real_prec, bool own = false)
159 : Solver(2*real_prec->Height()), prec(real_prec), own_prec(own) { }
160
161 virtual void Mult(const Vector &x, Vector &y) const override
162 {
163 int n = x.Size()/2;
164 MFEM_VERIFY(x.Size() == 2*n, "Invalid x vector size");
165 MFEM_VERIFY(y.Size() == 2*n, "Invalid y vector size");
166
167 Vector x_r(const_cast<Vector&>(x), 0, n);
168 Vector x_i(const_cast<Vector&>(x), n, n);
169 Vector y_r(y, 0, n);
170 Vector y_i(y, n, n);
171
172 // Apply the preconditioner to the real and imaginary parts separately
173 prec->Mult(x_r, y_r);
174 prec->Mult(x_i, y_i);
175 }
176
177 virtual void MultTranspose(const Vector &x, Vector &y) const override
178 {
179 int n = x.Size()/2;
180 MFEM_VERIFY(x.Size() == 2*n, "Invalid x vector size");
181 MFEM_VERIFY(y.Size() == 2*n, "Invalid y vector size");
182
183 Vector x_r(const_cast<Vector&>(x), 0, n);
184 Vector x_i(const_cast<Vector&>(x), n, n);
185 Vector y_r(y, 0, n);
186 Vector y_i(y, n, n);
187
188 // Apply the preconditioner to the real and imaginary parts separately
189 prec->MultTranspose(x_r, y_r);
190 prec->MultTranspose(x_i, y_i);
191 }
192
193 void SetOperator(const Operator &op_) override
194 {
195 MFEM_VERIFY(dynamic_cast<const ComplexOperator*>(&op_),
196 "ComplexPreconditioner::SetOperator only accepts ComplexOperator");
197 this->op = &op_;
198 }
199
201 {
202 if (own_prec) { delete prec; }
203 }
204};
205
206} // namespace mfem
207
208#endif // MFEM_DPG_PRECONDITIONERS
A class to handle Block diagonal preconditioners in a matrix-free implementation.
void Mult(const Vector &x, Vector &y) const override
Operator application.
A class to handle Block systems in a matrix-free implementation.
Mimic the action of a complex operator using two real operators.
Creates a p-refinement multigrid preconditioner for a given set of parallel finite element spaces and...
ComplexPRefinementMultigrid(const Array< ParFiniteElementSpace * > &pfes_, const std::vector< Array< int > > &ess_bdr_marker, const ComplexOperator &Op_, int mgmaxlevels=-1, real_t smoother_relax_factor=2.0/3, bool mumps_coarse_solver=false, int coarse_cg_max_iter=10, real_t coarse_cg_rel_tol=1e-3)
~ComplexPRefinementMultigrid() override=default
virtual void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
void SetOperator(const Operator &op_) override
Set/update the solver for the given operator.
virtual void MultTranspose(const Vector &x, Vector &y) const override
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
ComplexPreconditioner(const Solver *real_prec, bool own=false)
Multigrid solver class.
Abstract operator.
Definition operator.hpp:27
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition operator.hpp:68
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Definition operator.hpp:102
std::vector< Array< int > > ess_tdof_list
std::vector< std::vector< std::unique_ptr< PRefinementTransferOperator > > > T_level
const Array< ParFiniteElementSpace * > & pfes
std::vector< std::vector< std::unique_ptr< ParFiniteElementSpace > > > fes_owned
int GetFESpaceMinimumOrder(const ParFiniteElementSpace *pfespace) const
std::vector< std::vector< std::unique_ptr< FiniteElementCollection > > > fec_owned
std::vector< Array< int > > ess_bdr_marker
void BuildSpaceHierarchy(int mgmaxlevels=-1)
Computes orders/maxlevels and constructs fec/fes hierarchy and T_level storage.
BlockOperator * BuildProlongation(int lev)
Builds block-diagonal prolongation for level lev (coarse=lev, fine=lev+1). Its diagonal blocks are Hy...
const ParFiniteElementSpace * GetParFESpace(int lev, int b) const
PRefinementHierarchy(const Array< ParFiniteElementSpace * > &pfes_, const std::vector< Array< int > > &ess_bdr_marker_)
Creates a p-refinement multigrid preconditioner for a given set of parallel finite element spaces and...
~PRefinementMultigrid() override=default
PRefinementMultigrid(const Array< ParFiniteElementSpace * > &pfes_, const std::vector< Array< int > > &ess_bdr_marker_, const BlockOperator &Op_, int mgmaxlevels=-1, real_t smoother_relax_factor=2.0/3, bool mumps_coarse_solver=false, int coarse_cg_max_iter=10, real_t coarse_cg_rel_tol=1e-3)
Abstract parallel finite element space.
Definition pfespace.hpp:31
Class for parallel meshes.
Definition pmesh.hpp:35
Base class for solvers.
Definition operator.hpp:855
void MultTranspose(const Vector &x, Vector &y) const override
Action of the transpose operator.
SymmetricBlockDiagonalPreconditioner(const Array< int > &offsets, real_t c_=1.0)
Constructs a symmetric block-diagonal preconditioner with the given block offsets and scaling factor.
void Mult(const Vector &x, Vector &y) const override
Operator application.
Vector data type.
Definition vector.hpp:82
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
real_t b
Definition lissajous.cpp:42
Solver * MakeFESpaceDefaultSolver(const ParFiniteElementSpace *pfespace, int print_level)
Creates a default solver for a given parallel FE space. The default solvers are the following:
float real_t
Definition config.hpp:46