Nektar++
MeshGraph.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: MeshGraph.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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description:
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_SPATIALDOMAINS_MESHGRAPH_H
36 #define NEKTAR_SPATIALDOMAINS_MESHGRAPH_H
37 
38 #include <unordered_map>
39 
42 
44 #include <SpatialDomains/HexGeom.h>
46 #include <SpatialDomains/PyrGeom.h>
48 #include <SpatialDomains/SegGeom.h>
49 #include <SpatialDomains/TetGeom.h>
50 #include <SpatialDomains/TriGeom.h>
51 
52 #include <SpatialDomains/Curve.hpp>
54 
55 class TiXmlDocument;
56 
57 namespace Nektar
58 {
59 namespace SpatialDomains
60 {
61 typedef std::map<int, std::pair<LibUtilities::ShapeType, std::vector<int>>>
63 
65 {
85 };
86 
87 // Keep this consistent with the enums in ExpansionType.
88 // This is used in the BC file to specify the expansion type.
89 const std::string kExpansionTypeStr[] = {"NOTYPE",
90  "MODIFIED",
91  "MODIFIEDQUADPLUS1",
92  "MODIFIEDQUADPLUS2",
93  "MODIFIEDGLLRADAU10",
94  "ORTHOGONAL",
95  "GLL_LAGRANGE",
96  "GLL_LAGRANGE_SEM",
97  "GAUSS_LAGRANGE",
98  "GAUSS_LAGRANGE_SEM",
99  "FOURIER",
100  "FOURIERSINGLEMODE",
101  "FOURIERHALFMODERE",
102  "FOURIERHALFMODEIM",
103  "CHEBYSHEV",
104  "FOURIER-CHEBYSHEV",
105  "CHEBYSHEV-FOURIER",
106  "FOURIER-MODIFIED"};
107 
108 typedef std::map<int, std::vector<unsigned int>> CompositeOrdering;
109 typedef std::map<int, std::vector<unsigned int>> BndRegionOrdering;
110 
111 // set restriction on domain range for post-processing.
113 {
123 
126 };
127 
128 typedef std::shared_ptr<DomainRange> DomainRangeShPtr;
129 static DomainRangeShPtr NullDomainRangeShPtr;
130 
131 struct Composite
132 {
133  std::vector<std::shared_ptr<Geometry>> m_geomVec;
134 };
135 
136 typedef std::shared_ptr<Composite> CompositeSharedPtr;
137 typedef std::map<int, CompositeSharedPtr> CompositeMap;
138 
139 struct Expansion
140 {
142  const LibUtilities::BasisKeyVector basiskeyvec)
143  : m_geomShPtr(geomShPtr), m_basisKeyVector(basiskeyvec)
144  {
145  }
146 
149 };
150 
151 typedef std::shared_ptr<Expansion> ExpansionShPtr;
152 typedef std::map<int, ExpansionShPtr> ExpansionMap;
153 
154 typedef std::shared_ptr<ExpansionMap> ExpansionMapShPtr;
155 typedef std::map<std::string, ExpansionMapShPtr> ExpansionMapShPtrMap;
156 
157 typedef std::map<std::string, std::string> GeomInfoMap;
158 typedef std::shared_ptr<std::vector<std::pair<GeometrySharedPtr, int>>>
160 
161 typedef std::map<std::string, std::string> MeshMetaDataMap;
162 
163 class MeshGraph;
164 typedef std::shared_ptr<MeshGraph> MeshGraphSharedPtr;
165 
166 /// Base class for a spectral/hp element mesh.
168 {
169 public:
171  SPATIAL_DOMAINS_EXPORT virtual ~MeshGraph();
172 
173  SPATIAL_DOMAINS_EXPORT static MeshGraphSharedPtr Read(
175  DomainRangeShPtr rng = NullDomainRangeShPtr,
176  bool fillGraph = true);
177 
178  SPATIAL_DOMAINS_EXPORT virtual void WriteGeometry(
179  std::string &outfilename,
180  bool defaultExp = false,
181  const LibUtilities::FieldMetaDataMap &metadata
183 
184  void Empty(int dim, int space)
185  {
186  m_meshDimension = dim;
187  m_spaceDimension = space;
188  }
189 
190  /*transfers the minial data structure to full meshgraph*/
191  SPATIAL_DOMAINS_EXPORT void FillGraph();
192 
193  SPATIAL_DOMAINS_EXPORT void FillBoundingBoxTree();
194 
195  SPATIAL_DOMAINS_EXPORT std::vector<int> GetElementsContainingPoint(
197 
198  ////////////////////
199  ////////////////////
200 
201  SPATIAL_DOMAINS_EXPORT void ReadExpansions();
202 
203  /* ---- Helper functions ---- */
204  /// Dimension of the mesh (can be a 1D curve in 3D space).
206  {
207  return m_meshDimension;
208  }
209 
210  /// Dimension of the space (can be a 1D curve in 3D space).
212  {
213  return m_spaceDimension;
214  }
215 
216  /* Range definitions for postprorcessing */
217  SPATIAL_DOMAINS_EXPORT void SetDomainRange(
218  NekDouble xmin, NekDouble xmax,
223 
224  /// Check if goemetry is in range definition if activated
225  SPATIAL_DOMAINS_EXPORT bool CheckRange(Geometry2D &geom);
226 
227  /// Check if goemetry is in range definition if activated
228  SPATIAL_DOMAINS_EXPORT bool CheckRange(Geometry3D &geom);
229 
230  /* ---- Composites and Domain ---- */
231  CompositeSharedPtr GetComposite(int whichComposite)
232  {
233  ASSERTL0(m_meshComposites.find(whichComposite) !=
234  m_meshComposites.end(),
235  "Composite not found.");
236  return m_meshComposites.find(whichComposite)->second;
237  }
238 
239  SPATIAL_DOMAINS_EXPORT GeometrySharedPtr GetCompositeItem(
240  int whichComposite, int whichItem);
241 
242  SPATIAL_DOMAINS_EXPORT void GetCompositeList(
243  const std::string &compositeStr,
244  CompositeMap &compositeVector) const;
245 
246  std::map<int, CompositeSharedPtr> &GetComposites()
247  {
248  return m_meshComposites;
249  }
250 
251  std::map<int, std::string> &GetCompositesLabels()
252  {
253  return m_compositesLabels;
254  }
255 
256  std::vector<std::map<int, CompositeSharedPtr>> &GetDomain()
257  {
258  return m_domain;
259  }
260 
261  std::map<int, CompositeSharedPtr> &GetDomain(int domain)
262  {
263  ASSERTL1(domain < m_domain.size(),
264  "Request for domain which does not exist");
265  return m_domain[domain];
266  }
267 
268  SPATIAL_DOMAINS_EXPORT const ExpansionMap &GetExpansions(
269  const std::string variable = "DefaultVar");
270 
271  SPATIAL_DOMAINS_EXPORT ExpansionShPtr GetExpansion(
272  GeometrySharedPtr geom, const std::string variable = "DefaultVar");
273 
274  /// Sets expansions given field definitions
275  SPATIAL_DOMAINS_EXPORT void SetExpansions(
276  std::vector<LibUtilities::FieldDefinitionsSharedPtr> &fielddef);
277 
278  /// Sets expansions given field definition, quadrature points.
279  SPATIAL_DOMAINS_EXPORT void SetExpansions(
280  std::vector<LibUtilities::FieldDefinitionsSharedPtr> &fielddef,
281  std::vector<std::vector<LibUtilities::PointsType>> &pointstype);
282 
283  /// Sets expansions to have equispaced points
284  SPATIAL_DOMAINS_EXPORT void SetExpansionsToEvenlySpacedPoints(
285  int npoints = 0);
286 
287  /// Reset expansion to have specified polynomial order \a nmodes
288  SPATIAL_DOMAINS_EXPORT void SetExpansionsToPolyOrder(int nmodes);
289 
290  /// Reset expansion to have specified point order \a
291  /// npts
292  SPATIAL_DOMAINS_EXPORT void SetExpansionsToPointOrder(int npts);
293  /// This function sets the expansion #exp in map with
294  /// entry #variable
295 
296  inline void SetExpansions(const std::string variable,
297  ExpansionMapShPtr &exp);
298 
299  inline void SetSession(LibUtilities::SessionReaderSharedPtr pSession);
300 
301  /// Sets the basis key for all expansions of the given shape.
302  SPATIAL_DOMAINS_EXPORT void SetBasisKey(LibUtilities::ShapeType shape,
304  std::string var = "DefaultVar");
305 
306  inline bool SameExpansions(const std::string var1, const std::string var2);
307 
308  inline bool CheckForGeomInfo(std::string parameter);
309 
310  inline const std::string GetGeomInfo(std::string parameter);
311 
313  DefineBasisKeyFromExpansionType(GeometrySharedPtr in, ExpansionType type,
314  const int order);
315 
317  DefineBasisKeyFromExpansionTypeHomo(
318  GeometrySharedPtr in, ExpansionType type_x, ExpansionType type_y,
319  ExpansionType type_z, const int nummodes_x, const int nummodes_y,
320  const int nummodes_z);
321 
322  /* ---- Manipulation of mesh ---- */
324  {
325  return m_vertSet.size();
326  }
327 
329  {
330  return m_vertSet[id];
331  }
332 
334  {
335  return m_segGeoms[id];
336  }
337 
339  {
340  return m_curvedEdges;
341  }
343  {
344  return m_curvedFaces;
345  }
346 
347  SPATIAL_DOMAINS_EXPORT std::map<int, PointGeomSharedPtr> &GetAllPointGeoms()
348  {
349  return m_vertSet;
350  }
351  SPATIAL_DOMAINS_EXPORT std::map<int, SegGeomSharedPtr> &GetAllSegGeoms()
352  {
353  return m_segGeoms;
354  }
356  {
357  return m_triGeoms;
358  }
360  {
361  return m_quadGeoms;
362  }
364  {
365  return m_tetGeoms;
366  }
368  {
369  return m_pyrGeoms;
370  }
372  {
373  return m_prismGeoms;
374  }
376  {
377  return m_hexGeoms;
378  }
379 
380  SPATIAL_DOMAINS_EXPORT int GetNumElements();
381 
383  {
384  auto it1 = m_triGeoms.find(gID);
385  if (it1 != m_triGeoms.end())
386  return it1->second;
387 
388  auto it2 = m_quadGeoms.find(gID);
389  if (it2 != m_quadGeoms.end())
390  return it2->second;
391 
392  return Geometry2DSharedPtr();
393  };
394 
396  SegGeomSharedPtr edge, const std::string variable = "DefaultVar");
397 
398  SPATIAL_DOMAINS_EXPORT GeometryLinkSharedPtr GetElementsFromEdge(
399  Geometry1DSharedPtr edge);
400 
401  SPATIAL_DOMAINS_EXPORT GeometryLinkSharedPtr GetElementsFromFace(
402  Geometry2DSharedPtr face);
403 
405  Geometry2DSharedPtr face, const int facedir,
406  const std::string variable = "DefaultVar");
407 
408  CompositeOrdering &GetCompositeOrdering()
409  {
410  return m_compOrder;
411  }
412 
413  BndRegionOrdering &GetBndRegionOrdering()
414  {
415  return m_bndRegOrder;
416  }
417 
418  /*an inital read which loads a very light weight data structure*/
419  SPATIAL_DOMAINS_EXPORT virtual void ReadGeometry(
420  DomainRangeShPtr rng,
421  bool fillGraph) = 0;
422  SPATIAL_DOMAINS_EXPORT virtual void PartitionMesh(
424 
425  SPATIAL_DOMAINS_EXPORT std::map<int, MeshEntity>
426  CreateMeshEntities();
427  SPATIAL_DOMAINS_EXPORT CompositeDescriptor CreateCompositeDescriptor();
428 
429 protected:
430 
431  void PopulateFaceToElMap(Geometry3DSharedPtr element, int kNfaces);
432  ExpansionMapShPtr SetUpExpansionMap();
433  std::string GetCompositeString(CompositeSharedPtr comp);
434 
437 
440 
442 
449 
454 
455  CompositeMap m_meshComposites;
456  std::map<int, std::string> m_compositesLabels;
457  std::vector<CompositeMap> m_domain;
458  DomainRangeShPtr m_domainRange;
459 
460  ExpansionMapShPtrMap m_expansionMapShPtrMap;
461 
462  GeomInfoMap m_geomInfo;
463 
464  std::unordered_map<int, GeometryLinkSharedPtr> m_faceToElMap;
465 
466  TiXmlElement *m_xmlGeom;
467 
468  CompositeOrdering m_compOrder;
469  BndRegionOrdering m_bndRegOrder;
470 
471  struct GeomRTree;
472  std::unique_ptr<GeomRTree> m_boundingBoxTree;
473 };
474 typedef std::shared_ptr<MeshGraph> MeshGraphSharedPtr;
476 
477 SPATIAL_DOMAINS_EXPORT MeshGraphFactory &GetMeshGraphFactory();
478 
479 /**
480  *
481  */
482 void MeshGraph::SetExpansions(const std::string variable,
483  ExpansionMapShPtr &exp)
484 {
485  if (m_expansionMapShPtrMap.count(variable) != 0)
486  {
487  ASSERTL0(false,
488  (std::string("Expansion field is already set for variable ") +
489  variable)
490  .c_str());
491  }
492  else
493  {
494  m_expansionMapShPtrMap[variable] = exp;
495  }
496 }
497 
498 /**
499  *
500  */
502 {
503  m_session = pSession;
504 }
505 
506 /**
507  *
508  */
509 inline bool MeshGraph::SameExpansions(const std::string var1,
510  const std::string var2)
511 {
512  ExpansionMapShPtr expVec1 = m_expansionMapShPtrMap.find(var1)->second;
513  ExpansionMapShPtr expVec2 = m_expansionMapShPtrMap.find(var2)->second;
514 
515  if (expVec1.get() == expVec2.get())
516  {
517  return true;
518  }
519 
520  return false;
521 }
522 
523 /**
524  *
525  */
526 inline bool MeshGraph::CheckForGeomInfo(std::string parameter)
527 {
528  return m_geomInfo.find(parameter) != m_geomInfo.end();
529 }
530 
531 /**
532  *
533  */
534 inline const std::string MeshGraph::GetGeomInfo(std::string parameter)
535 {
536  ASSERTL1(m_geomInfo.find(parameter) != m_geomInfo.end(),
537  "Parameter " + parameter + " does not exist.");
538  return m_geomInfo[parameter];
539 }
540 }
541 }
542 
543 #endif
int GetMeshDimension()
Dimension of the mesh (can be a 1D curve in 3D space).
Definition: MeshGraph.h:205
std::map< std::string, std::string > GeomInfoMap
Definition: MeshGraph.h:157
void SetExpansions(std::vector< LibUtilities::FieldDefinitionsSharedPtr > &fielddef)
Sets expansions given field definitions.
Definition: MeshGraph.cpp:708
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
LibUtilities::ShapeType m_shapeType
Definition: MeshGraph.h:125
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
LibUtilities::SessionReaderSharedPtr m_session
Definition: MeshGraph.h:435
BndRegionOrdering & GetBndRegionOrdering()
Definition: MeshGraph.h:413
std::vector< std::map< int, CompositeSharedPtr > > & GetDomain()
Definition: MeshGraph.h:256
std::map< int, std::string > m_compositesLabels
Definition: MeshGraph.h:456
std::shared_ptr< Geometry3D > Geometry3DSharedPtr
Definition: Geometry3D.h:52
void SetSession(LibUtilities::SessionReaderSharedPtr pSession)
Definition: MeshGraph.h:501
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
Definition: Geometry.h:65
std::shared_ptr< std::vector< std::pair< GeometrySharedPtr, int > > > GeometryLinkSharedPtr
Definition: MeshGraph.h:159
std::unordered_map< int, CurveSharedPtr > CurveMap
Definition: Curve.hpp:62
Geometry2DSharedPtr GetGeometry2D(int gID)
Definition: MeshGraph.h:382
void Empty(int dim, int space)
Definition: MeshGraph.h:184
std::map< std::string, std::string > MeshMetaDataMap
Definition: MeshGraph.h:161
PointGeomSharedPtr GetVertex(int id)
Definition: MeshGraph.h:328
std::map< int, CompositeSharedPtr > CompositeMap
Definition: MeshGraph.h:137
std::map< int, PrismGeomSharedPtr > PrismGeomMap
Definition: PrismGeom.h:89
std::shared_ptr< Composite > CompositeSharedPtr
Definition: MeshGraph.h:136
std::map< int, PointGeomSharedPtr > & GetAllPointGeoms()
Definition: MeshGraph.h:347
LibUtilities::NekFactory< std::string, MeshGraph > MeshGraphFactory
Definition: MeshGraph.h:475
bool SameExpansions(const std::string var1, const std::string var2)
Definition: MeshGraph.h:509
std::map< int, PyrGeomSharedPtr > PyrGeomMap
Definition: PyrGeom.h:81
Expansion(GeometrySharedPtr geomShPtr, const LibUtilities::BasisKeyVector basiskeyvec)
Definition: MeshGraph.h:141
std::shared_ptr< DomainRange > DomainRangeShPtr
Definition: MeshGraph.h:128
CompositeSharedPtr GetComposite(int whichComposite)
Definition: MeshGraph.h:231
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:52
std::map< int, std::string > & GetCompositesLabels()
Definition: MeshGraph.h:251
std::map< int, TetGeomSharedPtr > TetGeomMap
Definition: TetGeom.h:90
bool CheckForGeomInfo(std::string parameter)
Definition: MeshGraph.h:526
std::unique_ptr< GeomRTree > m_boundingBoxTree
Definition: MeshGraph.h:471
std::map< int, TriGeomSharedPtr > TriGeomMap
Definition: TriGeom.h:59
SegGeomSharedPtr GetSegGeom(int id)
Definition: MeshGraph.h:333
DomainRangeShPtr m_domainRange
Definition: MeshGraph.h:458
CompositeOrdering & GetCompositeOrdering()
Definition: MeshGraph.h:408
MeshGraphFactory & GetMeshGraphFactory()
Definition: MeshGraph.cpp:76
std::map< int, std::vector< unsigned int > > CompositeOrdering
Definition: MeshGraph.h:108
std::map< int, SegGeomSharedPtr > SegGeomMap
Definition: SegGeom.h:52
std::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
GeometrySharedPtr m_geomShPtr
Definition: MeshGraph.h:147
std::vector< std::shared_ptr< Geometry > > m_geomVec
Definition: MeshGraph.h:133
double NekDouble
std::map< int, CompositeSharedPtr > & GetDomain(int domain)
Definition: MeshGraph.h:261
std::vector< BasisKey > BasisKeyVector
Name for a vector of BasisKeys.
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:59
std::map< std::string, ExpansionMapShPtr > ExpansionMapShPtrMap
Definition: MeshGraph.h:155
std::shared_ptr< Expansion > ExpansionShPtr
Definition: MeshGraph.h:151
static const NekDouble kNekUnsetDouble
PrismGeomMap & GetAllPrismGeoms()
Definition: MeshGraph.h:371
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
Definition: MeshGraph.h:62
std::map< int, CompositeSharedPtr > & GetComposites()
Definition: MeshGraph.h:246
int GetSpaceDimension()
Dimension of the space (can be a 1D curve in 3D space).
Definition: MeshGraph.h:211
const std::string GetGeomInfo(std::string parameter)
Definition: MeshGraph.h:534
std::unordered_map< int, GeometryLinkSharedPtr > m_faceToElMap
Definition: MeshGraph.h:464
BndRegionOrdering m_bndRegOrder
Definition: MeshGraph.h:469
std::map< int, QuadGeomSharedPtr > QuadGeomMap
Definition: QuadGeom.h:54
3D geometry information
Definition: Geometry3D.h:67
std::vector< CompositeMap > m_domain
Definition: MeshGraph.h:457
static DomainRangeShPtr NullDomainRangeShPtr
Definition: MeshGraph.h:129
2D geometry information
Definition: Geometry2D.h:68
ExpansionMapShPtrMap m_expansionMapShPtrMap
Definition: MeshGraph.h:460
Base class for a spectral/hp element mesh.
Definition: MeshGraph.h:167
CompositeOrdering m_compOrder
Definition: MeshGraph.h:468
std::shared_ptr< Geometry1D > Geometry1DSharedPtr
Definition: Geometry.h:63
std::map< int, SegGeomSharedPtr > & GetAllSegGeoms()
Definition: MeshGraph.h:351
std::map< int, PointGeomSharedPtr > PointGeomMap
Definition: PointGeom.h:54
std::shared_ptr< ExpansionMap > ExpansionMapShPtr
Definition: MeshGraph.h:154
const std::string kExpansionTypeStr[]
Definition: MeshGraph.h:89
std::map< int, std::vector< unsigned int > > BndRegionOrdering
Definition: MeshGraph.h:109
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
std::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:62
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:53
std::map< int, HexGeomSharedPtr > HexGeomMap
Definition: HexGeom.h:91
Describes the specification for a Basis.
Definition: Basis.h:49
std::shared_ptr< SessionReader > SessionReaderSharedPtr
#define SPATIAL_DOMAINS_EXPORT
LibUtilities::BasisKeyVector m_basisKeyVector
Definition: MeshGraph.h:148
std::map< int, ExpansionShPtr > ExpansionMap
Definition: MeshGraph.h:152
Provides a generic Factory class.
Definition: NekFactory.hpp:103