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