MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
quadinterpolator.hpp
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#ifndef MFEM_QUADINTERP
13#define MFEM_QUADINTERP
14
15#include "fespace.hpp"
16#include "kernel_dispatch.hpp"
17
18namespace mfem
19{
20
21/** @brief A class that performs interpolation from an E-vector to quadrature
22 point values and/or derivatives (Q-vectors). */
23/** An E-vector represents the element-wise discontinuous version of the FE
24 space and can be obtained, for example, from a GridFunction using the
25 Operator returned by FiniteElementSpace::GetElementRestriction().
26
27 The target quadrature points in the elements can be described either by an
28 IntegrationRule (all mesh elements must be of the same type in this case) or
29 by a QuadratureSpace. */
31{
32protected:
33 friend class FiniteElementSpace; // Needs access to qspace and IntRule
34
35 const FiniteElementSpace *fespace; ///< Not owned
36 const QuadratureSpace *qspace; ///< Not owned
37 const IntegrationRule *IntRule; ///< Not owned
38 mutable QVectorLayout q_layout; ///< Output Q-vector layout
39
40 mutable bool use_tensor_products; ///< Tensor product evaluation mode
41 mutable Vector d_buffer; ///< Auxiliary device buffer
42
43 /// Auxiliary method called by Mult() when using H(div)-conforming space
44 void MultHDiv(const Vector &e_vec, unsigned eval_flags,
45 Vector &q_val, Vector &q_div) const;
46
47public:
48 static const int MAX_NQ2D = 100;
49 static const int MAX_ND2D = 100;
50 static const int MAX_VDIM2D = 3;
51
52 static const int MAX_NQ3D = 1000;
53 static const int MAX_ND3D = 1000;
54 static const int MAX_VDIM3D = 3;
55
57 {
58 VALUES = 1 << 0, ///< Evaluate the values at quadrature points
59 DERIVATIVES = 1 << 1, ///< Evaluate the derivatives at quadrature points
60 /** @brief Assuming the derivative at quadrature points form a matrix,
61 this flag can be used to compute and store their determinants. This
62 flag can only be used in Mult(). */
63 DETERMINANTS = 1 << 2,
64 PHYSICAL_DERIVATIVES = 1 << 3, ///< Evaluate the physical derivatives
65 /** Evaluate the values in physical space; for fields with
66 FiniteElement::MapType other than FiniteElement::MapType::VALUE,
67 such as H(div) and H(curl) elements, the physical values are different
68 from the reference values. */
70 /** For vector-valued fields, evaluate the magnitudes of the physical
71 space vector values at quadrature points. */
72 PHYSICAL_MAGNITUDES = 1 << 5
73 };
74
76 const IntegrationRule &ir);
77
79 const QuadratureSpace &qs);
80
81 /** @brief Disable the use of tensor product evaluations, for tensor-product
82 elements, e.g. quads and hexes. By default, tensor product evaluations
83 are enabled. */
84 /** @sa EnableTensorProducts(), UsesTensorProducts(). */
85 void DisableTensorProducts(bool disable = true) const
86 { use_tensor_products = !disable; }
87
88 /** @brief Enable the use of tensor product evaluations, for tensor-product
89 elements, e.g. quads and hexes. By default, this option is enabled. */
90 /** @sa DisableTensorProducts(), UsesTensorProducts(). */
92
93 /** @brief Query the current tensor product evaluation mode. */
94 /** @sa DisableTensorProducts(), EnableTensorProducts(). */
95 bool UsesTensorProducts() const { return use_tensor_products; }
96
97 /** @brief Query the current output Q-vector layout. The default value is
98 QVectorLayout::byNODES. */
99 /** @sa SetOutputLayout(). */
101
102 /** @brief Set the desired output Q-vector layout. The default value is
103 QVectorLayout::byNODES. */
104 /** @sa GetOutputLayout(). */
105 void SetOutputLayout(QVectorLayout layout) const { q_layout = layout; }
106
107 /// Interpolate the E-vector @a e_vec to quadrature points.
108 /** The @a eval_flags are a bitwise mask of constants from the EvalFlags
109 enumeration. When the VALUES flag is set, the values at quadrature points
110 are computed and stored in the Vector @a q_val. Similarly, when one of
111 the flags DERIVATIVES or PHYSICAL_DERIVATIVES is set, the derivatives
112 (with respect to reference or physical coordinates, respectively) are
113 computed and stored in @a q_der. Only one of the flags DERIVATIVES or
114 PHYSICAL_DERIVATIVES can be set in a call. When the DETERMINANTS flag is
115 set, it is assumed that the derivatives (with respect to reference
116 coordinates) form a matrix at each quadrature point (i.e. the associated
117 FiniteElementSpace is a vector space) and their determinants are computed
118 and stored in @a q_det.
119
120 For Integral spaces, the flags VALUES requests the computation of the
121 scalar field values. The result is stored in @a q_val. Derivative types
122 are not supported.
123
124 For H(div)-conforming spaces, the flags VALUES / PHYSICAL_VALUES request
125 the computation of the vector field values in reference or physical
126 space, respectively. The flag PHYSICAL_MAGNITUDES requests the
127 computation of the physical space magnitudes. In all 3 cases, the result
128 is stored in @a q_val and therefore only one of the 3 cases can be
129 requested in a single call.
130
131 The layout of the input E-vector, @a e_vec, must be consistent with the
132 evaluation mode: if tensor-product evaluations are enabled, then
133 tensor-product elements, must use the ElementDofOrdering::LEXICOGRAPHIC
134 layout; otherwise -- ElementDofOrdering::NATIVE layout. See
135 FiniteElementSpace::GetElementRestriction(). */
136 void Mult(const Vector &e_vec, unsigned eval_flags,
137 Vector &q_val, Vector &q_der, Vector &q_det) const;
138
139 /// Interpolate the values of the E-vector @a e_vec at quadrature points.
140 void Values(const Vector &e_vec, Vector &q_val) const;
141
142 /// @brief Interpolate the physical values of the E-vector @a e_vec at
143 /// quadrature points.
144 void PhysValues(const Vector &e_vec, Vector &q_val) const;
145
146 /** @brief Interpolate the derivatives (with respect to reference
147 coordinates) of the E-vector @a e_vec at quadrature points. */
148 void Derivatives(const Vector &e_vec, Vector &q_der) const;
149
150 /** @brief Interpolate the derivatives in physical space of the E-vector
151 @a e_vec at quadrature points. */
152 void PhysDerivatives(const Vector &e_vec, Vector &q_der) const;
153
154 /** @brief Compute the determinants of the derivatives (with respect to
155 reference coordinates) of the E-vector @a e_vec at quadrature points. */
156 void Determinants(const Vector &e_vec, Vector &q_det) const;
157
158 /// Perform the transpose operation of Mult(). (TODO)
159 void MultTranspose(unsigned eval_flags, const Vector &q_val,
160 const Vector &q_der, Vector &e_vec) const;
161
162 /// @brief Returns true if the given finite element space is supported by
163 /// QuadratureInterpolator.
164 static bool SupportsFESpace(const FiniteElementSpace &fespace);
165
166 // value map types
167 using TensorEvalKernelType = void (*)(const int ne, const real_t *B,
168 const real_t *e_vec, real_t *q_val,
169 const int vdim, const int nd,
170 const int nq);
171 using GradKernelType = void (*)(const int ne, const real_t *B,
172 const real_t *G, const real_t *J,
173 const real_t *e_vec, real_t *q_der,
174 const int s_dim, const int v_dim,
175 const int nd, const int nq);
176 using CollocatedGradKernelType = void (*)(const int ne, const real_t *G,
177 const real_t *J,
178 const real_t *e_vec, real_t *q_der,
179 const int sdim, const int vdim,
180 const int d1d);
181 using DetKernelType = void (*)(const int NE, const real_t *B,
182 const real_t *G, const real_t *e_vec,
183 real_t *q_det, const int nd, const int nq,
185 using EvalKernelType = void (*)(const int NE, const int vdim,
187 const GeometricFactors *geom,
188 const DofToQuad &maps, const Vector &e_vec,
189 Vector &q_val, Vector &q_der, Vector &q_det,
190 const int eval_flags);
191
192 // integral map types
193 using IntTensorEvalKernelType = void (*)(const int ne, const real_t *B,
194 const real_t *detJ,
195 const real_t *e_vec, real_t *q_val,
196 const int vdim, const int nd,
197 const int nq);
199 void (*)(const int NE, const int vdim, const QVectorLayout q_layout,
200 const real_t *detJ, const GeometricFactors *geom,
201 const DofToQuad &maps, const Vector &e_vec, Vector &q_val,
202 Vector &q_der, Vector &q_det, const int eval_flags);
203
205 void(*)(const int, const real_t *, const real_t *, const real_t *,
206 const real_t *, real_t *, const int, const int);
207
208 // value-type mapping
210 (int, QVectorLayout, int, int, int), (int));
212 (int, QVectorLayout, bool, int, int, int), (int));
213 MFEM_REGISTER_KERNELS(DetKernels, DetKernelType, (int, int, int, int));
214 MFEM_REGISTER_KERNELS(EvalKernels, EvalKernelType, (int, int, int, int));
216 (int, QVectorLayout, bool, int, int), (int));
217
218 // integral-type mapping
220 (int, QVectorLayout, int, int, int), (int));
221 MFEM_REGISTER_KERNELS(IntEvalKernels, IntEvalKernelType, (int, int, int, int));
222
224 (int, QVectorLayout, unsigned, int, int));
225
226 /// Adds specializations for TensorEvalKernels
227 template <int DIM, QVectorLayout Q_LAYOUT, int VDIM, int D1D, int Q1D,
228 int NBZ = 0>
230 {
231 if constexpr (NBZ)
232 {
233 IntTensorEvalKernels::Specialization<DIM, Q_LAYOUT, VDIM, D1D,
234 Q1D>::template Opt<NBZ>::Add();
235 TensorEvalKernels::Specialization<DIM, Q_LAYOUT, VDIM, D1D,
236 Q1D>::template Opt<NBZ>::Add();
237 }
238 else if constexpr (NBZ == 0)
239 {
240 IntTensorEvalKernels::Specialization<DIM, Q_LAYOUT, VDIM, D1D,
241 Q1D>::Add();
242 TensorEvalKernels::Specialization<DIM, Q_LAYOUT, VDIM, D1D,
243 Q1D>::Add();
244 }
245 }
246
247 /// Adds specializations for EvalKernels
248 template <int DIM, int VDIM, int ND, int NQ>
250 {
251 IntEvalKernels::Specialization<DIM, VDIM, ND, NQ>::Add();
252 EvalKernels::Specialization<DIM, VDIM, ND, NQ>::Add();
253 }
254
255 /// Adds specializations for GradKernels
256 template <int DIM, QVectorLayout Q_LAYOUT, bool GRAD_PHYS, int VDIM, int D1D,
257 int Q1D, int NBZ = 0>
259 {
260 if constexpr (NBZ)
261 {
262 GradKernels::Specialization<DIM, Q_LAYOUT, GRAD_PHYS, VDIM, D1D,
263 Q1D>::template Opt<NBZ>::Add();
264 }
265 else if constexpr (NBZ == 0)
266 {
267 GradKernels::Specialization<DIM, Q_LAYOUT, GRAD_PHYS, VDIM, D1D,
268 Q1D>::Add();
269 }
270 }
271
272 /// Adds specializations for CollocatedGradKernels
273 template <int DIM, QVectorLayout Q_LAYOUT, bool GRAD_PHYS, int VDIM, int D1D,
274 int NBZ = 0>
276 {
277 if constexpr (NBZ)
278 {
279 CollocatedGradKernels::Specialization<DIM, Q_LAYOUT, GRAD_PHYS, VDIM,
280 D1D>::template Opt<NBZ>::Add();
281 }
282 else if constexpr (NBZ == 0)
283 {
284 CollocatedGradKernels::Specialization<DIM, Q_LAYOUT, GRAD_PHYS, VDIM,
285 D1D>::Add();
286 }
287 }
288
289 /// Adds specializations for DetKernels
290 template <int DIM, int SDIM, int D1D, int Q1D>
292 {
293 DetKernels::Specialization<DIM, SDIM, D1D, Q1D>::Add();
294 }
295};
296
297}
298
299#endif
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:210
Structure for storing mesh geometric factors: coordinates, Jacobians, and determinants of the Jacobia...
Definition mesh.hpp:3119
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:96
A class that performs interpolation from an E-vector to quadrature point values and/or derivatives (Q...
bool use_tensor_products
Tensor product evaluation mode.
@ VALUES
Evaluate the values at quadrature points.
@ DERIVATIVES
Evaluate the derivatives at quadrature points.
@ PHYSICAL_DERIVATIVES
Evaluate the physical derivatives.
@ DETERMINANTS
Assuming the derivative at quadrature points form a matrix, this flag can be used to compute and stor...
MFEM_REGISTER_KERNELS(TensorEvalKernels, TensorEvalKernelType,(int, QVectorLayout, int, int, int),(int))
QuadratureInterpolator(const FiniteElementSpace &fes, const IntegrationRule &ir)
static void AddCollocatedGradSpecializations()
Adds specializations for CollocatedGradKernels.
MFEM_REGISTER_KERNELS(TensorEvalHDivKernels, TensorEvalHDivKernelType,(int, QVectorLayout, unsigned, int, int))
void Mult(const Vector &e_vec, unsigned eval_flags, Vector &q_val, Vector &q_der, Vector &q_det) const
Interpolate the E-vector e_vec to quadrature points.
void(*)(const int NE, const real_t *B, const real_t *G, const real_t *e_vec, real_t *q_det, const int nd, const int nq, Vector *d_buffer) DetKernelType
void SetOutputLayout(QVectorLayout layout) const
Set the desired output Q-vector layout. The default value is QVectorLayout::byNODES.
void(*)(const int ne, const real_t *B, const real_t *e_vec, real_t *q_val, const int vdim, const int nd, const int nq) TensorEvalKernelType
void Determinants(const Vector &e_vec, Vector &q_det) const
Compute the determinants of the derivatives (with respect to reference coordinates) of the E-vector e...
bool UsesTensorProducts() const
Query the current tensor product evaluation mode.
void(*)(const int ne, const real_t *B, const real_t *G, const real_t *J, const real_t *e_vec, real_t *q_der, const int s_dim, const int v_dim, const int nd, const int nq) GradKernelType
void MultTranspose(unsigned eval_flags, const Vector &q_val, const Vector &q_der, Vector &e_vec) const
Perform the transpose operation of Mult(). (TODO)
void DisableTensorProducts(bool disable=true) const
Disable the use of tensor product evaluations, for tensor-product elements, e.g. quads and hexes....
void EnableTensorProducts() const
Enable the use of tensor product evaluations, for tensor-product elements, e.g. quads and hexes....
MFEM_REGISTER_KERNELS(EvalKernels, EvalKernelType,(int, int, int, int))
void(*)(const int NE, const int vdim, const QVectorLayout q_layout, const GeometricFactors *geom, const DofToQuad &maps, const Vector &e_vec, Vector &q_val, Vector &q_der, Vector &q_det, const int eval_flags) EvalKernelType
void(*)(const int NE, const int vdim, const QVectorLayout q_layout, const real_t *detJ, const GeometricFactors *geom, const DofToQuad &maps, const Vector &e_vec, Vector &q_val, Vector &q_der, Vector &q_det, const int eval_flags) IntEvalKernelType
void Values(const Vector &e_vec, Vector &q_val) const
Interpolate the values of the E-vector e_vec at quadrature points.
void(*)(const int, const real_t *, const real_t *, const real_t *, const real_t *, real_t *, const int, const int) TensorEvalHDivKernelType
void PhysValues(const Vector &e_vec, Vector &q_val) const
Interpolate the physical values of the E-vector e_vec at quadrature points.
MFEM_REGISTER_KERNELS(IntEvalKernels, IntEvalKernelType,(int, int, int, int))
void Derivatives(const Vector &e_vec, Vector &q_der) const
Interpolate the derivatives (with respect to reference coordinates) of the E-vector e_vec at quadratu...
MFEM_REGISTER_KERNELS(IntTensorEvalKernels, IntTensorEvalKernelType,(int, QVectorLayout, int, int, int),(int))
static void AddGradSpecializations()
Adds specializations for GradKernels.
QVectorLayout q_layout
Output Q-vector layout.
QVectorLayout GetOutputLayout() const
Query the current output Q-vector layout. The default value is QVectorLayout::byNODES.
void PhysDerivatives(const Vector &e_vec, Vector &q_der) const
Interpolate the derivatives in physical space of the E-vector e_vec at quadrature points.
static bool SupportsFESpace(const FiniteElementSpace &fespace)
Returns true if the given finite element space is supported by QuadratureInterpolator.
static void AddEvalSpecializations()
Adds specializations for EvalKernels.
static void AddDetSpecializations()
Adds specializations for DetKernels.
const IntegrationRule * IntRule
Not owned.
void(*)(const int ne, const real_t *B, const real_t *detJ, const real_t *e_vec, real_t *q_val, const int vdim, const int nd, const int nq) IntTensorEvalKernelType
MFEM_REGISTER_KERNELS(DetKernels, DetKernelType,(int, int, int, int))
Vector d_buffer
Auxiliary device buffer.
const FiniteElementSpace * fespace
Not owned.
MFEM_REGISTER_KERNELS(CollocatedGradKernels, CollocatedGradKernelType,(int, QVectorLayout, bool, int, int),(int))
const QuadratureSpace * qspace
Not owned.
void MultHDiv(const Vector &e_vec, unsigned eval_flags, Vector &q_val, Vector &q_div) const
Auxiliary method called by Mult() when using H(div)-conforming space.
void(*)(const int ne, const real_t *G, const real_t *J, const real_t *e_vec, real_t *q_der, const int sdim, const int vdim, const int d1d) CollocatedGradKernelType
MFEM_REGISTER_KERNELS(GradKernels, GradKernelType,(int, QVectorLayout, bool, int, int, int),(int))
static void AddTensorEvalSpecializations()
Adds specializations for TensorEvalKernels.
Class representing the storage layout of a QuadratureFunction.
Definition qspace.hpp:164
Vector data type.
Definition vector.hpp:82
constexpr int DIM
QVectorLayout
Type describing possible layouts for Q-vectors.
Definition fespace.hpp:33
float real_t
Definition config.hpp:46
void Add(const DenseMatrix &A, const DenseMatrix &B, real_t alpha, DenseMatrix &C)
C = A + alpha*B.