Nektar++
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/unordered_map.hpp>
45 #include <boost/functional/hash.hpp>
46 #include <boost/shared_ptr.hpp>
48 
49 namespace Nektar
50 {
51  namespace SpatialDomains
52  {
53  class Geometry; // Forward declaration for typedef.
54  typedef boost::shared_ptr<Geometry> GeometrySharedPtr;
55  typedef std::vector< GeometrySharedPtr > GeometryVector;
56  typedef boost::unordered_set< GeometrySharedPtr > GeometrySet;
57  typedef boost::shared_ptr <GeometryVector> GeometryVectorSharedPtr;
59 
60  class PointGeom;
61  typedef boost::shared_ptr< PointGeom > PointGeomSharedPtr;
62 
63  struct Curve;
64  typedef boost::shared_ptr<Curve> CurveSharedPtr;
65  typedef boost::unordered_map<int, CurveSharedPtr> CurveMap;
66 
67  /// \brief Less than operator to sort Geometry objects by global id when sorting
68  /// STL containers.
69  SPATIAL_DOMAINS_EXPORT bool SortByGlobalId(const boost::shared_ptr<Geometry>& lhs,
70  const boost::shared_ptr<Geometry>& rhs);
71 
72  SPATIAL_DOMAINS_EXPORT bool GlobalIdEquality(const boost::shared_ptr<Geometry>& lhs,
73  const boost::shared_ptr<Geometry>& rhs);
74 
75  /// Base class for shape geometry information
76  class Geometry
77  {
78  public:
80  SPATIAL_DOMAINS_EXPORT Geometry(int coordim);
81 
83 
84  //---------------------------------------
85  // Element connection functions
86  //---------------------------------------
88  int gvo_id,
89  int locid) const;
91  int gvo_id,
92  int locid);
93  SPATIAL_DOMAINS_EXPORT inline int NumElmtConnected() const;
94 
95  //---------------------------------------
96  // Helper functions
97  //---------------------------------------
98 
99  SPATIAL_DOMAINS_EXPORT inline int GetCoordim() const;
101  {
102  m_coordim = coordim;
103  }
109  SPATIAL_DOMAINS_EXPORT inline int GetGlobalID(void);
110  SPATIAL_DOMAINS_EXPORT inline void SetGlobalID(int globalid);
111  SPATIAL_DOMAINS_EXPORT inline int GetVid(int i) const;
112  SPATIAL_DOMAINS_EXPORT inline int GetEid(int i) const;
113  SPATIAL_DOMAINS_EXPORT inline int GetFid(int i) const;
114  SPATIAL_DOMAINS_EXPORT inline int GetTid(int i) const;
115  SPATIAL_DOMAINS_EXPORT inline int GetNumVerts() const;
116  SPATIAL_DOMAINS_EXPORT inline PointGeomSharedPtr GetVertex(int i) const;
118  GetEorient(const int i) const;
120  GetPorient(const int i) const;
122  GetForient(const int i) const;
123  SPATIAL_DOMAINS_EXPORT inline int GetNumEdges() const;
124  SPATIAL_DOMAINS_EXPORT inline int GetNumFaces() const;
125  SPATIAL_DOMAINS_EXPORT inline int GetShapeDim() const;
127  GetXmap() const;
129  GetCoeffs(const int i) const;
131  const Array<OneD, const NekDouble>& gloCoord,
132  NekDouble tol = 0.0);
134  const Array<OneD, const NekDouble>& gloCoord,
135  Array<OneD, NekDouble> &locCoord,
136  NekDouble tol);
138  const Array<OneD, const NekDouble>& gloCoord,
139  Array<OneD, NekDouble> &locCoord,
140  NekDouble tol,
141  NekDouble &resid);
142  SPATIAL_DOMAINS_EXPORT inline int GetVertexEdgeMap(int i, int j) const;
143  SPATIAL_DOMAINS_EXPORT inline int GetVertexFaceMap(int i, int j) const;
144  SPATIAL_DOMAINS_EXPORT inline int GetEdgeFaceMap(int i, int j) const;
145 
146  SPATIAL_DOMAINS_EXPORT inline void FillGeom();
148  const Array<OneD, const NekDouble> &coords,
149  Array<OneD, NekDouble> &Lcoords);
151  const int i, const Array<OneD, const NekDouble> &Lcoord);
152 
153  SPATIAL_DOMAINS_EXPORT inline void SetOwnData();
155  GetBasis(const int i);
157  GetPointsKeys();
158  SPATIAL_DOMAINS_EXPORT inline void Reset(
159  CurveMap &curvedEdges,
160  CurveMap &curvedFaces);
161 
162  protected:
163 
167 
168  /// coordinate dimension
173 
174  /// enum identifier to determine if quad points are filled
179 
181 
182  void GenGeomFactors();
183 
184  //---------------------------------------
185  // Element connection functions
186  //---------------------------------------
187  virtual bool v_IsElmtConnected(
188  int gvo_id,
189  int locid) const;
190  virtual void v_AddElmtConnected(
191  int gvo_id,
192  int locid);
193  virtual int v_NumElmtConnected() const;
194 
195  //---------------------------------------
196  // Helper functions
197  //---------------------------------------
198 
199  virtual int v_GetEid(int i) const;
200  virtual int v_GetVid(int i) const;
201  virtual int v_GetFid(int i) const;
202  virtual void v_GenGeomFactors() = 0;
203  virtual int v_GetNumVerts() const;
204  virtual PointGeomSharedPtr v_GetVertex(int i) const = 0;
206  v_GetEorient(const int i) const;
208  v_GetPorient(const int i) const;
210  v_GetForient(const int i) const;
211  virtual int v_GetNumEdges() const;
212  virtual int v_GetNumFaces() const;
213  virtual int v_GetShapeDim() const;
215  v_GetXmap() const;
216  virtual int v_GetCoordim() const;
217  virtual bool v_ContainsPoint(
218  const Array<OneD, const NekDouble>& gloCoord,
219  NekDouble tol = 0.0);
220  virtual bool v_ContainsPoint(
221  const Array<OneD, const NekDouble>& gloCoord,
222  Array<OneD, NekDouble>& locCoord,
223  NekDouble tol);
224  virtual bool v_ContainsPoint(
225  const Array<OneD, const NekDouble>& gloCoord,
226  Array<OneD, NekDouble>& locCoord,
227  NekDouble tol,
228  NekDouble &resid);
229 
230  virtual int v_GetVertexEdgeMap(int i,int j) const;
231  virtual int v_GetVertexFaceMap(int i,int j) const;
232  virtual int v_GetEdgeFaceMap(int i,int j) const;
233 
234  virtual void v_FillGeom();
235  virtual NekDouble v_GetCoord(
236  const int i,
237  const Array<OneD,const NekDouble>& Lcoord);
238  virtual NekDouble v_GetLocCoords(
239  const Array<OneD,const NekDouble>& coords,
240  Array<OneD,NekDouble>& Lcoords);
241 
242  virtual void v_SetOwnData();
243  virtual const LibUtilities::BasisSharedPtr
244  v_GetBasis(const int i);
245  virtual void v_Reset(
246  CurveMap &curvedEdges,
247  CurveMap &curvedFaces);
248  inline void SetUpCoeffs(const int nCoeffs);
249  }; // class Geometry
250 
251 
252  struct GeometryHash : std::unary_function<GeometrySharedPtr, std::size_t>
253  {
254  std::size_t operator()(GeometrySharedPtr const& p) const
255  {
256  int i;
257  size_t seed = 0;
258  int nVert = p->GetNumVerts();
259  std::vector<unsigned int> ids(nVert);
260 
261  for (i = 0; i < nVert; ++i)
262  {
263  ids[i] = p->GetVid(i);
264  }
265  std::sort(ids.begin(), ids.end());
266  boost::hash_range(seed, ids.begin(), ids.end());
267 
268  return seed;
269  }
270  };
271 
272 
273  inline void Geometry::AddElmtConnected(int gvo_id, int locid)
274  {
275  return v_AddElmtConnected(gvo_id, locid);
276  }
277 
278  inline int Geometry::NumElmtConnected() const
279  {
280  return v_NumElmtConnected();
281  }
282 
283  inline bool Geometry::IsElmtConnected(int gvo_id, int locid) const
284  {
285  return v_IsElmtConnected(gvo_id,locid);
286  }
287 
288  inline int Geometry::GetCoordim() const
289  {
290  return v_GetCoordim();
291  }
292 
294  {
295  GenGeomFactors();
297  }
298 
300  {
301  return m_geomFactors;
302  }
303 
305  {
306  return m_shapeType;
307  }
308 
309  inline int Geometry::GetGlobalID(void)
310  {
311  return m_globalID;
312  }
313 
314  inline void Geometry::SetGlobalID(int globalid)
315  {
316  m_globalID = globalid;
317  }
318 
319  inline int Geometry::GetVid(int i) const
320  {
321  return v_GetVid(i);
322  }
323 
324  inline int Geometry::GetEid(int i) const
325  {
326  return v_GetEid(i);
327  }
328 
329  inline int Geometry::GetFid(int i) const
330  {
331  return v_GetFid(i);
332  }
333 
334  inline int Geometry::GetTid(int i) const
335  {
336  const int nDim = GetShapeDim();
337  return
338  nDim == 1 ? v_GetVid(i) :
339  nDim == 2 ? v_GetEid(i) :
340  nDim == 3 ? v_GetFid(i) : 0;
341  }
342 
343  inline int Geometry::GetNumVerts() const
344  {
345  return v_GetNumVerts();
346  }
347 
348  inline PointGeomSharedPtr Geometry::GetVertex(int i) const
349  {
350  return v_GetVertex(i);
351  }
352 
354  {
355  return v_GetEorient(i);
356  }
357 
359  {
360  return v_GetPorient(i);
361  }
362 
364  {
365  return v_GetForient(i);
366  }
367 
368  inline int Geometry::GetNumEdges() const
369  {
370  return v_GetNumEdges();
371  }
372 
373  inline int Geometry::GetNumFaces() const
374  {
375  return v_GetNumFaces();
376  }
377 
378  inline int Geometry::GetShapeDim() const
379  {
380  return v_GetShapeDim();
381  }
382 
384  {
385  return v_GetXmap();
386  }
387 
388  inline const Array<OneD, const NekDouble> &Geometry::GetCoeffs(const int i) const
389  {
390  return m_coeffs[i];
391  }
392 
394  const Array<OneD, const NekDouble>& gloCoord,
395  NekDouble tol)
396  {
397  return v_ContainsPoint(gloCoord,tol);
398  }
399 
401  const Array<OneD, const NekDouble>& gloCoord,
402  Array<OneD, NekDouble> &locCoord,
403  NekDouble tol)
404  {
405  return v_ContainsPoint(gloCoord,locCoord,tol);
406  }
407 
409  const Array<OneD, const NekDouble>& gloCoord,
410  Array<OneD, NekDouble> &locCoord,
411  NekDouble tol,
412  NekDouble &resid)
413  {
414  return v_ContainsPoint(gloCoord,locCoord,tol,resid);
415  }
416 
417  inline int Geometry::GetVertexEdgeMap(int i, int j) const
418  {
419  return v_GetVertexEdgeMap(i,j);
420  }
421 
422  /// return the id of the \f$j^{th}\f$ face attached to the \f$ i^{th}\f$ vertex
423  inline int Geometry::GetVertexFaceMap(int i, int j) const
424  {
425  return v_GetVertexFaceMap(i,j);
426  }
427 
428  inline int Geometry::GetEdgeFaceMap(int i, int j) const
429  {
430  return v_GetEdgeFaceMap(i,j);
431  }
432 
434  {
435  return v_GenGeomFactors();
436  }
437 
438 
439  /**
440  * @brief Put all quadrature information into face/edge structure and
441  * backward transform.
442  *
443  * @see v_FillGeom()
444  */
445  inline void Geometry::FillGeom()
446  {
447  v_FillGeom();
448  }
449 
451  const Array<OneD, const NekDouble> &coords,
452  Array<OneD, NekDouble> &Lcoords)
453  {
454  return v_GetLocCoords(coords, Lcoords);
455  }
456 
457  /**
458  * @brief Given local collapsed coordinate Lcoord return the value of
459  * physical coordinate in direction i.
460  */
462  const int i, const Array<OneD, const NekDouble> &Lcoord)
463  {
464  return v_GetCoord(i, Lcoord);
465  }
466 
467  inline void Geometry::SetOwnData()
468  {
469  v_SetOwnData();
470  }
471 
472  /**
473  * @brief Return the j-th basis of the i-th co-ordinate dimension.
474  */
476  const int i)
477  {
478  return v_GetBasis(i);
479  }
480 
481  /**
482  * @brief Initialise the m_coeffs array.
483  */
484  inline void Geometry::SetUpCoeffs(const int nCoeffs)
485  {
487 
488  for (int i = 0; i < m_coordim; ++i)
489  {
490  m_coeffs[i] = Array<OneD, NekDouble>(nCoeffs, 0.0);
491  }
492  }
493 
495  {
496  return m_xmap->GetPointsKeys();
497  }
498 
499  inline void Geometry::Reset(CurveMap &curvedEdges,
500  CurveMap &curvedFaces)
501  {
502  v_Reset(curvedEdges, curvedFaces);
503  }
504  }; //end of namespace
505 }; // end of namespace
506 
507 #endif //NEKTAR_SPATIALDOMAINS_GEOMETRY_H
StdRegions::StdExpansionSharedPtr m_xmap
Definition: Geometry.h:172
virtual StdRegions::Orientation v_GetPorient(const int i) const
Definition: Geometry.cpp:169
StdRegions::Orientation GetPorient(const int i) const
Definition: Geometry.h:358
const LibUtilities::PointsKeyVector GetPointsKeys()
Definition: Geometry.h:494
GeomFactorsSharedPtr GetRefGeomFactors(const Array< OneD, const LibUtilities::BasisSharedPtr > &tbasis)
const Array< OneD, const NekDouble > & GetCoeffs(const int i) const
Definition: Geometry.h:388
virtual PointGeomSharedPtr v_GetVertex(int i) const =0
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:220
void SetGlobalID(int globalid)
Definition: Geometry.h:314
Base class for shape geometry information.
Definition: Geometry.h:76
virtual bool v_ContainsPoint(const Array< OneD, const NekDouble > &gloCoord, NekDouble tol=0.0)
Definition: Geometry.cpp:209
int GetEid(int i) const
Definition: Geometry.h:324
std::size_t operator()(GeometrySharedPtr const &p) const
Definition: Geometry.h:254
GeomFactorsSharedPtr m_geomFactors
Definition: Geometry.h:170
StdRegions::Orientation GetForient(const int i) const
Definition: Geometry.h:363
virtual bool v_IsElmtConnected(int gvo_id, int locid) const
Definition: Geometry.cpp:127
StdRegions::Orientation GetEorient(const int i) const
Definition: Geometry.h:353
virtual int v_GetNumFaces() const
Definition: Geometry.cpp:190
static GeomFactorsSharedPtr ValidateRegGeomFactor(GeomFactorsSharedPtr geomFactor)
Definition: Geometry.cpp:70
virtual NekDouble v_GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Definition: Geometry.cpp:269
GeomFactorsSharedPtr GetGeomFactors()
Definition: Geometry.h:293
virtual void v_Reset(CurveMap &curvedEdges, CurveMap &curvedFaces)
Reset this geometry object: unset the current state and remove allocated GeomFactors.
Definition: Geometry.cpp:307
virtual int v_GetFid(int i) const
Definition: Geometry.cpp:148
virtual int v_NumElmtConnected() const
Definition: Geometry.cpp:120
static GeomFactorsVector m_regGeomFactorsManager
Definition: Geometry.h:166
int GetFid(int i) const
Definition: Geometry.h:329
void Reset(CurveMap &curvedEdges, CurveMap &curvedFaces)
Definition: Geometry.h:499
StdRegions::StdExpansionSharedPtr GetXmap() const
Definition: Geometry.h:383
bool IsElmtConnected(int gvo_id, int locid) const
Definition: Geometry.h:283
virtual int v_GetVid(int i) const
Definition: Geometry.cpp:134
bool SortByGlobalId(const boost::shared_ptr< Geometry > &lhs, const boost::shared_ptr< Geometry > &rhs)
Less than operator to sort Geometry objects by global id when sorting STL containers.
Definition: Geometry.cpp:102
virtual StdRegions::StdExpansionSharedPtr v_GetXmap() const
Definition: Geometry.cpp:204
boost::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:62
int GetEdgeFaceMap(int i, int j) const
Definition: Geometry.h:428
StandardMatrixTag & lhs
const LibUtilities::BasisSharedPtr GetBasis(const int i)
Return the j-th basis of the i-th co-ordinate dimension.
Definition: Geometry.h:475
std::vector< GeometrySharedPtr >::iterator GeometryVectorIter
Definition: Geometry.h:58
virtual StdRegions::Orientation v_GetEorient(const int i) const
Definition: Geometry.cpp:162
virtual int v_GetEdgeFaceMap(int i, int j) const
Definition: Geometry.cpp:253
int GetVertexEdgeMap(int i, int j) const
Definition: Geometry.h:417
bool GlobalIdEquality(const boost::shared_ptr< Geometry > &lhs, const boost::shared_ptr< Geometry > &rhs)
Definition: Geometry.cpp:108
std::vector< GeomFactorsSharedPtr > GeomFactorsVector
A vector of GeomFactor pointers.
Definition: GeomFactors.h:64
bool ContainsPoint(const Array< OneD, const NekDouble > &gloCoord, NekDouble tol=0.0)
Definition: Geometry.h:393
double NekDouble
GeomState
Indicates if the geometric information for an element has been populated.
void FillGeom()
Put all quadrature information into face/edge structure and backward transform.
Definition: Geometry.h:445
virtual void v_AddElmtConnected(int gvo_id, int locid)
Definition: Geometry.cpp:114
virtual int v_GetVertexFaceMap(int i, int j) const
Definition: Geometry.cpp:246
PointGeomSharedPtr GetVertex(int i) const
Definition: Geometry.h:348
virtual int v_GetShapeDim() const
Definition: Geometry.cpp:197
std::vector< GeometrySharedPtr > GeometryVector
Definition: Geometry.h:55
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
int GetVertexFaceMap(int i, int j) const
return the id of the face attached to the vertex
Definition: Geometry.h:423
boost::shared_ptr< GeometryVector > GeometryVectorSharedPtr
Definition: Geometry.h:57
virtual StdRegions::Orientation v_GetForient(const int i) const
Definition: Geometry.cpp:176
boost::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:62
Array< OneD, Array< OneD, NekDouble > > m_coeffs
Definition: Geometry.h:180
int GetVid(int i) const
Definition: Geometry.h:319
NekDouble GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Definition: Geometry.h:450
int GetTid(int i) const
Definition: Geometry.h:334
LibUtilities::ShapeType m_shapeType
Definition: Geometry.h:177
void AddElmtConnected(int gvo_id, int locid)
Definition: Geometry.h:273
boost::unordered_map< int, CurveSharedPtr > CurveMap
Definition: Curve.hpp:63
void SetUpCoeffs(const int nCoeffs)
Initialise the m_coeffs array.
Definition: Geometry.h:484
NekDouble GetCoord(const int i, const Array< OneD, const NekDouble > &Lcoord)
Given local collapsed coordinate Lcoord return the value of physical coordinate in direction i...
Definition: Geometry.h:461
virtual int v_GetVertexEdgeMap(int i, int j) const
Definition: Geometry.cpp:239
virtual int v_GetNumEdges() const
Definition: Geometry.cpp:183
GeomFactorsSharedPtr GetMetricInfo()
Definition: Geometry.h:299
GeomType
Indicates the type of element geometry.
boost::shared_ptr< Basis > BasisSharedPtr
boost::unordered_set< GeometrySharedPtr > GeometrySet
Definition: Geometry.h:56
GeomState m_state
enum identifier to determine if quad points are filled
Definition: Geometry.h:175
virtual NekDouble v_GetCoord(const int i, const Array< OneD, const NekDouble > &Lcoord)
Definition: Geometry.cpp:260
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
virtual int v_GetNumVerts() const
Definition: Geometry.cpp:155
int m_coordim
coordinate dimension
Definition: Geometry.h:169
boost::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
virtual const LibUtilities::BasisSharedPtr v_GetBasis(const int i)
Definition: Geometry.cpp:290
LibUtilities::ShapeType GetShapeType(void)
Definition: Geometry.h:304
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60
virtual int v_GetEid(int i) const
Definition: Geometry.cpp:141
#define SPATIAL_DOMAINS_EXPORT
void SetCoordim(int coordim)
Definition: Geometry.h:100
virtual int v_GetCoordim() const
Definition: Geometry.cpp:298