Nektar++
Loading...
Searching...
No Matches
GeomFactors.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: GeomFactors.h
4//
5// For more information, please see: http://www.nektar.info/
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Geometric Factors base class
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_SPATIALDOMAINS_GEOMFACTORS_H
36#define NEKTAR_SPATIALDOMAINS_GEOMFACTORS_H
37
38#include <unordered_set>
39
47
49{
50// Forward declarations
51class GeomFactors;
52
53/// Equivalence test for GeomFactors objects
54SPATIAL_DOMAINS_EXPORT bool operator==(const GeomFactors &lhs,
55 const GeomFactors &rhs);
56
57/// A vector of GeomFactor pointers.
58typedef std::vector<GeomFactors *> GeomFactorsVector;
59/// An unordered set of GeomFactor pointers.
60typedef std::unordered_set<GeomFactors *> GeomFactorsSet;
61/// Storage type for derivative of mapping.
63
64/// Calculation and storage of geometric factors associated with the
65/// mapping from StdRegions reference elements to a given LocalRegions
66/// physical element in the mesh.
68{
69public:
70 /// Constructor for GeomFactors class.
72 const GeomType gtype, const int coordim,
74 const std::vector<Array<OneD, NekDouble>> &coords,
75 const LibUtilities::PointsKeyVector &keyTgt);
76
77 /// Copy constructor.
79
80 /// Tests if two GeomFactors classes are equal.
81 SPATIAL_DOMAINS_EXPORT friend bool operator==(const GeomFactors &lhs,
82 const GeomFactors &rhs);
83
84 /// Destructor.
86
87 /// Return the derivative of the mapping with respect to the
88 /// reference coordinates,
89 /// \f$\frac{\partial \chi_i}{\partial \xi_j}\f$.
91
92 /// Return the Jacobian of the mapping.
94 /// Compute the Jacobian of the mapping.
96 const LibUtilities::PointsKeyVector &keyTgt) const;
97
98 /// Return the Laplacian coefficients \f$g_{ij}\f$.
100 const LibUtilities::PointsKeyVector &keyTgt);
101
102 /// Return the derivative of the reference coordinates with respect
103 /// to the mapping, \f$\frac{\partial \xi_i}{\partial \chi_j}\f$.
105 /// Compute the derivative of the reference coordinates with respect
106 /// to the mapping, \f$\frac{\partial \xi_i}{\partial \chi_j}\f$.
108 const LibUtilities::PointsKeyVector &keyTgt) const;
109
110 /// Returns moving frames
111 inline void GetMovingFrames(const LibUtilities::PointsKeyVector &keyTgt,
112 const SpatialDomains::GeomMMF MMFdir,
113 const Array<OneD, const NekDouble> &CircCentre,
114 Array<OneD, Array<OneD, NekDouble>> &outarray);
115
116 /// Returns whether the geometry is regular or deformed.
117 inline GeomType GetGtype();
118
119 /// Determine if element is valid and not self-intersecting.
120 inline bool IsValid() const;
121
122 /// Return the number of dimensions of the coordinate system.
123 inline int GetCoordim() const;
124
125 /// Computes a hash of this GeomFactors element.
126 inline size_t GetHash();
127
128protected:
129 /// Type of geometry (e.g. eRegular, eDeformed, eMovingRegular).
131 /// Dimension of expansion.
133 /// Dimension of coordinate system.
135 /// Validity of element (Jacobian positive)
137 /// Default points at which to compute jacobian and derivative factors
139
140 /// Principle tangent direction for MMF.
142
143 /// Stores information about the expansion.
145 /// Stores coordinates of the geometry.
146 std::vector<Array<OneD, NekDouble>> m_coords;
147 /// Jacobian vector
149 /// DerivFactors vector
151 /// Indicates whether stored jacobian has been populated
152 bool m_jacComputed = false;
153 /// Indicates whether stored derivative factors have been populated
154 bool m_derivFacComputed = false;
155 /// Return the Xmap;
157
158private:
159 /// Tests if the element is valid and not self-intersecting.
160 void CheckIfValid();
161
163 ComputeDeriv(const LibUtilities::PointsKeyVector &keyTgt) const;
164
165 /// Computes the Laplacian coefficients \f$g_{ij}\f$.
167 const LibUtilities::PointsKeyVector &keyTgt) const;
168
170 const LibUtilities::PointsKeyVector &keyTgt,
171 const SpatialDomains::GeomMMF MMFdir,
172 const Array<OneD, const NekDouble> &CircCentre,
173 Array<OneD, Array<OneD, NekDouble>> &movingframes);
174
175 /// Perform interpolation of data between two point
176 /// distributions.
177 void Interp(const LibUtilities::PointsKeyVector &src_points,
179 const LibUtilities::PointsKeyVector &tgt_points,
180 Array<OneD, NekDouble> &tgt) const;
181
182 /// Compute the transpose of the cofactors matrix
184 Array<TwoD, NekDouble> &tgt) const;
185
187 const LibUtilities::PointsKeyVector &keyTgt,
188 const SpatialDomains::GeomMMF MMFdir,
189 const Array<OneD, const NekDouble> &CircCentre,
191
193
194 void VectorCrossProd(const Array<OneD, const Array<OneD, NekDouble>> &v1,
195 const Array<OneD, const Array<OneD, NekDouble>> &v2,
197};
198
199/// A hash functor for geometric factors. Utilises
200/// GeomFactors::GetHash.
202{
203 std::size_t operator()(GeomFactors *const &p) const
204 {
205 return p->GetHash();
206 }
207};
208
209/**
210 * @param tpoints Target point distributions.
211 * @returns Derivative evaluated at target point
212 * distributions.
213 * @see GeomFactors::ComputeDeriv
214 */
216 const LibUtilities::PointsKeyVector &tpoints)
217{
218 return ComputeDeriv(tpoints);
219}
220
221/**
222 * Returns Jacobian.
223 *
224 * @returns Jacobian evaluated at target point
225 * distributions.
226 * @see GeomFactors::ComputeJac
227 */
229{
230 if (!m_jacComputed)
231 {
233 m_jacComputed = true;
234 }
235 return m_jac;
236}
237
238/**
239 * @param keyTgt Target point distributions.
240 * @returns Inverse metric tensor evaluated at target point
241 * distributions.
242 * @see GeomFactors::ComputeGmat
243 */
245 const LibUtilities::PointsKeyVector &keyTgt)
246{
247 return ComputeGmat(keyTgt);
248}
249
250/**
251 * Returns derivative factors.
252 *
253 * @returns Derivative factors evaluated at target point
254 * distributions.
255 * @see GeomFactors::ComputeDerivFactors
256 */
266
268 const LibUtilities::PointsKeyVector &keyTgt,
269 const SpatialDomains::GeomMMF MMFdir,
270 const Array<OneD, const NekDouble> &CircCentre,
272{
273 ComputeMovingFrames(keyTgt, MMFdir, CircCentre, outarray);
274}
275
276/**
277 * A geometric shape is considered regular if it has constant geometric
278 * information, and deformed if this information changes throughout the
279 * shape.
280 * @returns The type of geometry.
281 * @see GeomType
282 */
284{
285 return m_type;
286}
287
288/**
289 * This is greater than or equal to the expansion dimension.
290 * @returns The dimension of the coordinate system.
291 */
292inline int GeomFactors::GetCoordim() const
293{
294 return m_coordDim;
295}
296
297/**
298 * The validity test is performed by testing if the Jacobian is
299 * negative at any point in the shape.
300 * @returns True if the element is not self-intersecting.
301 */
302inline bool GeomFactors::IsValid() const
303{
304 return m_valid;
305}
306
307/**
308 * The hash is computed from the geometry type, expansion dimension,
309 * coordinate dimension and Jacobian.
310 * @returns Hash of this GeomFactors object.
311 */
312inline size_t GeomFactors::GetHash()
313{
314 LibUtilities::PointsKeyVector ptsKeys = m_xmap->GetPointsKeys();
315 const Array<OneD, const NekDouble> jac = ComputeJac(ptsKeys);
316
317 size_t hash = 0;
319 if (m_type == eDeformed)
320 {
321 hash_range(hash, jac.begin(), jac.end());
322 }
323 else
324 {
325 hash_combine(hash, jac[0]);
326 }
327 return hash;
328}
329
334
335} // namespace Nektar::SpatialDomains
336
337#endif
#define SPATIAL_DOMAINS_EXPORT
Calculation and storage of geometric factors associated with the mapping from StdRegions reference el...
Definition GeomFactors.h:68
DerivStorage ComputeDeriv(const LibUtilities::PointsKeyVector &keyTgt) const
bool IsValid() const
Determine if element is valid and not self-intersecting.
Array< TwoD, NekDouble > ComputeDerivFactors(const LibUtilities::PointsKeyVector &keyTgt) const
Compute the derivative of the reference coordinates with respect to the mapping, .
enum GeomMMF m_MMFDir
Principle tangent direction for MMF.
void Adjoint(const Array< TwoD, const NekDouble > &src, Array< TwoD, NekDouble > &tgt) const
Compute the transpose of the cofactors matrix.
int m_coordDim
Dimension of coordinate system.
LibUtilities::PointsKeyVector m_keyTgt
Default points at which to compute jacobian and derivative factors.
Array< OneD, NekDouble > m_jac
Jacobian vector.
void CheckIfValid()
Tests if the element is valid and not self-intersecting.
const Array< OneD, const NekDouble > GetJac()
Return the Jacobian of the mapping.
void Interp(const LibUtilities::PointsKeyVector &src_points, const Array< OneD, const NekDouble > &src, const LibUtilities::PointsKeyVector &tgt_points, Array< OneD, NekDouble > &tgt) const
Perform interpolation of data between two point distributions.
Array< OneD, NekDouble > ComputeJac(const LibUtilities::PointsKeyVector &keyTgt) const
Compute the Jacobian of the mapping.
int m_expDim
Dimension of expansion.
Array< TwoD, NekDouble > ComputeGmat(const LibUtilities::PointsKeyVector &keyTgt) const
Computes the Laplacian coefficients .
void ComputePrincipleDirection(const LibUtilities::PointsKeyVector &keyTgt, const SpatialDomains::GeomMMF MMFdir, const Array< OneD, const NekDouble > &CircCentre, Array< OneD, Array< OneD, NekDouble > > &output)
friend bool operator==(const GeomFactors &lhs, const GeomFactors &rhs)
Tests if two GeomFactors classes are equal.
bool m_valid
Validity of element (Jacobian positive)
StdRegions::StdExpansionSharedPtr m_xmap
Stores information about the expansion.
~GeomFactors()=default
Destructor.
Array< TwoD, NekDouble > m_derivFactor
DerivFactors vector.
bool m_jacComputed
Indicates whether stored jacobian has been populated.
void GetMovingFrames(const LibUtilities::PointsKeyVector &keyTgt, const SpatialDomains::GeomMMF MMFdir, const Array< OneD, const NekDouble > &CircCentre, Array< OneD, Array< OneD, NekDouble > > &outarray)
Returns moving frames.
StdRegions::StdExpansionSharedPtr & GetXmap()
Return the Xmap;.
DerivStorage GetDeriv(const LibUtilities::PointsKeyVector &keyTgt)
Return the derivative of the mapping with respect to the reference coordinates, .
GeomType m_type
Type of geometry (e.g. eRegular, eDeformed, eMovingRegular).
std::vector< Array< OneD, NekDouble > > m_coords
Stores coordinates of the geometry.
int GetCoordim() const
Return the number of dimensions of the coordinate system.
bool m_derivFacComputed
Indicates whether stored derivative factors have been populated.
size_t GetHash()
Computes a hash of this GeomFactors element.
const Array< TwoD, const NekDouble > GetGmat(const LibUtilities::PointsKeyVector &keyTgt)
Return the Laplacian coefficients .
void ComputeMovingFrames(const LibUtilities::PointsKeyVector &keyTgt, const SpatialDomains::GeomMMF MMFdir, const Array< OneD, const NekDouble > &CircCentre, Array< OneD, Array< OneD, NekDouble > > &movingframes)
const Array< TwoD, const NekDouble > GetDerivFactors()
Return the derivative of the reference coordinates with respect to the mapping, .
void VectorNormalise(Array< OneD, Array< OneD, NekDouble > > &array)
void VectorCrossProd(const Array< OneD, const Array< OneD, NekDouble > > &v1, const Array< OneD, const Array< OneD, NekDouble > > &v2, Array< OneD, Array< OneD, NekDouble > > &v3)
Computes the vector cross-product in 3D of v1 and v2, storing the result in v3.
GeomType GetGtype()
Returns whether the geometry is regular or deformed.
std::vector< PointsKey > PointsKeyVector
Definition Points.h:313
GeomMMF
Principle direction for MMF.
bool operator==(const GeomFactors &lhs, const GeomFactors &rhs)
Equivalence test for GeomFactors objects.
GeomType
Indicates the type of element geometry.
@ eDeformed
Geometry is curved or has non-constant factors.
std::unordered_set< GeomFactors * > GeomFactorsSet
An unordered set of GeomFactor pointers.
Definition GeomFactors.h:60
std::vector< GeomFactors * > GeomFactorsVector
A vector of GeomFactor pointers.
Definition GeomFactors.h:58
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > DerivStorage
Storage type for derivative of mapping.
Definition GeomFactors.h:62
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
std::size_t hash_range(Iter first, Iter last)
Definition HashUtils.hpp:64
void hash_combine(std::size_t &seed)
Definition HashUtils.hpp:44
A hash functor for geometric factors. Utilises GeomFactors::GetHash.
std::size_t operator()(GeomFactors *const &p) const