MFEM  v4.5.2
Finite element discretization library
qspace.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, 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 
18 namespace mfem
19 {
20 
21 /// Abstract base class for QuadratureSpace and FaceQuadratureSpace.
22 /** This class represents the storage layout for QuadratureFunction%s, that may
23  be defined either on mesh elements or mesh faces. */
25 {
26 protected:
27  friend class QuadratureFunction; // Uses the offsets.
28 
29  Mesh &mesh; ///< The underlying mesh.
30  int order; ///< The order of integration rule.
31  int size; ///< Total number of quadrature points.
32 
33  /// @brief Entity quadrature point offset array, of size num_entities + 1.
34  ///
35  /// The quadrature point values for entity i are stored in the indices between
36  /// offsets[i] and offsets[i+1].
38  /// The quadrature rules used for each geometry type.
40 
41  /// Protected constructor. Used by derived classes.
42  QuadratureSpaceBase(Mesh &mesh_, int order_ = 0)
43  : mesh(mesh_), order(order_) { }
44 
45  /// Protected constructor. Used by derived classes.
47  const IntegrationRule &ir);
48 
49  /// Fill the @ref int_rule array for each geometry type using @ref order.
50  void ConstructIntRules(int dim);
51 
52 public:
53  /// Return the total number of quadrature points.
54  int GetSize() const { return size; }
55 
56  /// Return the order of the quadrature rule(s) used by all elements.
57  int GetOrder() const { return order; }
58 
59  /// Return the number of entities.
60  int GetNE() const { return offsets.Size() - 1; }
61 
62  /// Returns the mesh.
63  inline Mesh *GetMesh() const { return &mesh; }
64 
65  /// Get the (element or face) transformation of entity @a idx.
66  virtual ElementTransformation *GetTransformation(int idx) = 0;
67 
68  /// Return the geometry type of entity (element or face) @a idx.
69  virtual Geometry::Type GetGeometry(int idx) const = 0;
70 
71  /// Return the IntegrationRule associated with entity @a idx.
72  const IntegrationRule &GetIntRule(int idx) const
73  { return *int_rule[GetGeometry(idx)]; }
74 
75  /// @brief Returns the permuted index of the @a iq quadrature point in entity
76  /// @a idx.
77  ///
78  /// For tensor-product faces, returns the lexicographic index of the
79  /// quadrature point, oriented relative to "element 1". For QuadratureSpace%s
80  /// defined on elements (not faces), the permutation is trivial, and this
81  /// returns @a iq.
82  virtual int GetPermutedIndex(int idx, int iq) const = 0;
83 
84  /// Write the QuadratureSpace to the stream @a out.
85  virtual void Save(std::ostream &out) const = 0;
86 
87  virtual ~QuadratureSpaceBase() { }
88 };
89 
90 /// Class representing the storage layout of a QuadratureFunction.
91 /** Multiple QuadratureFunction%s can share the same QuadratureSpace. */
93 {
94 protected:
95  void ConstructOffsets();
96  void Construct();
97 public:
98  /// Create a QuadratureSpace based on the global rules from #IntRules.
99  QuadratureSpace(Mesh *mesh_, int order_)
100  : QuadratureSpaceBase(*mesh_, order_) { Construct(); }
101 
102  /// @brief Create a QuadratureSpace with an IntegrationRule, valid only when
103  /// the mesh has one element type.
104  QuadratureSpace(Mesh &mesh_, const IntegrationRule &ir);
105 
106  /// Read a QuadratureSpace from the stream @a in.
107  QuadratureSpace(Mesh *mesh_, std::istream &in);
108 
109  /// Returns number of elements in the mesh.
110  inline int GetNE() const { return mesh.GetNE(); }
111 
112  /// Returns the element transformation of element @a idx.
114  { return mesh.GetElementTransformation(idx); }
115 
116  /// Returns the geometry type of element @a idx.
117  Geometry::Type GetGeometry(int idx) const override
118  { return mesh.GetElementGeometry(idx); }
119 
120  /// Get the IntegrationRule associated with mesh element @a idx.
121  const IntegrationRule &GetElementIntRule(int idx) const
122  { return *int_rule[mesh.GetElementBaseGeometry(idx)]; }
123 
124  /// @brief Returns the permuted index of the @a iq quadrature point in entity
125  /// @a idx.
126  ///
127  /// The member function QuadratureSpace::GetPermutedIndex always returns @a
128  /// iq, the permutation is only nontrivial for FaceQuadratureSpace.
129  int GetPermutedIndex(int idx, int iq) const override { return iq; }
130 
131  /// Write the QuadratureSpace to the stream @a out.
132  void Save(std::ostream &out) const override;
133 };
134 
135 /// Class representing the storage layout of a FaceQuadratureFunction.
136 /** FaceQuadratureSpace is defined on either the interior or boundary faces
137  of a mesh, depending on the provided FaceType. */
139 {
140  FaceType face_type; ///< Is the space defined on interior or boundary faces?
141  const int num_faces; ///< Number of faces.
142 
143  /// Map from boundary or interior face indices to mesh face indices.
144  Array<int> face_indices;
145 
146  void ConstructOffsets();
147  void Construct();
148 
149 public:
150  /// Create a FaceQuadratureSpace based on the global rules from #IntRules.
151  FaceQuadratureSpace(Mesh &mesh_, int order_, FaceType face_type_);
152 
153  /// @brief Create a FaceQuadratureSpace with an IntegrationRule, valid only
154  /// when the mesh has one type of face geometry.
155  FaceQuadratureSpace(Mesh &mesh_, const IntegrationRule &ir,
156  FaceType face_type_);
157 
158  /// Returns number of faces in the mesh.
159  inline int GetNumFaces() const { return num_faces; }
160 
161  /// Returns the face type (boundary or interior).
162  FaceType GetFaceType() const { return face_type; }
163 
164  /// Returns the face transformation of face @a idx.
166  { return mesh.GetFaceTransformation(face_indices[idx]); }
167 
168  /// Returns the geometry type of face @a idx.
169  Geometry::Type GetGeometry(int idx) const override
170  { return mesh.GetFaceGeometry(face_indices[idx]); }
171 
172  /// Get the IntegrationRule associated with mesh element @a idx.
173  const IntegrationRule &GetFaceIntRule(int idx) const
174  { return *int_rule[GetGeometry(idx)]; }
175 
176  /// @brief Returns the permuted index of the @a iq quadrature point in entity
177  /// @a idx.
178  ///
179  /// For tensor-product faces, returns the lexicographic index of the
180  /// quadrature point, oriented relative to "element 1".
181  int GetPermutedIndex(int idx, int iq) const override;
182 
183  /// Write the FaceQuadratureSpace to the stream @a out.
184  void Save(std::ostream &out) const override;
185 };
186 
187 }
188 
189 #endif
ElementTransformation * GetTransformation(int idx) override
Returns the element transformation of element idx.
Definition: qspace.hpp:113
Geometry::Type GetGeometry(int idx) const override
Returns the geometry type of face idx.
Definition: qspace.hpp:169
int GetNE() const
Return the number of entities.
Definition: qspace.hpp:60
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:90
Geometry::Type GetElementBaseGeometry(int i) const
Definition: mesh.hpp:1108
static const int NumGeom
Definition: geom.hpp:42
int GetNE() const
Returns number of elements in the mesh.
Definition: qspace.hpp:110
virtual int GetPermutedIndex(int idx, int iq) const =0
Returns the permuted index of the iq quadrature point in entity idx.
Geometry::Type GetFaceGeometry(int i) const
Return the Geometry::Type associated with face i.
Definition: mesh.cpp:1413
const IntegrationRule & GetElementIntRule(int idx) const
Get the IntegrationRule associated with mesh element idx.
Definition: qspace.hpp:121
QuadratureSpaceBase(Mesh &mesh_, int order_=0)
Protected constructor. Used by derived classes.
Definition: qspace.hpp:42
int size
Total number of quadrature points.
Definition: qspace.hpp:31
int GetPermutedIndex(int idx, int iq) const override
Returns the permuted index of the iq quadrature point in entity idx.
Definition: qspace.cpp:147
virtual ElementTransformation * GetTransformation(int idx)=0
Get the (element or face) transformation of entity idx.
FaceType
Definition: mesh.hpp:45
void GetFaceTransformation(int i, IsoparametricTransformation *FTr)
Definition: mesh.cpp:497
virtual Geometry::Type GetGeometry(int idx) const =0
Return the geometry type of entity (element or face) idx.
Geometry::Type GetGeometry(int idx) const override
Returns the geometry type of element idx.
Definition: qspace.hpp:117
virtual ~QuadratureSpaceBase()
Definition: qspace.hpp:87
int GetNumFaces() const
Returns number of faces in the mesh.
Definition: qspace.hpp:159
Mesh * GetMesh() const
Returns the mesh.
Definition: qspace.hpp:63
void Save(std::ostream &out) const override
Write the QuadratureSpace to the stream out.
Definition: qspace.cpp:90
virtual void Save(std::ostream &out) const =0
Write the QuadratureSpace to the stream out.
Array< int > offsets
Entity quadrature point offset array, of size num_entities + 1.
Definition: qspace.hpp:37
Abstract base class for QuadratureSpace and FaceQuadratureSpace.
Definition: qspace.hpp:24
Geometry::Type GetElementGeometry(int i) const
Definition: mesh.hpp:1094
FaceQuadratureSpace(Mesh &mesh_, int order_, FaceType face_type_)
Create a FaceQuadratureSpace based on the global rules from IntRules.
Definition: qspace.cpp:97
const IntegrationRule & GetFaceIntRule(int idx) const
Get the IntegrationRule associated with mesh element idx.
Definition: qspace.hpp:173
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
const IntegrationRule & GetIntRule(int idx) const
Return the IntegrationRule associated with entity idx.
Definition: qspace.hpp:72
Class representing the storage layout of a FaceQuadratureFunction.
Definition: qspace.hpp:138
ElementTransformation * GetTransformation(int idx) override
Returns the face transformation of face idx.
Definition: qspace.hpp:165
int GetNE() const
Returns number of elements.
Definition: mesh.hpp:936
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: mesh.cpp:348
Mesh & mesh
The underlying mesh.
Definition: qspace.hpp:29
const IntegrationRule * int_rule[Geometry::NumGeom]
The quadrature rules used for each geometry type.
Definition: qspace.hpp:39
int GetPermutedIndex(int idx, int iq) const override
Returns the permuted index of the iq quadrature point in entity idx.
Definition: qspace.hpp:129
int dim
Definition: ex24.cpp:53
void Save(std::ostream &out) const override
Write the FaceQuadratureSpace to the stream out.
Definition: qspace.cpp:164
QuadratureSpace(Mesh *mesh_, int order_)
Create a QuadratureSpace based on the global rules from IntRules.
Definition: qspace.hpp:99
int Size() const
Return the logical size of the array.
Definition: array.hpp:141
void ConstructOffsets()
Definition: qspace.cpp:38
FaceType GetFaceType() const
Returns the face type (boundary or interior).
Definition: qspace.hpp:162
void ConstructIntRules(int dim)
Fill the int_rule array for each geometry type using order.
Definition: qspace.cpp:28
Class representing the storage layout of a QuadratureFunction.
Definition: qspace.hpp:92
int GetSize() const
Return the total number of quadrature points.
Definition: qspace.hpp:54
Represents values or vectors of values at quadrature points on a mesh.
Definition: qfunction.hpp:23
int order
The order of integration rule.
Definition: qspace.hpp:30
int GetOrder() const
Return the order of the quadrature rule(s) used by all elements.
Definition: qspace.hpp:57