Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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.
74  typedef Array<OneD, Array<OneD, Array<OneD,NekDouble> > >
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.
107  inline const Array<OneD, const NekDouble> GetJac(
108  const LibUtilities::PointsKeyVector &keyTgt);
109 
110  /// Return the Laplacian coefficients \f$g_{ij}\f$.
111  inline const Array<TwoD, const NekDouble> GetGmat(
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$.
116  inline const Array<TwoD, const NekDouble> GetDerivFactors(
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.
143  Array<OneD, Array<OneD, NekDouble> > m_coords;
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 
151  private:
152  /// Tests if the element is valid and not self-intersecting.
153  void CheckIfValid();
154 
156  const LibUtilities::PointsKeyVector &keyTgt) const;
157 
158  /// Return the Jacobian of the mapping and cache the result.
159  SPATIAL_DOMAINS_EXPORT Array<OneD, NekDouble> ComputeJac(
160  const LibUtilities::PointsKeyVector &keyTgt) const;
161 
162  /// Computes the Laplacian coefficients \f$g_{ij}\f$.
163  SPATIAL_DOMAINS_EXPORT Array<TwoD, NekDouble> ComputeGmat(
164  const LibUtilities::PointsKeyVector &keyTgt) const;
165 
166  /// Return the derivative of the reference coordinates with respect
167  /// to the mapping, \f$\frac{\partial \xi_i}{\partial \chi_j}\f$.
168  SPATIAL_DOMAINS_EXPORT Array<TwoD, NekDouble> ComputeDerivFactors(
169  const LibUtilities::PointsKeyVector &keyTgt) const;
170 
171  /// Perform interpolation of data between two point
172  /// distributions.
173  void Interp(
174  const LibUtilities::PointsKeyVector &src_points,
175  const Array<OneD, const NekDouble> &src,
176  const LibUtilities::PointsKeyVector &tgt_points,
177  Array<OneD, NekDouble> &tgt) const;
178 
179  /// Compute the transpose of the cofactors matrix
180  void Adjoint(
181  const Array<TwoD, const NekDouble>& src,
182  Array<TwoD, NekDouble>& tgt) const;
183  };
184 
185 
186  /// A hash functor for geometric factors. Utilises
187  /// GeomFactors::GetHash.
188  struct GeomFactorsHash : std::unary_function<GeomFactorsSharedPtr,
189  std::size_t>
190  {
191  std::size_t operator()(GeomFactorsSharedPtr const& p) const
192  {
193  return p->GetHash();
194  }
195  };
196 
197 
198  /**
199  * @param tpoints Target point distributions.
200  * @returns Derivative evaluated at target point
201  * distributions.
202  * @see GeomFactors::ComputeDeriv
203  */
205  const LibUtilities::PointsKeyVector &tpoints)
206  {
207  return ComputeDeriv(tpoints);
208  }
209 
210 
211  /**
212  * Returns cached value if available, otherwise computes Jacobian and
213  * stores result in cache.
214  *
215  * @param keyTgt Target point distributions.
216  * @returns Jacobian evaluated at target point
217  * distributions.
218  * @see GeomFactors::ComputeJac
219  */
220  inline const Array<OneD, const NekDouble> GeomFactors::GetJac(
221  const LibUtilities::PointsKeyVector &keyTgt)
222  {
224  Array<OneD, NekDouble> >::const_iterator x;
225 
226  if ((x = m_jacCache.find(keyTgt)) != m_jacCache.end())
227  {
228  return x->second;
229  }
230 
231  m_jacCache[keyTgt] = ComputeJac(keyTgt);
232 
233  return m_jacCache[keyTgt];
234 
235  }
236 
237 
238  /**
239  * @param keyTgt Target point distributions.
240  * @returns Inverse metric tensor evaluated at target point
241  * distributions.
242  * @see GeomFactors::ComputeGmat
243  */
244  inline const Array<TwoD, const NekDouble> GeomFactors::GetGmat(
245  const LibUtilities::PointsKeyVector &keyTgt)
246  {
247  return ComputeGmat(keyTgt);
248  }
249 
250 
251  /**
252  * Returns cached value if available, otherwise computes derivative
253  * factors and stores result in cache.
254  *
255  * @param keyTgt Target point distributions.
256  * @returns Derivative factors evaluated at target point
257  * distributions.
258  * @see GeomFactors::ComputeDerivFactors
259  */
260  inline const Array<TwoD, const NekDouble> GeomFactors::GetDerivFactors(
261  const LibUtilities::PointsKeyVector &keyTgt)
262  {
264  Array<TwoD, NekDouble> >::const_iterator x;
265 
266  if ((x = m_derivFactorCache.find(keyTgt)) != m_derivFactorCache.end())
267  {
268  return x->second;
269  }
270 
271  m_derivFactorCache[keyTgt] = ComputeDerivFactors(keyTgt);
272 
273  return m_derivFactorCache[keyTgt];
274 
275  }
276 
277 
278  /**
279  * A geometric shape is considered regular if it has constant geometric
280  * information, and deformed if this information changes throughout the
281  * shape.
282  * @returns The type of geometry.
283  * @see GeomType
284  */
286  {
287  return m_type;
288  }
289 
290 
291  /**
292  * This is greater than or equal to the expansion dimension.
293  * @returns The dimension of the coordinate system.
294  */
295  inline int GeomFactors::GetCoordim() const
296  {
297  return m_coordDim;
298  }
299 
300  /**
301  * The validity test is performed by testing if the Jacobian is
302  * negative at any point in the shape.
303  * @returns True if the element is not self-intersecting.
304  */
305  inline bool GeomFactors::IsValid() const
306  {
307  return m_valid;
308  }
309 
310  /**
311  * The hash is computed from the geometry type, expansion dimension,
312  * coordinate dimension and Jacobian.
313  * @returns Hash of this GeomFactors object.
314  */
315  inline size_t GeomFactors::GetHash()
316  {
317  LibUtilities::PointsKeyVector ptsKeys = m_xmap->GetPointsKeys();
318  const Array<OneD, const NekDouble> jac = GetJac(ptsKeys);
319 
320  size_t hash = 0;
321  boost::hash_combine(hash, (int)m_type);
322  boost::hash_combine(hash, m_expDim);
323  boost::hash_combine(hash, m_coordDim);
324  if (m_type == eDeformed)
325  {
326  boost::hash_range(hash, jac.begin(), jac.end());
327  }
328  else
329  {
330  boost::hash_combine(hash, jac[0]);
331  }
332  return hash;
333  }
334 
335 } //end of namespace
336 } //end of namespace
337 
338 #endif