MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
algebraic.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_CEED_ALGEBRAIC_HPP
13#define MFEM_CEED_ALGEBRAIC_HPP
14
16#include "../../multigrid.hpp"
18#include "../interface/ceed.hpp"
19
20namespace mfem
21{
22
23namespace ceed
24{
25
26#ifdef MFEM_USE_CEED
27/** @brief A way to use algebraic levels in a Multigrid object
28
29 This is analogous to a FiniteElementSpace but with no Mesh information,
30 constructed in a semi-algebraic way. */
32{
33public:
34 AlgebraicCoarseSpace(FiniteElementSpace &fine_fes, CeedElemRestriction fine_er,
35 int order, int dim, int order_reduction_);
36 int GetOrderReduction() const { return order_reduction; }
37 CeedElemRestriction GetCeedElemRestriction() const { return ceed_elem_restriction; }
38 CeedBasis GetCeedCoarseToFine() const { return coarse_to_fine; }
39 virtual const mfem::Operator *GetProlongationMatrix() const override { return NULL; }
40 virtual const SparseMatrix *GetRestrictionMatrix() const override { return NULL; }
42
43protected:
44 int *dof_map;
46 CeedElemRestriction ceed_elem_restriction;
47 CeedBasis coarse_to_fine;
48};
49
50#ifdef MFEM_USE_MPI
51
52/** @brief Parallel version of AlgebraicCoarseSpace
53
54 This provides prolongation and restriction matrices for RAP-type parallel
55 operators and potential explicit assembly. */
57{
58public:
60 FiniteElementSpace &fine_fes,
61 CeedElemRestriction fine_er,
62 int order,
63 int dim,
64 int order_reduction_,
65 GroupCommunicator *gc_fine
66 );
67 virtual const mfem::Operator *GetProlongationMatrix() const override { return P; }
68 virtual const SparseMatrix *GetRestrictionMatrix() const override { return R_mat; }
72
73private:
74 SparseMatrix *R_mat;
77 HypreParMatrix *P_mat;
78 Array<int> ldof_group, ldof_ltdof;
79};
80
81#endif // MFEM_USE_MPI
82
83/** @brief Multigrid interpolation operator in Ceed framework
84
85 Interpolation/restriction has two components, an element-wise interpolation
86 and then a scaling to correct multiplicity on shared ldofs. This
87 encapsulates those two in one object using the MFEM Operator interface. */
89{
90public:
92 Ceed ceed, CeedBasis basisctof,
93 CeedElemRestriction erestrictu_coarse,
94 CeedElemRestriction erestrictu_fine);
95
97
98 virtual void Mult(const mfem::Vector& x, mfem::Vector& y) const;
99
100 virtual void MultTranspose(const mfem::Vector& x, mfem::Vector& y) const;
101
103private:
104 int Initialize(Ceed ceed, CeedBasis basisctof,
105 CeedElemRestriction erestrictu_coarse,
106 CeedElemRestriction erestrictu_fine);
107 int Finalize();
108
109 CeedBasis basisctof_;
110 CeedVector u_, v_;
111
112 bool owns_basis_;
113
114 CeedQFunction qf_restrict, qf_prolong;
115 CeedOperator op_interp, op_restrict;
116 CeedVector fine_multiplicity_r;
117 CeedVector fine_work;
118};
119
120/** @brief Hierarchy of AlgebraicCoarseSpace objects for use in Multigrid
121 object */
123{
124public:
125 /** @brief Construct hierarchy based on finest FiniteElementSpace
126
127 The given space is a real (geometric) space, but the coarse spaces are
128 constructed semi-algebraically with no mesh information. */
131 {
132 MFEM_ASSERT(level < GetNumLevels() - 1, "");
133 return static_cast<AlgebraicCoarseSpace&>(*fespaces[level]);
134 }
136 {
137 for (int i=0; i<R_tr.Size(); ++i)
138 {
139 delete R_tr[i];
140 }
141 for (int i=0; i<ceed_interpolations.Size(); ++i)
142 {
143 delete ceed_interpolations[i];
144 }
145 }
146
147private:
148 CeedElemRestriction fine_er;
149 Array<AlgebraicInterpolation*> ceed_interpolations;
151};
152
153/** @brief Extension of Multigrid object to algebraically generated coarse
154 spaces */
156{
157public:
158 /** @brief Constructs multigrid solver based on existing space hierarchy
159
160 This only works if the Ceed device backend is enabled.
161
162 @param[in] hierarchy Hierarchy of (algebraic) spaces
163 @param[in] form partially assembled BilinearForm on finest level
164 @param[in] ess_tdofs List of essential true dofs on finest level
165 */
167 AlgebraicSpaceHierarchy &hierarchy,
168 BilinearForm &form,
169 const Array<int> &ess_tdofs
170 );
171 virtual void SetOperator(const mfem::Operator &op) override { }
173
174private:
175 OperatorHandle fine_operator;
176 Array<CeedOperator> ceed_operators;
177};
178#endif // MFEM_USE_CEED
179
180/** @brief Wrapper for AlgebraicMultigrid object
181
182 This exists so that the algebraic Ceed-based idea has the simplest possible
183 one-line interface. Finer control (choosing smoothers, w-cycle) can be
184 exercised with the AlgebraicMultigrid object. */
186{
187private:
188#ifdef MFEM_USE_CEED
189 AlgebraicSpaceHierarchy * fespaces;
190 AlgebraicMultigrid * multigrid;
191#endif
192
193public:
194 /** @brief Constructs algebraic multigrid hierarchy and solver.
195
196 This only works if the Ceed device backend is enabled.
197
198 @param[in] form partially assembled BilinearForm on finest level
199 @param[in] ess_tdofs List of essential true dofs on finest level
200 */
201 AlgebraicSolver(BilinearForm &form, const Array<int>& ess_tdofs);
203 void Mult(const Vector& x, Vector& y) const;
204 void SetOperator(const mfem::Operator& op);
205};
206
207} // namespace ceed
208
209} // namespace mfem
210
211#endif // MFEM_CEED_ALGEBRAIC_HPP
A "square matrix" operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
Auxiliary class used by ParFiniteElementSpace.
Definition pfespace.hpp:442
int GetNumLevels() const
Returns the number of levels in the hierarchy.
Array< FiniteElementSpace * > fespaces
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:220
Geometric multigrid associated with a hierarchy of finite element spaces.
Communicator performing operations within groups defined by a GroupTopology with arbitrary-size data ...
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:388
Pointer to an Operator of a specified type.
Definition handle.hpp:34
Abstract operator.
Definition operator.hpp:25
Operator * SetupRAP(const Operator *Pi, const Operator *Po)
Returns RAP Operator of this, using input/output Prolongation matrices Pi corresponds to "P",...
Definition operator.cpp:168
Base class for solvers.
Definition operator.hpp:683
Data type sparse matrix.
Definition sparsemat.hpp:51
Vector data type.
Definition vector.hpp:80
A way to use algebraic levels in a Multigrid object.
Definition algebraic.hpp:32
AlgebraicCoarseSpace(FiniteElementSpace &fine_fes, CeedElemRestriction fine_er, int order, int dim, int order_reduction_)
CeedBasis GetCeedCoarseToFine() const
Definition algebraic.hpp:38
virtual const SparseMatrix * GetRestrictionMatrix() const override
The returned SparseMatrix is owned by the FiniteElementSpace.
Definition algebraic.hpp:40
CeedElemRestriction ceed_elem_restriction
Definition algebraic.hpp:46
CeedElemRestriction GetCeedElemRestriction() const
Definition algebraic.hpp:37
virtual const mfem::Operator * GetProlongationMatrix() const override
The returned Operator is owned by the FiniteElementSpace.
Definition algebraic.hpp:39
Multigrid interpolation operator in Ceed framework.
Definition algebraic.hpp:89
virtual void Mult(const mfem::Vector &x, mfem::Vector &y) const
Operator application: y=A(x).
AlgebraicInterpolation(Ceed ceed, CeedBasis basisctof, CeedElemRestriction erestrictu_coarse, CeedElemRestriction erestrictu_fine)
virtual void MultTranspose(const mfem::Vector &x, mfem::Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Extension of Multigrid object to algebraically generated coarse spaces.
virtual void SetOperator(const mfem::Operator &op) override
Not supported for multigrid.
AlgebraicMultigrid(AlgebraicSpaceHierarchy &hierarchy, BilinearForm &form, const Array< int > &ess_tdofs)
Constructs multigrid solver based on existing space hierarchy.
Wrapper for AlgebraicMultigrid object.
AlgebraicSolver(BilinearForm &form, const Array< int > &ess_tdofs)
Constructs algebraic multigrid hierarchy and solver.
void SetOperator(const mfem::Operator &op)
Set/update the solver for the given operator.
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Hierarchy of AlgebraicCoarseSpace objects for use in Multigrid object.
AlgebraicSpaceHierarchy(FiniteElementSpace &fespace)
Construct hierarchy based on finest FiniteElementSpace.
AlgebraicCoarseSpace & GetAlgebraicCoarseSpace(int level)
Parallel version of AlgebraicCoarseSpace.
Definition algebraic.hpp:57
ParAlgebraicCoarseSpace(FiniteElementSpace &fine_fes, CeedElemRestriction fine_er, int order, int dim, int order_reduction_, GroupCommunicator *gc_fine)
GroupCommunicator * GetGroupCommunicator() const
Definition algebraic.hpp:69
HypreParMatrix * GetProlongationHypreParMatrix()
virtual const SparseMatrix * GetRestrictionMatrix() const override
The returned SparseMatrix is owned by the FiniteElementSpace.
Definition algebraic.hpp:68
virtual const mfem::Operator * GetProlongationMatrix() const override
The returned Operator is owned by the FiniteElementSpace.
Definition algebraic.hpp:67
int dim
Definition ex24.cpp:53