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