Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Geometry.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Geometry.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: This file contains the base class specification for the
33 // Geometry class.
34 //
35 //
36 ////////////////////////////////////////////////////////////////////////////////
37 #ifndef NEKTAR_SPATIALDOMAINS_GEOMETRY_H
38 #define NEKTAR_SPATIALDOMAINS_GEOMETRY_H
39 
42 
43 #include <boost/unordered_set.hpp>
44 #include <boost/functional/hash.hpp>
45 #include <boost/shared_ptr.hpp>
47 
48 namespace Nektar
49 {
50  namespace SpatialDomains
51  {
52  class Geometry; // Forward declaration for typedef.
53  typedef boost::shared_ptr<Geometry> GeometrySharedPtr;
54  typedef std::vector< GeometrySharedPtr > GeometryVector;
55  typedef boost::unordered_set< GeometrySharedPtr > GeometrySet;
56  typedef boost::shared_ptr <GeometryVector> GeometryVectorSharedPtr;
58 
59  class PointGeom;
60  typedef boost::shared_ptr< PointGeom > PointGeomSharedPtr;
61 
62  /// \brief Less than operator to sort Geometry objects by global id when sorting
63  /// STL containers.
64  SPATIAL_DOMAINS_EXPORT bool SortByGlobalId(const boost::shared_ptr<Geometry>& lhs,
65  const boost::shared_ptr<Geometry>& rhs);
66 
67  SPATIAL_DOMAINS_EXPORT bool GlobalIdEquality(const boost::shared_ptr<Geometry>& lhs,
68  const boost::shared_ptr<Geometry>& rhs);
69 
70  /// Base class for shape geometry information
71  class Geometry
72  {
73  public:
75  SPATIAL_DOMAINS_EXPORT Geometry(int coordim);
76 
78 
79  //---------------------------------------
80  // Element connection functions
81  //---------------------------------------
83  int gvo_id,
84  int locid) const;
86  int gvo_id,
87  int locid);
88  SPATIAL_DOMAINS_EXPORT inline int NumElmtConnected() const;
89 
90  //---------------------------------------
91  // Helper functions
92  //---------------------------------------
93 
94  SPATIAL_DOMAINS_EXPORT inline int GetCoordim() const;
96  {
97  m_coordim = coordim;
98  }
101  const Array<OneD, const LibUtilities::BasisSharedPtr>& tbasis);
104  SPATIAL_DOMAINS_EXPORT inline int GetGlobalID(void);
105  SPATIAL_DOMAINS_EXPORT inline void SetGlobalID(int globalid);
106  SPATIAL_DOMAINS_EXPORT inline int GetVid(int i) const;
107  SPATIAL_DOMAINS_EXPORT inline int GetEid(int i) const;
108  SPATIAL_DOMAINS_EXPORT inline int GetFid(int i) const;
109  SPATIAL_DOMAINS_EXPORT inline int GetNumVerts() const;
112  GetEorient(const int i) const;
114  GetPorient(const int i) const;
115  SPATIAL_DOMAINS_EXPORT inline int GetNumEdges() const;
116  SPATIAL_DOMAINS_EXPORT inline int GetNumFaces() const;
117  SPATIAL_DOMAINS_EXPORT inline int GetShapeDim() const;
119  GetXmap() const;
120  SPATIAL_DOMAINS_EXPORT inline const Array<OneD, const NekDouble> &
121  GetCoeffs(const int i) const;
123  const Array<OneD, const NekDouble>& gloCoord,
124  NekDouble tol = 0.0);
126  const Array<OneD, const NekDouble>& gloCoord,
127  Array<OneD, NekDouble> &locCoord,
128  NekDouble tol);
130  const Array<OneD, const NekDouble>& gloCoord,
131  Array<OneD, NekDouble> &locCoord,
132  NekDouble tol,
133  NekDouble &resid);
134  SPATIAL_DOMAINS_EXPORT inline int GetVertexEdgeMap(int i, int j) const;
135  SPATIAL_DOMAINS_EXPORT inline int GetVertexFaceMap(int i, int j) const;
136  SPATIAL_DOMAINS_EXPORT inline int GetEdgeFaceMap(int i, int j) const;
137 
138  SPATIAL_DOMAINS_EXPORT inline void FillGeom();
140  const Array<OneD, const NekDouble> &coords,
141  Array<OneD, NekDouble> &Lcoords);
143  const int i, const Array<OneD, const NekDouble> &Lcoord);
144 
145  SPATIAL_DOMAINS_EXPORT inline void SetOwnData();
147  GetBasis(const int i);
149  GetPointsKeys();
150 
151  protected:
152 
156 
157  /// coordinate dimension
162 
163  /// enum identifier to determine if quad points are filled
168 
169  Array<OneD, Array<OneD, NekDouble> > m_coeffs;
170 
171  void GenGeomFactors();
172 
173  //---------------------------------------
174  // Element connection functions
175  //---------------------------------------
176  virtual bool v_IsElmtConnected(
177  int gvo_id,
178  int locid) const;
179  virtual void v_AddElmtConnected(
180  int gvo_id,
181  int locid);
182  virtual int v_NumElmtConnected() const;
183 
184  //---------------------------------------
185  // Helper functions
186  //---------------------------------------
187 
188  virtual int v_GetEid(int i) const;
189  virtual int v_GetVid(int i) const;
190  virtual int v_GetFid(int i) const;
191  virtual void v_GenGeomFactors() = 0;
192  virtual int v_GetNumVerts() const;
193  virtual PointGeomSharedPtr v_GetVertex(int i) const = 0;
195  v_GetEorient(const int i) const;
197  v_GetPorient(const int i) const;
198  virtual int v_GetNumEdges() const;
199  virtual int v_GetNumFaces() const;
200  virtual int v_GetShapeDim() const;
202  v_GetXmap() const;
203  virtual int v_GetCoordim() const;
204  virtual bool v_ContainsPoint(
205  const Array<OneD, const NekDouble>& gloCoord,
206  NekDouble tol = 0.0);
207  virtual bool v_ContainsPoint(
208  const Array<OneD, const NekDouble>& gloCoord,
209  Array<OneD, NekDouble>& locCoord,
210  NekDouble tol);
211  virtual bool v_ContainsPoint(
212  const Array<OneD, const NekDouble>& gloCoord,
213  Array<OneD, NekDouble>& locCoord,
214  NekDouble tol,
215  NekDouble &resid);
216 
217  virtual int v_GetVertexEdgeMap(int i,int j) const;
218  virtual int v_GetVertexFaceMap(int i,int j) const;
219  virtual int v_GetEdgeFaceMap(int i,int j) const;
220 
221  virtual void v_FillGeom();
222  virtual NekDouble v_GetCoord(
223  const int i,
224  const Array<OneD,const NekDouble>& Lcoord);
225  virtual NekDouble v_GetLocCoords(
226  const Array<OneD,const NekDouble>& coords,
227  Array<OneD,NekDouble>& Lcoords);
228 
229  virtual void v_SetOwnData();
230  virtual const LibUtilities::BasisSharedPtr
231  v_GetBasis(const int i);
232 
233  inline void SetUpCoeffs(const int nCoeffs);
234  }; // class Geometry
235 
236 
237  struct GeometryHash : std::unary_function<GeometrySharedPtr, std::size_t>
238  {
239  std::size_t operator()(GeometrySharedPtr const& p) const
240  {
241  int i;
242  size_t seed = 0;
243  int nVert = p->GetNumVerts();
244  std::vector<unsigned int> ids(nVert);
245 
246  for (i = 0; i < nVert; ++i)
247  {
248  ids[i] = p->GetVid(i);
249  }
250  std::sort(ids.begin(), ids.end());
251  boost::hash_range(seed, ids.begin(), ids.end());
252 
253  return seed;
254  }
255  };
256 
257 
258  inline void Geometry::AddElmtConnected(int gvo_id, int locid)
259  {
260  return v_AddElmtConnected(gvo_id, locid);
261  }
262 
263  inline int Geometry::NumElmtConnected() const
264  {
265  return v_NumElmtConnected();
266  }
267 
268  inline bool Geometry::IsElmtConnected(int gvo_id, int locid) const
269  {
270  return v_IsElmtConnected(gvo_id,locid);
271  }
272 
273  inline int Geometry::GetCoordim() const
274  {
275  return v_GetCoordim();
276  }
277 
279  {
280  GenGeomFactors();
282  }
283 
285  {
286  return m_geomFactors;
287  }
288 
290  {
291  return m_shapeType;
292  }
293 
294  inline int Geometry::GetGlobalID(void)
295  {
296  return m_globalID;
297  }
298 
299  inline void Geometry::SetGlobalID(int globalid)
300  {
301  m_globalID = globalid;
302  }
303 
304  inline int Geometry::GetVid(int i) const
305  {
306  return v_GetVid(i);
307  }
308 
309  inline int Geometry::GetEid(int i) const
310  {
311  return v_GetEid(i);
312  }
313 
314  inline int Geometry::GetFid(int i) const
315  {
316  return v_GetFid(i);
317  }
318 
319  inline int Geometry::GetNumVerts() const
320  {
321  return v_GetNumVerts();
322  }
323 
325  {
326  return v_GetVertex(i);
327  }
328 
330  {
331  return v_GetEorient(i);
332  }
333 
335  {
336  return v_GetPorient(i);
337  }
338 
339  inline int Geometry::GetNumEdges() const
340  {
341  return v_GetNumEdges();
342  }
343 
344  inline int Geometry::GetNumFaces() const
345  {
346  return v_GetNumFaces();
347  }
348 
349  inline int Geometry::GetShapeDim() const
350  {
351  return v_GetShapeDim();
352  }
353 
355  {
356  return v_GetXmap();
357  }
358 
359  inline const Array<OneD, const NekDouble> &Geometry::GetCoeffs(const int i) const
360  {
361  return m_coeffs[i];
362  }
363 
365  const Array<OneD, const NekDouble>& gloCoord,
366  NekDouble tol)
367  {
368  return v_ContainsPoint(gloCoord,tol);
369  }
370 
372  const Array<OneD, const NekDouble>& gloCoord,
373  Array<OneD, NekDouble> &locCoord,
374  NekDouble tol)
375  {
376  return v_ContainsPoint(gloCoord,locCoord,tol);
377  }
378 
380  const Array<OneD, const NekDouble>& gloCoord,
381  Array<OneD, NekDouble> &locCoord,
382  NekDouble tol,
383  NekDouble &resid)
384  {
385  return v_ContainsPoint(gloCoord,locCoord,tol,resid);
386  }
387 
388  inline int Geometry::GetVertexEdgeMap(int i, int j) const
389  {
390  return v_GetVertexEdgeMap(i,j);
391  }
392 
393  /// return the id of the \f$j^{th}\f$ face attached to the \f$ i^{th}\f$ vertex
394  inline int Geometry::GetVertexFaceMap(int i, int j) const
395  {
396  return v_GetVertexFaceMap(i,j);
397  }
398 
399  inline int Geometry::GetEdgeFaceMap(int i, int j) const
400  {
401  return v_GetEdgeFaceMap(i,j);
402  }
403 
405  {
406  return v_GenGeomFactors();
407  }
408 
409 
410  /**
411  * @brief Put all quadrature information into face/edge structure and
412  * backward transform.
413  *
414  * @see v_FillGeom()
415  */
416  inline void Geometry::FillGeom()
417  {
418  v_FillGeom();
419  }
420 
422  const Array<OneD, const NekDouble> &coords,
423  Array<OneD, NekDouble> &Lcoords)
424  {
425  return v_GetLocCoords(coords, Lcoords);
426  }
427 
428  /**
429  * @brief Given local collapsed coordinate Lcoord return the value of
430  * physical coordinate in direction i.
431  */
433  const int i, const Array<OneD, const NekDouble> &Lcoord)
434  {
435  return v_GetCoord(i, Lcoord);
436  }
437 
438  inline void Geometry::SetOwnData()
439  {
440  v_SetOwnData();
441  }
442 
443  /**
444  * @brief Return the j-th basis of the i-th co-ordinate dimension.
445  */
447  const int i)
448  {
449  return v_GetBasis(i);
450  }
451 
452  inline void Geometry::SetUpCoeffs(const int nCoeffs)
453  {
454  m_coeffs = Array<OneD, Array<OneD, NekDouble> >(m_coordim);
455 
456  for (int i = 0; i < m_coordim; ++i)
457  {
458  m_coeffs[i] = Array<OneD, NekDouble>(nCoeffs, 0.0);
459  }
460  }
461 
463  {
464  return m_xmap->GetPointsKeys();
465  }
466  }; //end of namespace
467 }; // end of namespace
468 
469 #endif //NEKTAR_SPATIALDOMAINS_GEOMETRY_H