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