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 GetTid(int i) const;
110  SPATIAL_DOMAINS_EXPORT inline int GetNumVerts() const;
113  GetEorient(const int i) const;
115  GetPorient(const int i) const;
117  GetForient(const int i) const;
118  SPATIAL_DOMAINS_EXPORT inline int GetNumEdges() const;
119  SPATIAL_DOMAINS_EXPORT inline int GetNumFaces() const;
120  SPATIAL_DOMAINS_EXPORT inline int GetShapeDim() const;
122  GetXmap() const;
123  SPATIAL_DOMAINS_EXPORT inline const Array<OneD, const NekDouble> &
124  GetCoeffs(const int i) const;
126  const Array<OneD, const NekDouble>& gloCoord,
127  NekDouble tol = 0.0);
129  const Array<OneD, const NekDouble>& gloCoord,
130  Array<OneD, NekDouble> &locCoord,
131  NekDouble tol);
133  const Array<OneD, const NekDouble>& gloCoord,
134  Array<OneD, NekDouble> &locCoord,
135  NekDouble tol,
136  NekDouble &resid);
137  SPATIAL_DOMAINS_EXPORT inline int GetVertexEdgeMap(int i, int j) const;
138  SPATIAL_DOMAINS_EXPORT inline int GetVertexFaceMap(int i, int j) const;
139  SPATIAL_DOMAINS_EXPORT inline int GetEdgeFaceMap(int i, int j) const;
140 
141  SPATIAL_DOMAINS_EXPORT inline void FillGeom();
143  const Array<OneD, const NekDouble> &coords,
144  Array<OneD, NekDouble> &Lcoords);
146  const int i, const Array<OneD, const NekDouble> &Lcoord);
147 
148  SPATIAL_DOMAINS_EXPORT inline void SetOwnData();
150  GetBasis(const int i);
152  GetPointsKeys();
153 
154  protected:
155 
159 
160  /// coordinate dimension
165 
166  /// enum identifier to determine if quad points are filled
171 
172  Array<OneD, Array<OneD, NekDouble> > m_coeffs;
173 
174  void GenGeomFactors();
175 
176  //---------------------------------------
177  // Element connection functions
178  //---------------------------------------
179  virtual bool v_IsElmtConnected(
180  int gvo_id,
181  int locid) const;
182  virtual void v_AddElmtConnected(
183  int gvo_id,
184  int locid);
185  virtual int v_NumElmtConnected() const;
186 
187  //---------------------------------------
188  // Helper functions
189  //---------------------------------------
190 
191  virtual int v_GetEid(int i) const;
192  virtual int v_GetVid(int i) const;
193  virtual int v_GetFid(int i) const;
194  virtual void v_GenGeomFactors() = 0;
195  virtual int v_GetNumVerts() const;
196  virtual PointGeomSharedPtr v_GetVertex(int i) const = 0;
198  v_GetEorient(const int i) const;
200  v_GetPorient(const int i) const;
202  v_GetForient(const int i) const;
203  virtual int v_GetNumEdges() const;
204  virtual int v_GetNumFaces() const;
205  virtual int v_GetShapeDim() const;
207  v_GetXmap() const;
208  virtual int v_GetCoordim() const;
209  virtual bool v_ContainsPoint(
210  const Array<OneD, const NekDouble>& gloCoord,
211  NekDouble tol = 0.0);
212  virtual bool v_ContainsPoint(
213  const Array<OneD, const NekDouble>& gloCoord,
214  Array<OneD, NekDouble>& locCoord,
215  NekDouble tol);
216  virtual bool v_ContainsPoint(
217  const Array<OneD, const NekDouble>& gloCoord,
218  Array<OneD, NekDouble>& locCoord,
219  NekDouble tol,
220  NekDouble &resid);
221 
222  virtual int v_GetVertexEdgeMap(int i,int j) const;
223  virtual int v_GetVertexFaceMap(int i,int j) const;
224  virtual int v_GetEdgeFaceMap(int i,int j) const;
225 
226  virtual void v_FillGeom();
227  virtual NekDouble v_GetCoord(
228  const int i,
229  const Array<OneD,const NekDouble>& Lcoord);
230  virtual NekDouble v_GetLocCoords(
231  const Array<OneD,const NekDouble>& coords,
232  Array<OneD,NekDouble>& Lcoords);
233 
234  virtual void v_SetOwnData();
235  virtual const LibUtilities::BasisSharedPtr
236  v_GetBasis(const int i);
237 
238  inline void SetUpCoeffs(const int nCoeffs);
239  }; // class Geometry
240 
241 
242  struct GeometryHash : std::unary_function<GeometrySharedPtr, std::size_t>
243  {
244  std::size_t operator()(GeometrySharedPtr const& p) const
245  {
246  int i;
247  size_t seed = 0;
248  int nVert = p->GetNumVerts();
249  std::vector<unsigned int> ids(nVert);
250 
251  for (i = 0; i < nVert; ++i)
252  {
253  ids[i] = p->GetVid(i);
254  }
255  std::sort(ids.begin(), ids.end());
256  boost::hash_range(seed, ids.begin(), ids.end());
257 
258  return seed;
259  }
260  };
261 
262 
263  inline void Geometry::AddElmtConnected(int gvo_id, int locid)
264  {
265  return v_AddElmtConnected(gvo_id, locid);
266  }
267 
268  inline int Geometry::NumElmtConnected() const
269  {
270  return v_NumElmtConnected();
271  }
272 
273  inline bool Geometry::IsElmtConnected(int gvo_id, int locid) const
274  {
275  return v_IsElmtConnected(gvo_id,locid);
276  }
277 
278  inline int Geometry::GetCoordim() const
279  {
280  return v_GetCoordim();
281  }
282 
284  {
285  GenGeomFactors();
287  }
288 
290  {
291  return m_geomFactors;
292  }
293 
295  {
296  return m_shapeType;
297  }
298 
299  inline int Geometry::GetGlobalID(void)
300  {
301  return m_globalID;
302  }
303 
304  inline void Geometry::SetGlobalID(int globalid)
305  {
306  m_globalID = globalid;
307  }
308 
309  inline int Geometry::GetVid(int i) const
310  {
311  return v_GetVid(i);
312  }
313 
314  inline int Geometry::GetEid(int i) const
315  {
316  return v_GetEid(i);
317  }
318 
319  inline int Geometry::GetFid(int i) const
320  {
321  return v_GetFid(i);
322  }
323 
324  inline int Geometry::GetTid(int i) const
325  {
326  const int nDim = GetShapeDim();
327  return
328  nDim == 1 ? v_GetVid(i) :
329  nDim == 2 ? v_GetEid(i) :
330  nDim == 3 ? v_GetFid(i) : 0;
331  }
332 
333  inline int Geometry::GetNumVerts() const
334  {
335  return v_GetNumVerts();
336  }
337 
339  {
340  return v_GetVertex(i);
341  }
342 
344  {
345  return v_GetEorient(i);
346  }
347 
349  {
350  return v_GetPorient(i);
351  }
352 
354  {
355  return v_GetForient(i);
356  }
357 
358  inline int Geometry::GetNumEdges() const
359  {
360  return v_GetNumEdges();
361  }
362 
363  inline int Geometry::GetNumFaces() const
364  {
365  return v_GetNumFaces();
366  }
367 
368  inline int Geometry::GetShapeDim() const
369  {
370  return v_GetShapeDim();
371  }
372 
374  {
375  return v_GetXmap();
376  }
377 
378  inline const Array<OneD, const NekDouble> &Geometry::GetCoeffs(const int i) const
379  {
380  return m_coeffs[i];
381  }
382 
384  const Array<OneD, const NekDouble>& gloCoord,
385  NekDouble tol)
386  {
387  return v_ContainsPoint(gloCoord,tol);
388  }
389 
391  const Array<OneD, const NekDouble>& gloCoord,
392  Array<OneD, NekDouble> &locCoord,
393  NekDouble tol)
394  {
395  return v_ContainsPoint(gloCoord,locCoord,tol);
396  }
397 
399  const Array<OneD, const NekDouble>& gloCoord,
400  Array<OneD, NekDouble> &locCoord,
401  NekDouble tol,
402  NekDouble &resid)
403  {
404  return v_ContainsPoint(gloCoord,locCoord,tol,resid);
405  }
406 
407  inline int Geometry::GetVertexEdgeMap(int i, int j) const
408  {
409  return v_GetVertexEdgeMap(i,j);
410  }
411 
412  /// return the id of the \f$j^{th}\f$ face attached to the \f$ i^{th}\f$ vertex
413  inline int Geometry::GetVertexFaceMap(int i, int j) const
414  {
415  return v_GetVertexFaceMap(i,j);
416  }
417 
418  inline int Geometry::GetEdgeFaceMap(int i, int j) const
419  {
420  return v_GetEdgeFaceMap(i,j);
421  }
422 
424  {
425  return v_GenGeomFactors();
426  }
427 
428 
429  /**
430  * @brief Put all quadrature information into face/edge structure and
431  * backward transform.
432  *
433  * @see v_FillGeom()
434  */
435  inline void Geometry::FillGeom()
436  {
437  v_FillGeom();
438  }
439 
441  const Array<OneD, const NekDouble> &coords,
442  Array<OneD, NekDouble> &Lcoords)
443  {
444  return v_GetLocCoords(coords, Lcoords);
445  }
446 
447  /**
448  * @brief Given local collapsed coordinate Lcoord return the value of
449  * physical coordinate in direction i.
450  */
452  const int i, const Array<OneD, const NekDouble> &Lcoord)
453  {
454  return v_GetCoord(i, Lcoord);
455  }
456 
457  inline void Geometry::SetOwnData()
458  {
459  v_SetOwnData();
460  }
461 
462  /**
463  * @brief Return the j-th basis of the i-th co-ordinate dimension.
464  */
466  const int i)
467  {
468  return v_GetBasis(i);
469  }
470 
471  inline void Geometry::SetUpCoeffs(const int nCoeffs)
472  {
473  m_coeffs = Array<OneD, Array<OneD, NekDouble> >(m_coordim);
474 
475  for (int i = 0; i < m_coordim; ++i)
476  {
477  m_coeffs[i] = Array<OneD, NekDouble>(nCoeffs, 0.0);
478  }
479  }
480 
482  {
483  return m_xmap->GetPointsKeys();
484  }
485  }; //end of namespace
486 }; // end of namespace
487 
488 #endif //NEKTAR_SPATIALDOMAINS_GEOMETRY_H