MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
bilininteg_mass_pa.cpp
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
13#include "../bilininteg.hpp"
14#include "../gridfunc.hpp"
15#include "../qfunction.hpp"
18
19namespace mfem
20{
21
22// PA Mass Integrator
23
25{
26 const MemoryType mt = (pa_mt == MemoryType::DEFAULT) ?
28
29 // Assuming the same element type
30 fespace = &fes;
31 Mesh *mesh = fes.GetMesh();
32 const FiniteElement &el = *fes.GetTypicalFE();
34 const IntegrationRule *ir = IntRule ? IntRule : &GetRule(el, el, *T0);
35 if (DeviceCanUseCeed())
36 {
37 delete ceedOp;
38 const bool mixed = mesh->GetNumGeometries(mesh->Dimension()) > 1 ||
39 fes.IsVariableOrder();
40 if (mixed)
41 {
42 ceedOp = new ceed::MixedPAMassIntegrator(*this, fes, Q);
43 }
44 else
45 {
46 ceedOp = new ceed::PAMassIntegrator(fes, *ir, Q);
47 }
48 return;
49 }
50 int map_type = el.GetMapType();
51 dim = mesh->Dimension();
52 ne = fes.GetMesh()->GetNE();
53 nq = ir->GetNPoints();
56 dofs1D = maps->ndof;
57 quad1D = maps->nqpt;
58 pa_data.SetSize(ne*nq, mt);
59
60 QuadratureSpace qs(*mesh, *ir);
62 {
63 const int NE = ne;
64 const int NQ = nq;
65 const bool const_c = coeff.Size() == 1;
66 const bool by_val = map_type == FiniteElement::VALUE;
67 const auto W = Reshape(ir->GetWeights().Read(), NQ);
68 const auto J = Reshape(geom->detJ.Read(), NQ, NE);
69 const auto C =
70 const_c ? Reshape(coeff.Read(), 1, 1) : Reshape(coeff.Read(), NQ, NE);
71 auto v = Reshape(pa_data.Write(), NQ, NE);
72 mfem::forall(NQ, NE, [=] MFEM_HOST_DEVICE(int q, int e)
73 {
74 const real_t detJ = J(q, e);
75 const real_t coeff = const_c ? C(0, 0) : C(q, e);
76 v(q, e) = W(q) * coeff * (by_val ? detJ : 1.0 / detJ);
77 });
78 }
79}
80
82{
83 const MemoryType mt = (pa_mt == MemoryType::DEFAULT) ?
85
86 // Assuming the same element type
87 fespace = &fes;
88 Mesh *mesh = fes.GetMesh();
90 if (ne == 0) { return; }
91 const FiniteElement &el = *fes.GetBE(0);
93 const IntegrationRule *ir = IntRule ? IntRule : &GetRule(el, el, *T0);
94
95 int map_type = el.GetMapType();
96 dim = el.GetDim(); // Dimension of the boundary element, *not* the mesh
97 nq = ir->GetNPoints();
101 dofs1D = maps->ndof;
102 quad1D = maps->nqpt;
103 pa_data.SetSize(ne*nq, mt);
104
107
108 const int NE = ne;
109 const int NQ = nq;
110 const bool const_c = coeff.Size() == 1;
111 const bool by_val = map_type == FiniteElement::VALUE;
112 {
113 const auto W = Reshape(ir->GetWeights().Read(), NQ);
114 const auto J = Reshape(face_geom->detJ.Read(), NQ, NE);
115 const auto C = const_c ? Reshape(coeff.Read(), 1, 1)
116 : Reshape(coeff.Read(), NQ, NE);
117 auto v = Reshape(pa_data.Write(), NQ, NE);
118 mfem::forall(NQ, NE, [=] MFEM_HOST_DEVICE(int q, int e)
119 {
120 const real_t detJ = J(q, e);
121 const real_t coeff = const_c ? C(0, 0) : C(q, e);
122 v(q, e) = W(q) * coeff * (by_val ? detJ : 1.0 / detJ);
123 });
124 }
125}
126
128{
129 if (DeviceCanUseCeed())
130 {
131 ceedOp->GetDiagonal(diag);
132 }
133 else
134 {
135 DiagonalPAKernels::Run(dim, dofs1D, quad1D, ne, maps->B, pa_data,
136 diag, dofs1D, quad1D);
137 }
138}
139
141{
142 if (DeviceCanUseCeed())
143 {
144 ceedOp->AddMult(x, y);
145 }
146 else
147 {
148 const int D1D = dofs1D;
149 const int Q1D = quad1D;
150 const Array<real_t> &B = maps->B;
151 const Array<real_t> &Bt = maps->Bt;
152 const Vector &D = pa_data;
153#ifdef MFEM_USE_OCCA
154 if (DeviceCanUseOcca())
155 {
156 if (dim == 2)
157 {
158 return internal::OccaPAMassApply2D(D1D,Q1D,ne,B,Bt,D,x,y);
159 }
160 if (dim == 3)
161 {
162 return internal::OccaPAMassApply3D(D1D,Q1D,ne,B,Bt,D,x,y);
163 }
164 MFEM_ABORT("OCCA PA Mass Apply unknown kernel!");
165 }
166#endif // MFEM_USE_OCCA
167 ApplyPAKernels::Run(dim, D1D, Q1D, ne, B, Bt, D, x, y, D1D, Q1D);
168 }
169}
170
172{
173 if (DeviceCanUseCeed())
174 {
175 MFEM_ABORT("AddAbsMultPA not implemented with CEED!");
176 ceedOp->AddMult(x, y);
177 }
178 else
179 {
180 Vector abs_pa_data(pa_data);
181 abs_pa_data.Abs();
182 Array<real_t> absB(maps->B);
183 Array<real_t> absBt(maps->Bt);
184 absB.Abs();
185 absBt.Abs();
186
187 ApplyPAKernels::Run(dim, dofs1D, quad1D, ne, absB, absBt, abs_pa_data,
188 x, y, dofs1D, quad1D);
189 }
190}
191
193{
194 // Mass integrator is symmetric
195 AddMultPA(x, y);
196}
197
199{
200 // Mass integrator is symmetric
201 AddAbsMultPA(x, y);
202}
203
204} // namespace mfem
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition array.hpp:381
void Abs()
Replace each entry of the array with its absolute value.
Definition array.cpp:115
Class to represent a coefficient evaluated at quadrature points.
static MemoryType GetDeviceMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
Definition device.hpp:277
@ 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:193
int ndof
Number of degrees of freedom = number of basis functions. When mode is TENSOR, this is the 1D number.
Definition fe_base.hpp:178
int nqpt
Number of quadrature points. When mode is TENSOR, this is the 1D number.
Definition fe_base.hpp:182
Array< real_t > Bt
Transpose of B.
Definition fe_base.hpp:199
Vector detJ
Determinants of the Jacobians at all quadrature points.
Definition mesh.hpp:3169
Class representing the storage layout of a FaceQuadratureFunction.
Definition qspace.hpp:214
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:208
bool IsVariableOrder() const
Returns true if the space contains elements of varying polynomial orders.
Definition fespace.hpp:678
const FiniteElement * GetBE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th boundary fac...
Definition fespace.cpp:3870
Mesh * GetMesh() const
Returns the mesh.
Definition fespace.hpp:644
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:3860
Abstract class for all finite elements.
Definition fe_base.hpp:247
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:375
int GetDim() const
Returns the reference space dimension for the finite element.
Definition fe_base.hpp:324
int GetMapType() const
Returns the FiniteElement::MapType of the element describing how reference functions are mapped to ph...
Definition fe_base.hpp:363
Vector detJ
Determinants of the Jacobians at all quadrature points.
Definition mesh.hpp:3121
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:100
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition intrules.hpp:256
const Array< real_t > & GetWeights() const
Return the quadrature weights in a contiguous array.
Definition intrules.cpp:86
const IntegrationRule * IntRule
const FiniteElementSpace * fespace
const FaceGeometricFactors * face_geom
Not owned.
void AddAbsMultPA(const Vector &, Vector &) const override
const DofToQuad * maps
Not owned.
static const IntegrationRule & GetRule(const FiniteElement &trial_fe, const FiniteElement &test_fe, const ElementTransformation &Trans)
void AddMultPA(const Vector &, Vector &) const override
Method for partially assembled action.
void AssemblePABoundary(const FiniteElementSpace &fes) override
virtual void AssembleDiagonalPA(Vector &diag) override
Assemble diagonal and add it to Vector diag.
void AssemblePA(const FiniteElementSpace &fes) override
Method defining partial assembly.
const GeometricFactors * geom
Not owned.
void AddMultTransposePA(const Vector &, Vector &) const override
Method for partially assembled transposed action.
void AddAbsMultTransposePA(const Vector &, Vector &) const override
Mesh data type.
Definition mesh.hpp:65
virtual int GetNFbyType(FaceType type) const
Returns the number of faces according to the requested type, does not count master nonconforming face...
Definition mesh.cpp:6862
const FaceGeometricFactors * GetFaceGeometricFactors(const IntegrationRule &ir, const int flags, FaceType type, MemoryType d_mt=MemoryType::DEFAULT)
Return the mesh geometric factors for the faces corresponding to the given integration rule.
Definition mesh.cpp:903
int GetNE() const
Returns number of elements.
Definition mesh.hpp:1377
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1306
ElementTransformation * GetTypicalElementTransformation()
If the local mesh is not empty return GetElementTransformation(0); otherwise, return the identity tra...
Definition mesh.cpp:393
ElementTransformation * GetBdrElementTransformation(int i)
Returns a pointer to the transformation defining the i-th boundary element.
Definition mesh.cpp:533
const GeometricFactors * GetGeometricFactors(const IntegrationRule &ir, const int flags, MemoryType d_mt=MemoryType::DEFAULT)
Return the mesh geometric factors corresponding to the given integration rule.
Definition mesh.cpp:883
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
Definition mesh.cpp:7558
Class representing the storage layout of a QuadratureFunction.
Definition qspace.hpp:164
Vector data type.
Definition vector.hpp:82
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:520
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
void Abs()
(*this)(i) = abs((*this)(i))
Definition vector.cpp:392
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:584
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:528
void GetDiagonal(mfem::Vector &diag) const
Definition operator.cpp:104
void AddMult(const mfem::Vector &x, mfem::Vector &y, const real_t a=1.0) const override
Operator application: y+=A(x) (default) or y+=a*A(x).
Definition operator.cpp:72
Represent a MassIntegrator with AssemblyLevel::Partial using libCEED.
Definition mass.hpp:27
MFEM_HOST_DEVICE DeviceTensor< sizeof...(Dims), T > Reshape(T *ptr, Dims... dims)
Wrap a pointer as a DeviceTensor with automatically deduced template parameters.
Definition dtensor.hpp:138
bool DeviceCanUseCeed()
Function that determines if a CEED kernel should be used, based on the current mfem::Device configura...
Definition util.cpp:33
@ COMPRESSED
Enable all above compressions.
bool DeviceCanUseOcca()
Function that determines if an OCCA kernel should be used, based on the current mfem::Device configur...
Definition occa.hpp:69
float real_t
Definition config.hpp:46
MemoryType
Memory types supported by MFEM.
void forall(int N, lambda &&body)
Definition forall.hpp:839