MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
dgmassinv.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_DGMASSINV_HPP
13#define MFEM_DGMASSINV_HPP
14
16#include "fespace.hpp"
17#include "kernel_dispatch.hpp"
18#include <memory>
19
20namespace mfem
21{
22
23/// @brief Solver for the discontinuous Galerkin mass matrix.
24///
25/// This class performs a @a local (diagonally preconditioned) conjugate
26/// gradient iteration for each element. Optionally, a change of basis is
27/// performed to iterate on a better-conditioned system. This class fully
28/// supports execution on device (GPU).
29class DGMassInverse : public Solver
30{
31protected:
32 DG_FECollection fec; ///< FE collection in requested basis.
33 FiniteElementSpace fes; ///< FE space in requested basis.
34 const DofToQuad *d2q; ///< Change of basis. Not owned.
35 Array<real_t> B_; ///< Inverse of change of basis.
36 Array<real_t> Bt_; ///< Inverse of change of basis, transposed.
37 std::unique_ptr<class BilinearForm> M; ///< Mass bilinear form.
38 class MassIntegrator *m; ///< Mass integrator, owned by the form @ref M.
39 Vector diag_inv; ///< Jacobi preconditioner.
40 real_t rel_tol = 1e-12; ///< Relative CG tolerance.
41 real_t abs_tol = 1e-12; ///< Absolute CG tolerance.
42 int max_iter = 100; ///< Maximum number of CG iterations;
43
44 /// @name Intermediate vectors needed for CG three-term recurrence.
45 ///@{
46 mutable Vector r_, d_, z_, b2_;
47 ///@}
48
49 /// @brief Protected constructor, used internally.
50 ///
51 /// Custom coefficient and integration rule are used if @a coeff and @a ir
52 /// are non-NULL.
54 const IntegrationRule *ir, int btype);
55public:
56 /// @brief Construct the DG inverse mass operator for @a fes_.
57 ///
58 /// The basis type @a btype determines which basis should be used internally
59 /// in the solver. This <b>does not</b> have to be the same basis as @a fes_.
60 /// The best choice is typically BasisType::GaussLegendre because it is
61 /// well-preconditioned by its diagonal.
62 ///
63 /// The solution and right-hand side used for the solver are not affected by
64 /// this basis (they correspond to the basis of @a fes_). @a btype is only
65 /// used internally, and only has an effect on the convergence rate.
67 int btype=BasisType::GaussLegendre);
68 /// @brief Construct the DG inverse mass operator for @a fes_ with
69 /// Coefficient @a coeff.
70 ///
71 /// @sa DGMassInverse(FiniteElementSpace&, int) for information about @a
72 /// btype.
74 int btype=BasisType::GaussLegendre);
75 /// @brief Construct the DG inverse mass operator for @a fes_ with
76 /// Coefficient @a coeff and IntegrationRule @a ir.
77 ///
78 /// @sa DGMassInverse(FiniteElementSpace&, int) for information about @a
79 /// btype.
81 const IntegrationRule &ir, int btype=BasisType::GaussLegendre);
82 /// @brief Construct the DG inverse mass operator for @a fes_ with
83 /// IntegrationRule @a ir.
84 ///
85 /// @sa DGMassInverse(FiniteElementSpace&, int) for information about @a
86 /// btype.
88 int btype=BasisType::GaussLegendre);
89 /// @brief Solve the system M b = u.
90 ///
91 /// If @ref iterative_mode is @a true, @a u is used as an initial guess.
92 void Mult(const Vector &b, Vector &u) const override;
93 /// Same as Mult() since the mass matrix is symmetric.
94 void MultTranspose(const Vector &b, Vector &u) const override { Mult(b, u); }
95 /// Not implemented. Aborts.
96 void SetOperator(const Operator &op) override;
97 /// Set the relative tolerance.
98 void SetRelTol(const real_t rel_tol_);
99 /// Set the absolute tolerance.
100 void SetAbsTol(const real_t abs_tol_);
101 /// Set the maximum number of iterations.
102 void SetMaxIter(const int max_iter_);
103 /// Recompute operator and preconditioner (when coefficient or mesh changes).
104 void Update();
105
107
108 /// @brief Solve the system M b = u. <b>Not part of the public interface.</b>
109 /// @note This member function must be public because it defines an
110 /// extended lambda used in an mfem::forall kernel (nvcc limitation)
111 template<int DIM, int D1D = 0, int Q1D = 0>
112 void DGMassCGIteration(const Vector &b_, Vector &u_) const;
113
114 using CGKernelType = void(DGMassInverse::*)(const Vector &b_, Vector &u) const;
115 MFEM_REGISTER_KERNELS(CGKernels, CGKernelType, (int, int, int));
116};
117
118} // namespace mfem
119
120#endif
@ GaussLegendre
Open type.
Definition fe_base.hpp:35
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
Solver for the discontinuous Galerkin mass matrix.
Definition dgmassinv.hpp:30
Vector diag_inv
Jacobi preconditioner.
Definition dgmassinv.hpp:39
void MultTranspose(const Vector &b, Vector &u) const override
Same as Mult() since the mass matrix is symmetric.
Definition dgmassinv.hpp:94
class MassIntegrator * m
Mass integrator, owned by the form M.
Definition dgmassinv.hpp:38
void(DGMassInverse::*)(const Vector &b_, Vector &u) const CGKernelType
real_t rel_tol
Relative CG tolerance.
Definition dgmassinv.hpp:40
int max_iter
Maximum number of CG iterations;.
Definition dgmassinv.hpp:42
Array< real_t > B_
Inverse of change of basis.
Definition dgmassinv.hpp:35
std::unique_ptr< class BilinearForm > M
Mass bilinear form.
Definition dgmassinv.hpp:37
real_t abs_tol
Absolute CG tolerance.
Definition dgmassinv.hpp:41
DGMassInverse(const FiniteElementSpace &fes_, Coefficient *coeff, const IntegrationRule *ir, int btype)
Protected constructor, used internally.
Definition dgmassinv.cpp:22
void SetMaxIter(const int max_iter_)
Set the maximum number of iterations.
Array< real_t > Bt_
Inverse of change of basis, transposed.
Definition dgmassinv.hpp:36
DG_FECollection fec
FE collection in requested basis.
Definition dgmassinv.hpp:32
void SetOperator(const Operator &op) override
Not implemented. Aborts.
void Update()
Recompute operator and preconditioner (when coefficient or mesh changes).
void DGMassCGIteration(const Vector &b_, Vector &u_) const
Solve the system M b = u. Not part of the public interface.
MFEM_REGISTER_KERNELS(CGKernels, CGKernelType,(int, int, int))
void Mult(const Vector &b, Vector &u) const override
Solve the system M b = u.
void SetRelTol(const real_t rel_tol_)
Set the relative tolerance.
FiniteElementSpace fes
FE space in requested basis.
Definition dgmassinv.hpp:33
const DofToQuad * d2q
Change of basis. Not owned.
Definition dgmassinv.hpp:34
void SetAbsTol(const real_t abs_tol_)
Set the absolute tolerance.
Structure representing the matrices/tensors needed to evaluate (in reference space) the values,...
Definition fe_base.hpp:141
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:208
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:100
Arbitrary order "L2-conforming" discontinuous finite elements.
Definition fe_coll.hpp:350
Abstract operator.
Definition operator.hpp:25
Base class for solvers.
Definition operator.hpp:792
Vector data type.
Definition vector.hpp:82
real_t b
Definition lissajous.cpp:42
real_t u(const Vector &xvec)
Definition lor_mms.hpp:22
float real_t
Definition config.hpp:46