MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
dgmassinv.cpp
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#include "dgmassinv.hpp"
13#include "bilinearform.hpp"
14#include "dgmassinv_kernels.hpp"
15
16namespace mfem
17{
18
19struct DGMassInvKernels { DGMassInvKernels(); };
20
22 Coefficient *coeff,
23 const IntegrationRule *ir,
24 int btype)
25 : Solver(fes_orig.GetTrueVSize()),
26 fec(fes_orig.GetMaxElementOrder(),
27 fes_orig.GetMesh()->Dimension(),
28 btype,
29 fes_orig.GetTypicalFE()->GetMapType()),
30 fes(fes_orig.GetMesh(), &fec)
31{
32 static DGMassInvKernels kernels;
33
34 MFEM_VERIFY(fes.IsDGSpace(), "Space must be DG.");
35 MFEM_VERIFY(!fes.IsVariableOrder(), "Variable orders not supported.");
36
37 const int btype_orig =
38 static_cast<const L2_FECollection*>(fes_orig.FEColl())->GetBasisType();
39
40 if (btype_orig == btype)
41 {
42 // No change of basis required
43 d2q = nullptr;
44 }
45 else
46 {
47 // original basis to solver basis
48 const auto mode = DofToQuad::TENSOR;
49 const FiniteElement &fe_orig = *fes_orig.GetTypicalFE();
50 const FiniteElement &fe = *fes.GetTypicalFE();
51 d2q = &fe_orig.GetDofToQuad(fe.GetNodes(), mode);
52
53 const int n = d2q->ndof;
54 Array<real_t> B_inv = d2q->B; // deep copy
55 Array<int> ipiv(n);
56 // solver basis to original
57 LUFactors lu(B_inv.HostReadWrite(), ipiv.HostWrite());
58 lu.Factor(n);
59 B_.SetSize(n*n);
61 Bt_.SetSize(n*n);
62 DenseMatrix B_matrix(B_.HostReadWrite(), n, n);
63 DenseMatrix Bt_matrix(Bt_.HostWrite(), n, n);
64 Bt_matrix.Transpose(B_matrix);
65 }
66
67 if (coeff) { m = new MassIntegrator(*coeff, ir); }
68 else { m = new MassIntegrator(ir); }
69
71 // Workspace vectors used for CG
75 // Only need transformed RHS if basis is different
76 if (btype_orig != btype) { b2_.SetSize(height); }
77
78 M.reset(new BilinearForm(&fes));
79 M->AddDomainIntegrator(m); // M assumes ownership of m
80 M->SetAssemblyLevel(AssemblyLevel::PARTIAL);
81
82 // Assemble the bilinear form and its diagonal (for preconditioning).
83 Update();
84}
85
87 int btype)
88 : DGMassInverse(fes_, &coeff, nullptr, btype) { }
89
91 const IntegrationRule &ir, int btype)
92 : DGMassInverse(fes_, &coeff, &ir, btype) { }
93
95 const IntegrationRule &ir, int btype)
96 : DGMassInverse(fes_, nullptr, &ir, btype) { }
97
99 : DGMassInverse(fes_, nullptr, nullptr, btype) { }
100
102{
103 MFEM_ABORT("SetOperator not supported with DGMassInverse.")
104}
105
106void DGMassInverse::SetRelTol(const real_t rel_tol_) { rel_tol = rel_tol_; }
107
108void DGMassInverse::SetAbsTol(const real_t abs_tol_) { abs_tol = abs_tol_; }
109
110void DGMassInverse::SetMaxIter(const int max_iter_) { max_iter = max_iter_; }
111
113{
114 M->Assemble();
117}
118
120
121void DGMassInverse::Mult(const Vector &Mu, Vector &u) const
122{
123 // Dispatch to templated version based on dim, d1d, and q1d.
124 const int dim = fes.GetMesh()->Dimension();
125 const int d1d = m->dofs1D;
126 const int q1d = m->quad1D;
127
128 CGKernels::Run(dim, d1d, q1d, *this, Mu, u);
129}
130
131DGMassInvKernels::DGMassInvKernels()
132{
133 using k = DGMassInverse::CGKernels;
134 // 2D
135 k::Specialization<2,1,1>::Add();
136 k::Specialization<2,2,2>::Add();
137 k::Specialization<2,3,3>::Add();
138 k::Specialization<2,3,5>::Add();
139 k::Specialization<2,4,4>::Add();
140 k::Specialization<2,4,6>::Add();
141 k::Specialization<2,5,5>::Add();
142 k::Specialization<2,5,7>::Add();
143 k::Specialization<2,6,6>::Add();
144 k::Specialization<2,6,8>::Add();
145 // 3D
146 k::Specialization<3,2,2>::Add();
147 k::Specialization<3,2,3>::Add();
148 k::Specialization<3,3,3>::Add();
149 k::Specialization<3,3,4>::Add();
150 k::Specialization<3,3,5>::Add();
151 k::Specialization<3,4,4>::Add();
152 k::Specialization<3,4,5>::Add();
153 k::Specialization<3,4,6>::Add();
154 k::Specialization<3,4,8>::Add();
155 k::Specialization<3,5,5>::Add();
156 k::Specialization<3,5,6>::Add();
157 k::Specialization<3,5,7>::Add();
158 k::Specialization<3,5,8>::Add();
159 k::Specialization<3,6,6>::Add();
160 k::Specialization<3,6,7>::Add();
161}
162
163} // namespace mfem
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition array.hpp:869
T * HostReadWrite()
Shortcut for mfem::ReadWrite(a.GetMemory(), a.Size(), false).
Definition array.hpp:430
T * HostWrite()
Shortcut for mfem::Write(a.GetMemory(), a.Size(), false).
Definition array.hpp:422
A "square matrix" operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
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
class MassIntegrator * m
Mass integrator, owned by the form M.
Definition dgmassinv.hpp:38
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:21
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
void SetOperator(const Operator &op) override
Not implemented. Aborts.
void Update()
Recompute operator and preconditioner (when coefficient or mesh changes).
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.
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
void Transpose()
(*this) = (*this)^t
@ TENSOR
Tensor product representation using 1D matrices/tensors with dimensions using 1D number of quadrature...
Definition fe_base.hpp:165
Array< real_t > B
Basis functions evaluated at quadrature points.
Definition fe_base.hpp:201
int ndof
Number of degrees of freedom = number of basis functions. When mode is TENSOR, this is the 1D number.
Definition fe_base.hpp:186
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:210
bool IsVariableOrder() const
Returns true if the space contains elements of varying polynomial orders.
Definition fespace.hpp:673
const FiniteElementCollection * FEColl() const
Definition fespace.hpp:854
Mesh * GetMesh() const
Returns the mesh.
Definition fespace.hpp:639
bool IsDGSpace() const
Return whether or not the space is discontinuous (L2)
Definition fespace.hpp:1587
const FiniteElement * GetTypicalFE() const
Return GetFE(0) if the local mesh is not empty; otherwise return a typical FE based on the Geometry t...
Definition fespace.cpp:3896
Abstract class for all finite elements.
Definition fe_base.hpp:294
virtual const DofToQuad & GetDofToQuad(const IntegrationRule &ir, DofToQuad::Mode mode) const
Return a DofToQuad structure corresponding to the given IntegrationRule using the given DofToQuad::Mo...
Definition fe_base.cpp:373
const IntegrationRule & GetNodes() const
Get a const reference to the nodes of the element.
Definition fe_base.hpp:476
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:96
Arbitrary order "L2-conforming" discontinuous finite elements.
Definition fe_coll.hpp:369
bool Factor(int m, real_t TOL=0.0) override
Compute the LU factorization of the current matrix.
void GetInverseMatrix(int m, real_t *X) const override
Assuming L.U = P.A factored data of size (m x m), compute X <- A^{-1}.
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1314
Abstract operator.
Definition operator.hpp:27
int height
Dimension of the output / number of rows in the matrix.
Definition operator.hpp:29
virtual void AssembleDiagonal(Vector &diag) const
Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operat...
Definition operator.hpp:166
Base class for solvers.
Definition operator.hpp:855
Vector data type.
Definition vector.hpp:82
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:633
void Reciprocal()
(*this)(i) = 1.0 / (*this)(i)
Definition vector.cpp:384
int dim
Definition ex24.cpp:53
Mesh * GetMesh(int type)
Definition ex29.cpp:218
real_t u(const Vector &xvec)
Definition lor_mms.hpp:22
float real_t
Definition config.hpp:46