MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
qspace.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_QSPACE
13#define MFEM_QSPACE
14
15#include "../config/config.hpp"
16#include "fespace.hpp"
17#include <unordered_map>
18
19namespace mfem
20{
21
23{
24 FULL,
26};
27
28/// Abstract base class for QuadratureSpace and FaceQuadratureSpace.
29/** This class represents the storage layout for QuadratureFunction%s, that may
30 be defined either on mesh elements or mesh faces. */
32{
33protected:
34 friend class QuadratureFunction; // Uses the offsets.
35
36 Mesh &mesh; ///< The underlying mesh.
37 int order; ///< The order of integration rule.
38 int size; ///< Total number of quadrature points.
39 int ne; ///< Number of entities
40 mutable Vector weights; ///< Integration weights.
41 mutable long nodes_sequence = 0; ///< Nodes counter for cache invalidation.
42
43 /// @brief Entity quadrature point offset array.
44 ///
45 /// Supports a constant compression scheme for meshes which have a single
46 /// geometry type. When compressed, will have a single value. The true offset
47 /// can be computed as i * offsets[0], where i is the entity index. Otherwise
48 /// has size num_entities + 1.
49 ///
50 /// In the non-compressed case, the quadrature point values for entity i are
51 /// stored in the indices between offsets[i] and offsets[i+1].
53
54 /// @brief Cached version of the "full" offsets, returned by Offsets() when
55 /// QSpaceOffsetStorage::FULL is provided.
56 ///
57 /// The quadrature point values for entity i are stored in the indices
58 /// between offsets[i] and offsets[i+1].
60
61 /// The quadrature rules used for each geometry type.
63
64 /// Protected constructor. Used by derived classes.
65 QuadratureSpaceBase(Mesh &mesh_, int order_ = 0)
66 : mesh(mesh_), order(order_) { }
67
68 /// Protected constructor. Used by derived classes.
70 const IntegrationRule &ir);
71
72 /// Fill the @ref int_rule array for each geometry type using @ref order.
73 void ConstructIntRules(int dim);
74
75 /// Compute the det(J) (volume or faces, depending on the type).
76 virtual const Vector &GetGeometricFactorWeights() const = 0;
77
78 /// Compute the integration weights.
79 void ConstructWeights() const;
80
81public:
82 /// @brief Gets the offset for a given entity @a idx.
83 ///
84 /// The quadrature point values for entity i are stored in the indices
85 /// between Offset(i) and Offset(i+1)
86 int Offset(int idx) const
87 {
88 return (offsets.Size() == 1) ? (idx * offsets[0]) : offsets[idx];
89 }
90
91 /// @brief Entity quadrature point offset array.
92 ///
93 /// If @a storage is QSpaceOffsetStorage::COMPRESSED, then the returned array
94 /// supports a constant compression scheme for meshes which have a single
95 /// geometry type. When compressed, will have a single value. The true offset
96 /// can be computed as i * offsets[0], where i is the entity index. Otherwise
97 /// has size num_entities + 1.
98 ///
99 /// If @a storage is QSpaceOffsetStorage::FULL, then the array will never be
100 /// compressed.
101 ///
102 /// In the non-compressed case, the quadrature point values for entity i are
103 /// stored in the indices between offsets[i] and offsets[i+1].
104 const Array<int> &Offsets(QSpaceOffsetStorage storage) const;
105
106 /// Return the total number of quadrature points.
107 int GetSize() const { return size; }
108
109 /// Return the order of the quadrature rule(s) used by all elements.
110 int GetOrder() const { return order; }
111
112 /// Return the number of entities.
113 int GetNE() const { return ne; }
114
115 /// Returns the mesh.
116 inline Mesh *GetMesh() const { return &mesh; }
117
118 /// Get the (element or face) transformation of entity @a idx.
120
121 /// Return the geometry type of entity (element or face) @a idx.
122 virtual Geometry::Type GetGeometry(int idx) const = 0;
123
124 /// Return the IntegrationRule associated with entity @a idx.
125 const IntegrationRule &GetIntRule(int idx) const
126 { return *int_rule[GetGeometry(idx)]; }
127
128 /// @brief Returns the permuted index of the @a iq quadrature point in entity
129 /// @a idx.
130 ///
131 /// For tensor-product faces, returns the lexicographic index of the
132 /// quadrature point, oriented relative to "element 1". For QuadratureSpace%s
133 /// defined on elements (not faces), the permutation is trivial, and this
134 /// returns @a iq.
135 virtual int GetPermutedIndex(int idx, int iq) const = 0;
136
137 /// @brief Returns the index in the quadrature space of the entity associated
138 /// with the transformation @a T.
139 ///
140 /// For a QuadratureSpace defined on elements, this just returns the element
141 /// index. For FaceQuadratureSpace, the returned index depends on the chosen
142 /// FaceType. If the entity is not found (for example, if @a T represents an
143 /// interior face, and the space has FaceType::Boundary) then -1 is returned.
144 virtual int GetEntityIndex(const ElementTransformation &T) const = 0;
145
146 /// Write the QuadratureSpace to the stream @a out.
147 virtual void Save(std::ostream &out) const = 0;
148
149 /// Return the integration weights (including geometric factors).
150 const Vector &GetWeights() const;
151
152 /// Return the integral of the scalar Coefficient @a coeff.
153 real_t Integrate(Coefficient &coeff) const;
154
155 /// Return the integral of the VectorCoefficient @a coeff in @a integrals.
156 void Integrate(VectorCoefficient &coeff, Vector &integrals) const;
157
159};
160
161/// Class representing the storage layout of a QuadratureFunction.
162/** Multiple QuadratureFunction%s can share the same QuadratureSpace. */
164{
165protected:
166 const Vector &GetGeometricFactorWeights() const override;
167 void ConstructOffsets();
168 void Construct();
169public:
170 /// Create a QuadratureSpace based on the global rules from #IntRules.
171 QuadratureSpace(Mesh *mesh_, int order_)
172 : QuadratureSpaceBase(*mesh_, order_) { Construct(); }
173
174 /// @brief Create a QuadratureSpace with an IntegrationRule, valid only when
175 /// the mesh has one element type.
176 QuadratureSpace(Mesh &mesh_, const IntegrationRule &ir);
177
178 /// Read a QuadratureSpace from the stream @a in.
179 QuadratureSpace(Mesh *mesh_, std::istream &in);
180
181 /// Returns number of elements in the mesh.
182 inline int GetNE() const { return mesh.GetNE(); }
183
184 /// Returns the element transformation of element @a idx.
187
188 /// Returns the geometry type of element @a idx.
189 Geometry::Type GetGeometry(int idx) const override
190 { return mesh.GetElementGeometry(idx); }
191
192 /// Get the IntegrationRule associated with mesh element @a idx.
193 const IntegrationRule &GetElementIntRule(int idx) const
194 { return *int_rule[mesh.GetElementBaseGeometry(idx)]; }
195
196 /// @brief Returns the permuted index of the @a iq quadrature point in entity
197 /// @a idx.
198 ///
199 /// The member function QuadratureSpace::GetPermutedIndex always returns @a
200 /// iq, the permutation is only nontrivial for FaceQuadratureSpace.
201 int GetPermutedIndex(int idx, int iq) const override { return iq; }
202
203 /// Returns the element index of @a T.
204 int GetEntityIndex(const ElementTransformation &T) const override { return T.ElementNo; }
205
206 /// Write the QuadratureSpace to the stream @a out.
207 void Save(std::ostream &out) const override;
208};
209
210/// Class representing the storage layout of a FaceQuadratureFunction.
211/** FaceQuadratureSpace is defined on either the interior or boundary faces
212 of a mesh, depending on the provided FaceType. */
214{
215 FaceType face_type; ///< Is the space defined on interior or boundary faces?
216
217 /// Map from boundary or interior face indices to mesh face indices.
218 const Array<int> &face_indices;
219
220 /// Inverse of the map @a face_indices.
221 const std::unordered_map<int,int> &face_indices_inv;
222
223 const Vector &GetGeometricFactorWeights() const override;
224 void ConstructOffsets();
225 void Construct();
226
227public:
228 /// Create a FaceQuadratureSpace based on the global rules from #IntRules.
229 FaceQuadratureSpace(Mesh &mesh_, int order_, FaceType face_type_);
230
231 /// @brief Create a FaceQuadratureSpace with an IntegrationRule, valid only
232 /// when the mesh has one type of face geometry.
233 FaceQuadratureSpace(Mesh &mesh_, const IntegrationRule &ir,
234 FaceType face_type_);
235
236 /// Returns number of faces in the mesh.
237 inline int GetNumFaces() const { return face_indices.Size(); }
238
239 /// Returns the face type (boundary or interior).
240 FaceType GetFaceType() const { return face_type; }
241
242 /// Returns the face transformation of face @a idx.
243 ElementTransformation *GetTransformation(int idx) override;
244
245 /// Returns the geometry type of face @a idx.
246 Geometry::Type GetGeometry(int idx) const override
247 { return mesh.GetFaceGeometry(face_indices[idx]); }
248
249 /// Get the IntegrationRule associated with mesh element @a idx.
250 const IntegrationRule &GetFaceIntRule(int idx) const
251 { return *int_rule[GetGeometry(idx)]; }
252
253 /// @brief Returns the permuted index of the @a iq quadrature point in entity
254 /// @a idx.
255 ///
256 /// For tensor-product faces, returns the lexicographic index of the
257 /// quadrature point, oriented relative to "element 1".
258 int GetPermutedIndex(int idx, int iq) const override;
259
260 /// @brief Get the face index (in the standard Mesh numbering) associated
261 /// with face @a idx in the FaceQuadratureSpace.
262 int GetMeshFaceIndex(int idx) const { return face_indices[idx]; }
263
264 /// @brief Returns the index associated with the face described by @a T.
265 ///
266 /// The index may differ from the mesh face or boundary element index
267 /// depending on the FaceType used to construct the FaceQuadratureSpace.
268 int GetEntityIndex(const ElementTransformation &T) const override;
269
270 /// Write the FaceQuadratureSpace to the stream @a out.
271 void Save(std::ostream &out) const override;
272};
273
274}
275
276#endif
int Size() const
Return the logical size of the array.
Definition array.hpp:166
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
Class representing the storage layout of a FaceQuadratureFunction.
Definition qspace.hpp:214
FaceType GetFaceType() const
Returns the face type (boundary or interior).
Definition qspace.hpp:240
int GetMeshFaceIndex(int idx) const
Get the face index (in the standard Mesh numbering) associated with face idx in the FaceQuadratureSpa...
Definition qspace.hpp:262
int GetEntityIndex(const ElementTransformation &T) const override
Returns the index associated with the face described by T.
Definition qspace.cpp:287
Geometry::Type GetGeometry(int idx) const override
Returns the geometry type of face idx.
Definition qspace.hpp:246
void Save(std::ostream &out) const override
Write the FaceQuadratureSpace to the stream out.
Definition qspace.cpp:309
int GetPermutedIndex(int idx, int iq) const override
Returns the permuted index of the iq quadrature point in entity idx.
Definition qspace.cpp:260
const IntegrationRule & GetFaceIntRule(int idx) const
Get the IntegrationRule associated with mesh element idx.
Definition qspace.hpp:250
FaceQuadratureSpace(Mesh &mesh_, int order_, FaceType face_type_)
Create a FaceQuadratureSpace based on the global rules from IntRules.
Definition qspace.cpp:205
int GetNumFaces() const
Returns number of faces in the mesh.
Definition qspace.hpp:237
ElementTransformation * GetTransformation(int idx) override
Returns the face transformation of face idx.
Definition qspace.cpp:277
static const int NumGeom
Definition geom.hpp:46
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:100
Mesh data type.
Definition mesh.hpp:65
Geometry::Type GetFaceGeometry(int i) const
Return the Geometry::Type associated with face i.
Definition mesh.cpp:1576
Geometry::Type GetElementGeometry(int i) const
Definition mesh.hpp:1535
int GetNE() const
Returns number of elements.
Definition mesh.hpp:1377
void GetElementTransformation(int i, IsoparametricTransformation *ElTr) const
Builds the transformation defining the i-th element in ElTr. ElTr must be allocated in advance and wi...
Definition mesh.cpp:360
Geometry::Type GetElementBaseGeometry(int i) const
Definition mesh.hpp:1556
Represents values or vectors of values at quadrature points on a mesh.
Definition qfunction.hpp:24
Abstract base class for QuadratureSpace and FaceQuadratureSpace.
Definition qspace.hpp:32
Vector weights
Integration weights.
Definition qspace.hpp:40
virtual Geometry::Type GetGeometry(int idx) const =0
Return the geometry type of entity (element or face) idx.
const Vector & GetWeights() const
Return the integration weights (including geometric factors).
Definition qspace.cpp:94
void ConstructWeights() const
Compute the integration weights.
Definition qspace.cpp:81
int GetNE() const
Return the number of entities.
Definition qspace.hpp:113
virtual void Save(std::ostream &out) const =0
Write the QuadratureSpace to the stream out.
void ConstructIntRules(int dim)
Fill the int_rule array for each geometry type using order.
Definition qspace.cpp:30
virtual ElementTransformation * GetTransformation(int idx)=0
Get the (element or face) transformation of entity idx.
int GetSize() const
Return the total number of quadrature points.
Definition qspace.hpp:107
const IntegrationRule * int_rule[Geometry::NumGeom]
The quadrature rules used for each geometry type.
Definition qspace.hpp:62
QuadratureSpaceBase(Mesh &mesh_, int order_=0)
Protected constructor. Used by derived classes.
Definition qspace.hpp:65
long nodes_sequence
Nodes counter for cache invalidation.
Definition qspace.hpp:41
int order
The order of integration rule.
Definition qspace.hpp:37
const IntegrationRule & GetIntRule(int idx) const
Return the IntegrationRule associated with entity idx.
Definition qspace.hpp:125
virtual const Vector & GetGeometricFactorWeights() const =0
Compute the det(J) (volume or faces, depending on the type).
int ne
Number of entities.
Definition qspace.hpp:39
int Offset(int idx) const
Gets the offset for a given entity idx.
Definition qspace.hpp:86
virtual int GetEntityIndex(const ElementTransformation &T) const =0
Returns the index in the quadrature space of the entity associated with the transformation T.
virtual int GetPermutedIndex(int idx, int iq) const =0
Returns the permuted index of the iq quadrature point in entity idx.
const Array< int > & Offsets(QSpaceOffsetStorage storage) const
Entity quadrature point offset array.
Definition qspace.cpp:40
Array< int > full_offset_cache
Cached version of the "full" offsets, returned by Offsets() when QSpaceOffsetStorage::FULL is provide...
Definition qspace.hpp:59
int GetOrder() const
Return the order of the quadrature rule(s) used by all elements.
Definition qspace.hpp:110
Mesh & mesh
The underlying mesh.
Definition qspace.hpp:36
Array< int > offsets
Entity quadrature point offset array.
Definition qspace.hpp:52
int size
Total number of quadrature points.
Definition qspace.hpp:38
virtual ~QuadratureSpaceBase()
Definition qspace.hpp:158
Mesh * GetMesh() const
Returns the mesh.
Definition qspace.hpp:116
real_t Integrate(Coefficient &coeff) const
Return the integral of the scalar Coefficient coeff.
Definition qspace.cpp:104
Class representing the storage layout of a QuadratureFunction.
Definition qspace.hpp:164
int GetEntityIndex(const ElementTransformation &T) const override
Returns the element index of T.
Definition qspace.hpp:204
int GetPermutedIndex(int idx, int iq) const override
Returns the permuted index of the iq quadrature point in entity idx.
Definition qspace.hpp:201
const Vector & GetGeometricFactorWeights() const override
Compute the det(J) (volume or faces, depending on the type).
Definition qspace.cpp:194
int GetNE() const
Returns number of elements in the mesh.
Definition qspace.hpp:182
const IntegrationRule & GetElementIntRule(int idx) const
Get the IntegrationRule associated with mesh element idx.
Definition qspace.hpp:193
ElementTransformation * GetTransformation(int idx) override
Returns the element transformation of element idx.
Definition qspace.hpp:185
void Save(std::ostream &out) const override
Write the QuadratureSpace to the stream out.
Definition qspace.cpp:187
QuadratureSpace(Mesh *mesh_, int order_)
Create a QuadratureSpace based on the global rules from IntRules.
Definition qspace.hpp:171
Geometry::Type GetGeometry(int idx) const override
Returns the geometry type of element idx.
Definition qspace.hpp:189
Base class for vector Coefficients that optionally depend on time and space.
Vector data type.
Definition vector.hpp:82
int dim
Definition ex24.cpp:53
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition globals.hpp:66
@ COMPRESSED
Enable all above compressions.
QSpaceOffsetStorage
Definition qspace.hpp:23
float real_t
Definition config.hpp:46
FaceType
Definition mesh.hpp:49