MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
multigrid.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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_MULTIGRID
13#define MFEM_MULTIGRID
14
15#include "fespacehierarchy.hpp"
16#include "bilinearform.hpp"
17
19#include "../linalg/handle.hpp"
20
21namespace mfem
22{
23
24/// Abstract base class for Multigrid solvers
25class MultigridBase : public Solver
26{
27public:
28 enum class CycleType
29 {
30 VCYCLE,
31 WCYCLE
32 };
33
34protected:
39
43
44 mutable Array2D<Vector*> X, Y, R, Z;
45 mutable int nrhs;
46
47public:
48 /// Constructs an empty multigrid hierarchy
50
51 /// Constructs a multigrid hierarchy from the given inputs
52 /** Inputs include operators and smoothers on all levels, and ownership of
53 the given operators and smoothers */
54 MultigridBase(const Array<Operator*>& operators_,
55 const Array<Solver*>& smoothers_,
56 const Array<bool>& ownedOperators_,
57 const Array<bool>& ownedSmoothers_);
58
59 /// Destructor
60 virtual ~MultigridBase();
61
62 /// Adds a level to the multigrid operator hierarchy
63 /** The ownership of the operators and solvers/smoothers may be transferred
64 to the Multigrid by setting the according boolean variables */
65 void AddLevel(Operator* op, Solver* smoother, bool ownOperator,
66 bool ownSmoother);
67
68 /// Returns the number of levels
69 int NumLevels() const { return operators.Size(); }
70
71 /// Returns the index of the finest level
72 int GetFinestLevelIndex() const { return NumLevels() - 1; }
73
74 /// Returns operator at given level
75 const Operator* GetOperatorAtLevel(int level) const
76 {
77 return operators[level];
78 }
80 {
81 return operators[level];
82 }
83
84 /// Returns operator at finest level
93
94 /// Returns smoother at given level
95 const Solver* GetSmootherAtLevel(int level) const
96 {
97 return smoothers[level];
98 }
100 {
101 return smoothers[level];
102 }
103
104 /// Set cycle type and number of pre- and post-smoothing steps used by Mult
105 void SetCycleType(CycleType cycleType_, int preSmoothingSteps_,
106 int postSmoothingSteps_);
107
108 /// Application of the multigrid as a preconditioner
109 virtual void Mult(const Vector& x, Vector& y) const override;
110 virtual void ArrayMult(const Array<const Vector*>& X_,
111 Array<Vector*>& Y_) const override;
112
113 /// Not supported for multigrid
114 virtual void SetOperator(const Operator& op) override
115 {
116 MFEM_ABORT("SetOperator is not supported in Multigrid!");
117 }
118
119private:
120 /// Application of a multigrid cycle at particular level
121 void Cycle(int level) const;
122
123 /// Application of a pre-/post-smoothing step at particular level
124 void SmoothingStep(int level, bool zero, bool transpose) const;
125
126 /// Allocate or destroy temporary storage
127 void InitVectors() const;
128 void EraseVectors() const;
129
130 /// Returns prolongation operator at given level
131 virtual const Operator* GetProlongationAtLevel(int level) const = 0;
132};
133
134/// Multigrid solver class
136{
137protected:
140
141public:
142 /// Constructs an empty multigrid hierarchy
143 Multigrid() = default;
144
145 /// Constructs a multigrid hierarchy from the given inputs
146 /** Inputs include operators and smoothers on all levels, prolongation
147 operators that go from coarser to finer levels, and ownership of the
148 given operators, smoothers, and prolongations */
149 Multigrid(const Array<Operator*>& operators_, const Array<Solver*>& smoothers_,
150 const Array<Operator*>& prolongations_, const Array<bool>& ownedOperators_,
151 const Array<bool>& ownedSmoothers_, const Array<bool>& ownedProlongations_);
152
153 /// Destructor
154 virtual ~Multigrid();
155
156private:
157 /// Returns prolongation operator at given level
158 virtual const Operator* GetProlongationAtLevel(int level) const override
159 {
160 return prolongations[level];
161 }
162};
163
164/// Geometric multigrid associated with a hierarchy of finite element spaces
166{
167protected:
171
172public:
173 /// @brief Deprecated.
174 ///
175 /// Construct an empty geometric multigrid object for the given finite
176 /// element space hierarchy @a fespaces_.
177 ///
178 /// @deprecated Use GeometricMultigrid::GeometricMultigrid(const
179 /// FiniteElementSpaceHierarchy&, const Array<int>&) instead. This version
180 /// constructs prolongation and restriction operators without eliminated
181 /// essential boundary conditions.
182 MFEM_DEPRECATED
184
185 /// @brief Construct a geometric multigrid object for the given finite
186 /// element space hierarchy @a fespaces_, where @a ess_bdr is a list of
187 /// mesh boundary element attributes that define the essential DOFs.
188 ///
189 /// If @a ess_bdr is empty, or all its entries are 0, then no essential
190 /// boundary conditions are imposed and the protected array essentialTrueDofs
191 /// remains empty.
193 const Array<int> &ess_bdr);
194
195 /// Destructor
196 virtual ~GeometricMultigrid();
197
198 /** Form the linear system A X = B, corresponding to the operator on the
199 finest level of the geometric multigrid hierarchy */
201 Vector& B);
202
203 /// Recover the solution of a linear system formed with FormFineLinearSystem()
204 void RecoverFineFEMSolution(const Vector& X, const Vector& b, Vector& x);
205};
206
207} // namespace mfem
208
209#endif
Dynamic 2D array using row-major layout.
Definition array.hpp:372
Geometric multigrid associated with a hierarchy of finite element spaces.
MFEM_DEPRECATED GeometricMultigrid(const FiniteElementSpaceHierarchy &fespaces_)
Deprecated.
void RecoverFineFEMSolution(const Vector &X, const Vector &b, Vector &x)
Recover the solution of a linear system formed with FormFineLinearSystem()
Array< Array< int > * > essentialTrueDofs
Array< BilinearForm * > bfs
const FiniteElementSpaceHierarchy & fespaces
void FormFineLinearSystem(Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B)
virtual ~GeometricMultigrid()
Destructor.
Abstract base class for Multigrid solvers.
Definition multigrid.hpp:26
virtual void ArrayMult(const Array< const Vector * > &X_, Array< Vector * > &Y_) const override
Operator application on a matrix: Y=A(X).
Solver * GetSmootherAtLevel(int level)
Definition multigrid.hpp:99
Array2D< Vector * > R
Definition multigrid.hpp:44
int GetFinestLevelIndex() const
Returns the index of the finest level.
Definition multigrid.hpp:72
Array2D< Vector * > Y
Definition multigrid.hpp:44
int NumLevels() const
Returns the number of levels.
Definition multigrid.hpp:69
virtual ~MultigridBase()
Destructor.
Definition multigrid.cpp:36
Array< Operator * > operators
Definition multigrid.hpp:35
Array2D< Vector * > Z
Definition multigrid.hpp:44
Array< bool > ownedSmoothers
Definition multigrid.hpp:38
const Operator * GetOperatorAtLevel(int level) const
Returns operator at given level.
Definition multigrid.hpp:75
Array< bool > ownedOperators
Definition multigrid.hpp:37
virtual void SetOperator(const Operator &op) override
Not supported for multigrid.
Array2D< Vector * > X
Definition multigrid.hpp:44
void AddLevel(Operator *op, Solver *smoother, bool ownOperator, bool ownSmoother)
Adds a level to the multigrid operator hierarchy.
Definition multigrid.cpp:87
Array< Solver * > smoothers
Definition multigrid.hpp:36
MultigridBase()
Constructs an empty multigrid hierarchy.
Definition multigrid.cpp:17
virtual void Mult(const Vector &x, Vector &y) const override
Application of the multigrid as a preconditioner.
const Solver * GetSmootherAtLevel(int level) const
Returns smoother at given level.
Definition multigrid.hpp:95
void SetCycleType(CycleType cycleType_, int preSmoothingSteps_, int postSmoothingSteps_)
Set cycle type and number of pre- and post-smoothing steps used by Mult.
Definition multigrid.cpp:98
const Operator * GetOperatorAtFinestLevel() const
Returns operator at finest level.
Definition multigrid.hpp:85
Operator * GetOperatorAtLevel(int level)
Definition multigrid.hpp:79
Operator * GetOperatorAtFinestLevel()
Definition multigrid.hpp:89
Multigrid solver class.
Multigrid()=default
Constructs an empty multigrid hierarchy.
Array< bool > ownedProlongations
Array< Operator * > prolongations
virtual ~Multigrid()
Destructor.
Pointer to an Operator of a specified type.
Definition handle.hpp:34
Abstract operator.
Definition operator.hpp:25
Base class for solvers.
Definition operator.hpp:683
Vector data type.
Definition vector.hpp:80
real_t b
Definition lissajous.cpp:42