Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Geometric Factors base class
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_SPATIALDOMAINS_GEOMFACTORS_H
37 #define NEKTAR_SPATIALDOMAINS_GEOMFACTORS_H
38 
39 #include <boost/unordered_set.hpp>
40 
46 
47 namespace Nektar
48 {
49 namespace SpatialDomains
50 {
51  // Forward declarations
52  class GeomFactors;
53  class Geometry;
54 
55  typedef boost::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 boost::shared_ptr<GeomFactors> GeomFactorsSharedPtr;
63  /// A vector of GeomFactor pointers.
64  typedef std::vector< GeomFactorsSharedPtr > GeomFactorsVector;
65  /// Iterator for the GeomFactorsVector.
67  /// An unordered set of GeomFactor pointers.
68  typedef boost::unordered_set< GeomFactorsSharedPtr >
70  /// Iterator for the GeomFactorsSet
73  /// Storage type for derivative of mapping.
76 
77  /// Calculation and storage of geometric factors associated with the
78  /// mapping from StdRegions reference elements to a given LocalRegions
79  /// physical element in the mesh.
81  {
82  public:
83  /// Constructor for GeomFactors class.
84  GeomFactors(const GeomType gtype,
85  const int coordim,
87  const Array<OneD, Array<OneD, NekDouble> > &coords);
88 
89  /// Copy constructor.
90  GeomFactors(const GeomFactors &S);
91 
92  /// Tests if two GeomFactors classes are equal.
94  const GeomFactors &lhs,
95  const GeomFactors &rhs);
96 
97  /// Destructor.
99 
100  /// Return the derivative of the mapping with respect to the
101  /// reference coordinates,
102  /// \f$\frac{\partial \chi_i}{\partial \xi_j}\f$.
103  inline DerivStorage GetDeriv(
104  const LibUtilities::PointsKeyVector &keyTgt);
105 
106  /// Return the Jacobian of the mapping and cache the result.
108  const LibUtilities::PointsKeyVector &keyTgt);
109 
110  /// Return the Laplacian coefficients \f$g_{ij}\f$.
112  const LibUtilities::PointsKeyVector &keyTgt);
113 
114  /// Return the derivative of the reference coordinates with respect
115  /// to the mapping, \f$\frac{\partial \xi_i}{\partial \chi_j}\f$.
117  const LibUtilities::PointsKeyVector &keyTgt);
118 
119  /// Returns whether the geometry is regular or deformed.
120  inline GeomType GetGtype();
121 
122  /// Determine if element is valid and not self-intersecting.
123  inline bool IsValid() const;
124 
125  /// Return the number of dimensions of the coordinate system.
126  inline int GetCoordim() const;
127 
128  /// Computes a hash of this GeomFactors element.
129  inline size_t GetHash();
130 
131  protected:
132  /// Type of geometry (e.g. eRegular, eDeformed, eMovingRegular).
134  /// Dimension of expansion.
135  int m_expDim;
136  /// Dimension of coordinate system.
138  /// Validity of element (Jacobian positive)
139  bool m_valid;
140  /// Stores information about the expansion.
142  /// Stores coordinates of the geometry.
144  /// Jacobian vector cache
145  std::map<LibUtilities::PointsKeyVector, Array<OneD, NekDouble> >
147  /// DerivFactors vector cache
148  std::map<LibUtilities::PointsKeyVector, Array<TwoD, NekDouble> >
150  /// Return the Xmap;
152 
153  private:
154  /// Tests if the element is valid and not self-intersecting.
155  void CheckIfValid();
156 
158  const LibUtilities::PointsKeyVector &keyTgt) const;
159 
160  /// Return the Jacobian of the mapping and cache the result.
162  const LibUtilities::PointsKeyVector &keyTgt) const;
163 
164  /// Computes the Laplacian coefficients \f$g_{ij}\f$.
166  const LibUtilities::PointsKeyVector &keyTgt) const;
167 
168  /// Return the derivative of the reference coordinates with respect
169  /// to the mapping, \f$\frac{\partial \xi_i}{\partial \chi_j}\f$.
171  const LibUtilities::PointsKeyVector &keyTgt) const;
172 
173  /// Perform interpolation of data between two point
174  /// distributions.
175  void Interp(
176  const LibUtilities::PointsKeyVector &src_points,
177  const Array<OneD, const NekDouble> &src,
178  const LibUtilities::PointsKeyVector &tgt_points,
179  Array<OneD, NekDouble> &tgt) const;
180 
181  /// Compute the transpose of the cofactors matrix
182  void Adjoint(
183  const Array<TwoD, const NekDouble>& src,
184  Array<TwoD, NekDouble>& tgt) const;
185 
186  };
187 
188 
189  /// A hash functor for geometric factors. Utilises
190  /// GeomFactors::GetHash.
191  struct GeomFactorsHash : std::unary_function<GeomFactorsSharedPtr,
192  std::size_t>
193  {
194  std::size_t operator()(GeomFactorsSharedPtr const& p) const
195  {
196  return p->GetHash();
197  }
198  };
199 
200 
201  /**
202  * @param tpoints Target point distributions.
203  * @returns Derivative evaluated at target point
204  * distributions.
205  * @see GeomFactors::ComputeDeriv
206  */
208  const LibUtilities::PointsKeyVector &tpoints)
209  {
210  return ComputeDeriv(tpoints);
211  }
212 
213 
214  /**
215  * Returns cached value if available, otherwise computes Jacobian and
216  * stores result in cache.
217  *
218  * @param keyTgt Target point distributions.
219  * @returns Jacobian evaluated at target point
220  * distributions.
221  * @see GeomFactors::ComputeJac
222  */
224  const LibUtilities::PointsKeyVector &keyTgt)
225  {
227  Array<OneD, NekDouble> >::const_iterator x;
228 
229  if ((x = m_jacCache.find(keyTgt)) != m_jacCache.end())
230  {
231  return x->second;
232  }
233 
234  m_jacCache[keyTgt] = ComputeJac(keyTgt);
235 
236  return m_jacCache[keyTgt];
237 
238  }
239 
240  /**
241  * @param keyTgt Target point distributions.
242  * @returns Inverse metric tensor evaluated at target point
243  * distributions.
244  * @see GeomFactors::ComputeGmat
245  */
247  const LibUtilities::PointsKeyVector &keyTgt)
248  {
249  return ComputeGmat(keyTgt);
250  }
251 
252 
253  /**
254  * Returns cached value if available, otherwise computes derivative
255  * factors and stores result in cache.
256  *
257  * @param keyTgt Target point distributions.
258  * @returns Derivative factors evaluated at target point
259  * distributions.
260  * @see GeomFactors::ComputeDerivFactors
261  */
263  const LibUtilities::PointsKeyVector &keyTgt)
264  {
266  Array<TwoD, NekDouble> >::const_iterator x;
267 
268  if ((x = m_derivFactorCache.find(keyTgt)) != m_derivFactorCache.end())
269  {
270  return x->second;
271  }
272 
273  m_derivFactorCache[keyTgt] = ComputeDerivFactors(keyTgt);
274 
275  return m_derivFactorCache[keyTgt];
276 
277  }
278 
279 
280  /**
281  * A geometric shape is considered regular if it has constant geometric
282  * information, and deformed if this information changes throughout the
283  * shape.
284  * @returns The type of geometry.
285  * @see GeomType
286  */
288  {
289  return m_type;
290  }
291 
292 
293  /**
294  * This is greater than or equal to the expansion dimension.
295  * @returns The dimension of the coordinate system.
296  */
297  inline int GeomFactors::GetCoordim() const
298  {
299  return m_coordDim;
300  }
301 
302  /**
303  * The validity test is performed by testing if the Jacobian is
304  * negative at any point in the shape.
305  * @returns True if the element is not self-intersecting.
306  */
307  inline bool GeomFactors::IsValid() const
308  {
309  return m_valid;
310  }
311 
312  /**
313  * The hash is computed from the geometry type, expansion dimension,
314  * coordinate dimension and Jacobian.
315  * @returns Hash of this GeomFactors object.
316  */
317  inline size_t GeomFactors::GetHash()
318  {
319  LibUtilities::PointsKeyVector ptsKeys = m_xmap->GetPointsKeys();
320  const Array<OneD, const NekDouble> jac = GetJac(ptsKeys);
321 
322  size_t hash = 0;
323  boost::hash_combine(hash, (int)m_type);
324  boost::hash_combine(hash, m_expDim);
325  boost::hash_combine(hash, m_coordDim);
326  if (m_type == eDeformed)
327  {
328  boost::hash_range(hash, jac.begin(), jac.end());
329  }
330  else
331  {
332  boost::hash_combine(hash, jac[0]);
333  }
334  return hash;
335  }
336 
338  {
339  return m_xmap;
340  }
341 
342 } //end of namespace
343 } //end of namespace
344 
345 #endif
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:262
GeomFactorsVector::iterator GeomFactorsVectorIter
Iterator for the GeomFactorsVector.
Definition: GeomFactors.h:66
Array< OneD, NekDouble > ComputeJac(const LibUtilities::PointsKeyVector &keyTgt) const
Return the Jacobian of the mapping and cache the result.
void Adjoint(const Array< TwoD, const NekDouble > &src, Array< TwoD, NekDouble > &tgt) const
Compute the transpose of the cofactors matrix.
bool IsValid() const
Determine if element is valid and not self-intersecting.
Definition: GeomFactors.h:307
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:242
boost::unordered_set< GeomFactorsSharedPtr >::iterator GeomFactorsSetIter
Iterator for the GeomFactorsSet.
Definition: GeomFactors.h:72
GeomType m_type
Type of geometry (e.g. eRegular, eDeformed, eMovingRegular).
Definition: GeomFactors.h:133
friend bool operator==(const GeomFactors &lhs, const GeomFactors &rhs)
Tests if two GeomFactors classes are equal.
GeomType GetGtype()
Returns whether the geometry is regular or deformed.
Definition: GeomFactors.h:287
DerivStorage GetDeriv(const LibUtilities::PointsKeyVector &keyTgt)
Return the derivative of the mapping with respect to the reference coordinates, . ...
Definition: GeomFactors.h:207
size_t GetHash()
Computes a hash of this GeomFactors element.
Definition: GeomFactors.h:317
boost::unordered_set< GeomFactorsSharedPtr > GeomFactorsSet
An unordered set of GeomFactor pointers.
Definition: GeomFactors.h:69
void CheckIfValid()
Tests if the element is valid and not self-intersecting.
StandardMatrixTag & lhs
int m_coordDim
Dimension of coordinate system.
Definition: GeomFactors.h:137
std::map< LibUtilities::PointsKeyVector, Array< OneD, NekDouble > > m_jacCache
Jacobian vector cache.
Definition: GeomFactors.h:146
Array< TwoD, NekDouble > ComputeGmat(const LibUtilities::PointsKeyVector &keyTgt) const
Computes the Laplacian coefficients .
const Array< TwoD, const NekDouble > GetGmat(const LibUtilities::PointsKeyVector &keyTgt)
Return the Laplacian coefficients .
Definition: GeomFactors.h:246
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > DerivStorage
Storage type for derivative of mapping.
Definition: GeomFactors.h:75
bool m_valid
Validity of element (Jacobian positive)
Definition: GeomFactors.h:139
StdRegions::StdExpansionSharedPtr & GetXmap()
Return the Xmap;.
Definition: GeomFactors.h:337
std::vector< GeomFactorsSharedPtr > GeomFactorsVector
A vector of GeomFactor pointers.
Definition: GeomFactors.h:64
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.
std::size_t operator()(GeomFactorsSharedPtr const &p) const
Definition: GeomFactors.h:194
const Array< OneD, const NekDouble > GetJac(const LibUtilities::PointsKeyVector &keyTgt)
Return the Jacobian of the mapping and cache the result.
Definition: GeomFactors.h:223
A hash functor for geometric factors. Utilises GeomFactors::GetHash.
Definition: GeomFactors.h:191
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
int GetCoordim() const
Return the number of dimensions of the coordinate system.
Definition: GeomFactors.h:297
int m_expDim
Dimension of expansion.
Definition: GeomFactors.h:135
Calculation and storage of geometric factors associated with the mapping from StdRegions reference el...
Definition: GeomFactors.h:80
boost::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:62
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:89
bool operator==(const GeomFactors &lhs, const GeomFactors &rhs)
Equivalence test for GeomFactors objects.
Array< TwoD, NekDouble > ComputeDerivFactors(const LibUtilities::PointsKeyVector &keyTgt) const
Return the derivative of the reference coordinates with respect to the mapping, . ...
Array< OneD, Array< OneD, NekDouble > > m_coords
Stores coordinates of the geometry.
Definition: GeomFactors.h:143
StdRegions::StdExpansionSharedPtr m_xmap
Stores information about the expansion.
Definition: GeomFactors.h:141
GeomType
Indicates the type of element geometry.
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
Geometry is curved or has non-constant factors.
boost::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
DerivStorage ComputeDeriv(const LibUtilities::PointsKeyVector &keyTgt) const
#define SPATIAL_DOMAINS_EXPORT
std::map< LibUtilities::PointsKeyVector, Array< TwoD, NekDouble > > m_derivFactorCache
DerivFactors vector cache.
Definition: GeomFactors.h:149