MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
algebraic.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, 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 
15 #include "../../fespacehierarchy.hpp"
16 #include "../../multigrid.hpp"
17 #include "../interface/operator.hpp"
18 #include "../interface/ceed.hpp"
19 
20 namespace mfem
21 {
22 
23 namespace 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 {
33 public:
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 
43 protected:
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 {
58 public:
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; }
69  GroupCommunicator *GetGroupCommunicator() const { return gc; }
72 
73 private:
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 {
90 public:
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 
103 private:
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 {
124 public:
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 
147 private:
148  CeedElemRestriction fine_er;
149  Array<AlgebraicInterpolation*> ceed_interpolations;
151 };
152 
153 /** @brief Extension of Multigrid object to algebraically generated coarse
154  spaces */
156 {
157 public:
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 
174 private:
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. */
185 class AlgebraicSolver : public Solver
186 {
187 private:
188 #ifdef MFEM_USE_CEED
189  AlgebraicSpaceHierarchy * fespaces;
190  AlgebraicMultigrid * multigrid;
191 #endif
192 
193 public:
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
CeedElemRestriction GetCeedElemRestriction() const
Definition: algebraic.hpp:37
AlgebraicInterpolation(Ceed ceed, CeedBasis basisctof, CeedElemRestriction erestrictu_coarse, CeedElemRestriction erestrictu_fine)
Definition: algebraic.cpp:460
virtual const SparseMatrix * GetRestrictionMatrix() const override
The returned SparseMatrix is owned by the FiniteElementSpace.
Definition: algebraic.hpp:40
Auxiliary class used by ParFiniteElementSpace.
Definition: pfespace.hpp:439
Geometric multigrid associated with a hierarchy of finite element spaces.
Definition: multigrid.hpp:119
Pointer to an Operator of a specified type.
Definition: handle.hpp:33
virtual const mfem::Operator * GetProlongationMatrix() const override
The returned Operator is owned by the FiniteElementSpace.
Definition: algebraic.hpp:67
Extension of Multigrid object to algebraically generated coarse spaces.
Definition: algebraic.hpp:155
GroupCommunicator * GetGroupCommunicator() const
Definition: algebraic.hpp:69
A way to use algebraic levels in a Multigrid object.
Definition: algebraic.hpp:31
Communicator performing operations within groups defined by a GroupTopology with arbitrary-size data ...
Data type sparse matrix.
Definition: sparsemat.hpp:50
AlgebraicSolver(BilinearForm &form, const Array< int > &ess_tdofs)
Constructs algebraic multigrid hierarchy and solver.
Definition: algebraic.cpp:949
virtual const mfem::Operator * GetProlongationMatrix() const override
The returned Operator is owned by the FiniteElementSpace.
Definition: algebraic.hpp:39
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: algebraic.cpp:975
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 ...
Definition: algebraic.cpp:563
Array< FiniteElementSpace * > fespaces
int GetNumLevels() const
Returns the number of levels in the hierarchy.
CeedBasis GetCeedCoarseToFine() const
Definition: algebraic.hpp:38
Multigrid interpolation operator in Ceed framework.
Definition: algebraic.hpp:88
virtual void Mult(const mfem::Vector &x, mfem::Vector &y) const
Operator application: y=A(x).
Definition: algebraic.cpp:531
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:96
void SetOperator(const mfem::Operator &op)
Set/update the solver for the given operator.
Definition: algebraic.cpp:982
virtual const SparseMatrix * GetRestrictionMatrix() const override
The returned SparseMatrix is owned by the FiniteElementSpace.
Definition: algebraic.hpp:68
AlgebraicCoarseSpace(FiniteElementSpace &fine_fes, CeedElemRestriction fine_er, int order, int dim, int order_reduction_)
Definition: algebraic.cpp:699
CeedElemRestriction ceed_elem_restriction
Definition: algebraic.hpp:46
Wrapper for AlgebraicMultigrid object.
Definition: algebraic.hpp:185
Parallel version of AlgebraicCoarseSpace.
Definition: algebraic.hpp:56
A &quot;square matrix&quot; operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
int dim
Definition: ex24.cpp:53
virtual void SetOperator(const mfem::Operator &op) override
Not supported for multigrid.
Definition: algebraic.hpp:171
Operator * SetupRAP(const Operator *Pi, const Operator *Po)
Returns RAP Operator of this, using input/output Prolongation matrices Pi corresponds to &quot;P&quot;...
Definition: operator.cpp:105
ParAlgebraicCoarseSpace(FiniteElementSpace &fine_fes, CeedElemRestriction fine_er, int order, int dim, int order_reduction_, GroupCommunicator *gc_fine)
Definition: algebraic.cpp:735
Vector data type.
Definition: vector.hpp:60
AlgebraicSpaceHierarchy(FiniteElementSpace &fespace)
Construct hierarchy based on finest FiniteElementSpace.
Definition: algebraic.cpp:610
Base class for solvers.
Definition: operator.hpp:655
Abstract operator.
Definition: operator.hpp:24
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:343
AlgebraicMultigrid(AlgebraicSpaceHierarchy &hierarchy, BilinearForm &form, const Array< int > &ess_tdofs)
Constructs multigrid solver based on existing space hierarchy.
Definition: algebraic.cpp:304
HypreParMatrix * GetProlongationHypreParMatrix()
Definition: algebraic.cpp:823
Hierarchy of AlgebraicCoarseSpace objects for use in Multigrid object.
Definition: algebraic.hpp:122
AlgebraicCoarseSpace & GetAlgebraicCoarseSpace(int level)
Definition: algebraic.hpp:130