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/// Pointer to a GeomFactors object.
58typedef std::shared_ptr<GeomFactors> GeomFactorsSharedPtr;
59/// A vector of GeomFactor pointers.
60typedef std::vector<GeomFactorsSharedPtr> GeomFactorsVector;
61/// An unordered set of GeomFactor pointers.
62typedef std::unordered_set<GeomFactorsSharedPtr> GeomFactorsSet;
63/// Storage type for derivative of mapping.
65
66/// Calculation and storage of geometric factors associated with the
67/// mapping from StdRegions reference elements to a given LocalRegions
68/// physical element in the mesh.
70{
71public:
72 /// Constructor for GeomFactors class.
73 GeomFactors(const GeomType gtype, const int coordim,
75 const Array<OneD, Array<OneD, NekDouble>> &coords);
76
77 /// Copy constructor.
78 GeomFactors(const GeomFactors &S);
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 and cache the result.
94 const LibUtilities::PointsKeyVector &keyTgt);
95
96 /// Return the Laplacian coefficients \f$g_{ij}\f$.
98 const LibUtilities::PointsKeyVector &keyTgt);
99
100 /// Return the derivative of the reference coordinates with respect
101 /// to the mapping, \f$\frac{\partial \xi_i}{\partial \chi_j}\f$.
103 const LibUtilities::PointsKeyVector &keyTgt);
104
105 /// Returns moving frames
106 inline void GetMovingFrames(const LibUtilities::PointsKeyVector &keyTgt,
107 const SpatialDomains::GeomMMF MMFdir,
108 const Array<OneD, const NekDouble> &CircCentre,
109 Array<OneD, Array<OneD, NekDouble>> &outarray);
110
111 /// Returns whether the geometry is regular or deformed.
112 inline GeomType GetGtype();
113
114 /// Determine if element is valid and not self-intersecting.
115 inline bool IsValid() const;
116
117 /// Return the number of dimensions of the coordinate system.
118 inline int GetCoordim() const;
119
120 /// Computes a hash of this GeomFactors element.
121 inline size_t GetHash();
122
123protected:
124 /// Type of geometry (e.g. eRegular, eDeformed, eMovingRegular).
126 /// Dimension of expansion.
128 /// Dimension of coordinate system.
130 /// Validity of element (Jacobian positive)
132
133 /// Principle tangent direction for MMF.
135
136 /// Stores information about the expansion.
138 /// Stores coordinates of the geometry.
140 /// Jacobian vector cache
141 std::map<LibUtilities::PointsKeyVector, Array<OneD, NekDouble>> m_jacCache;
142 /// DerivFactors vector cache
143 std::map<LibUtilities::PointsKeyVector, Array<TwoD, NekDouble>>
145 /// Return the Xmap;
147
148private:
149 /// Tests if the element is valid and not self-intersecting.
150 void CheckIfValid();
151
153 ComputeDeriv(const LibUtilities::PointsKeyVector &keyTgt) const;
154
155 /// Return the Jacobian of the mapping and cache the result.
157 const LibUtilities::PointsKeyVector &keyTgt) const;
158
159 /// Computes the Laplacian coefficients \f$g_{ij}\f$.
161 const LibUtilities::PointsKeyVector &keyTgt) const;
162
163 /// Return the derivative of the reference coordinates with respect
164 /// to the mapping, \f$\frac{\partial \xi_i}{\partial \chi_j}\f$.
166 const LibUtilities::PointsKeyVector &keyTgt) const;
167
169 const LibUtilities::PointsKeyVector &keyTgt,
170 const SpatialDomains::GeomMMF MMFdir,
171 const Array<OneD, const NekDouble> &CircCentre,
172 Array<OneD, Array<OneD, NekDouble>> &movingframes);
173
174 /// Perform interpolation of data between two point
175 /// distributions.
176 void Interp(const LibUtilities::PointsKeyVector &src_points,
178 const LibUtilities::PointsKeyVector &tgt_points,
179 Array<OneD, NekDouble> &tgt) const;
180
181 /// Compute the transpose of the cofactors matrix
183 Array<TwoD, NekDouble> &tgt) const;
184
186 const LibUtilities::PointsKeyVector &keyTgt,
187 const SpatialDomains::GeomMMF MMFdir,
188 const Array<OneD, const NekDouble> &CircCentre,
190
192
193 void VectorCrossProd(const Array<OneD, const Array<OneD, NekDouble>> &v1,
194 const Array<OneD, const Array<OneD, NekDouble>> &v2,
196};
197
198/// A hash functor for geometric factors. Utilises
199/// GeomFactors::GetHash.
201{
202 std::size_t operator()(GeomFactorsSharedPtr const &p) const
203 {
204 return p->GetHash();
205 }
206};
207
208/**
209 * @param tpoints Target point distributions.
210 * @returns Derivative evaluated at target point
211 * distributions.
212 * @see GeomFactors::ComputeDeriv
213 */
215 const LibUtilities::PointsKeyVector &tpoints)
216{
217 return ComputeDeriv(tpoints);
218}
219
220/**
221 * Returns cached value if available, otherwise computes Jacobian and
222 * stores result in cache.
223 *
224 * @param keyTgt Target point distributions.
225 * @returns Jacobian evaluated at target point
226 * distributions.
227 * @see GeomFactors::ComputeJac
228 */
230 const LibUtilities::PointsKeyVector &keyTgt)
231{
232 auto x = m_jacCache.find(keyTgt);
233
234 if (x != m_jacCache.end())
235 {
236 return x->second;
237 }
238
239 m_jacCache[keyTgt] = ComputeJac(keyTgt);
240
241 return m_jacCache[keyTgt];
242}
243
244/**
245 * @param keyTgt Target point distributions.
246 * @returns Inverse metric tensor evaluated at target point
247 * distributions.
248 * @see GeomFactors::ComputeGmat
249 */
251 const LibUtilities::PointsKeyVector &keyTgt)
252{
253 return ComputeGmat(keyTgt);
254}
255
256/**
257 * Returns cached value if available, otherwise computes derivative
258 * factors and stores result in cache.
259 *
260 * @param keyTgt Target point distributions.
261 * @returns Derivative factors evaluated at target point
262 * distributions.
263 * @see GeomFactors::ComputeDerivFactors
264 */
266 const LibUtilities::PointsKeyVector &keyTgt)
267{
268 auto x = m_derivFactorCache.find(keyTgt);
269
270 if (x != m_derivFactorCache.end())
271 {
272 return x->second;
273 }
274
275 m_derivFactorCache[keyTgt] = ComputeDerivFactors(keyTgt);
276
277 return m_derivFactorCache[keyTgt];
278}
279
281 const LibUtilities::PointsKeyVector &keyTgt,
282 const SpatialDomains::GeomMMF MMFdir,
283 const Array<OneD, const NekDouble> &CircCentre,
285{
286 ComputeMovingFrames(keyTgt, MMFdir, CircCentre, outarray);
287}
288
289/**
290 * A geometric shape is considered regular if it has constant geometric
291 * information, and deformed if this information changes throughout the
292 * shape.
293 * @returns The type of geometry.
294 * @see GeomType
295 */
297{
298 return m_type;
299}
300
301/**
302 * This is greater than or equal to the expansion dimension.
303 * @returns The dimension of the coordinate system.
304 */
305inline int GeomFactors::GetCoordim() const
306{
307 return m_coordDim;
308}
309
310/**
311 * The validity test is performed by testing if the Jacobian is
312 * negative at any point in the shape.
313 * @returns True if the element is not self-intersecting.
314 */
315inline bool GeomFactors::IsValid() const
316{
317 return m_valid;
318}
319
320/**
321 * The hash is computed from the geometry type, expansion dimension,
322 * coordinate dimension and Jacobian.
323 * @returns Hash of this GeomFactors object.
324 */
325inline size_t GeomFactors::GetHash()
326{
327 LibUtilities::PointsKeyVector ptsKeys = m_xmap->GetPointsKeys();
328 const Array<OneD, const NekDouble> jac = GetJac(ptsKeys);
329
330 size_t hash = 0;
332 if (m_type == eDeformed)
333 {
334 hash_range(hash, jac.begin(), jac.end());
335 }
336 else
337 {
338 hash_combine(hash, jac[0]);
339 }
340 return hash;
341}
342
347
348} // namespace Nektar::SpatialDomains
349
350#endif
#define SPATIAL_DOMAINS_EXPORT
Calculation and storage of geometric factors associated with the mapping from StdRegions reference el...
Definition GeomFactors.h:70
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
Return 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.
const Array< OneD, const NekDouble > GetJac(const LibUtilities::PointsKeyVector &keyTgt)
Return the Jacobian of the mapping and cache the result.
const Array< TwoD, const NekDouble > GetDerivFactors(const LibUtilities::PointsKeyVector &keyTgt)
Return the derivative of the reference coordinates with respect to the mapping, .
int m_coordDim
Dimension of coordinate system.
void CheckIfValid()
Tests if the element is valid and not self-intersecting.
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
Return the Jacobian of the mapping and cache the result.
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.
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.
std::map< LibUtilities::PointsKeyVector, Array< TwoD, NekDouble > > m_derivFactorCache
DerivFactors vector cache.
std::map< LibUtilities::PointsKeyVector, Array< OneD, NekDouble > > m_jacCache
Jacobian vector cache.
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).
int GetCoordim() const
Return the number of dimensions of the coordinate system.
size_t GetHash()
Computes a hash of this GeomFactors element.
Array< OneD, Array< OneD, NekDouble > > m_coords
Stores coordinates of the geometry.
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)
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:231
std::vector< GeomFactorsSharedPtr > GeomFactorsVector
A vector of GeomFactor pointers.
Definition GeomFactors.h:60
std::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition GeomFactors.h:58
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< GeomFactorsSharedPtr > GeomFactorsSet
An unordered set of GeomFactor pointers.
Definition GeomFactors.h:62
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > DerivStorage
Storage type for derivative of mapping.
Definition GeomFactors.h:64
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()(GeomFactorsSharedPtr const &p) const