Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // 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:
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 #ifndef NEKTAR_SPATIALDOMAINS_MESHGRAPH_H
36 #define NEKTAR_SPATIALDOMAINS_MESHGRAPH_H
37 
38 #include <boost/unordered_map.hpp>
39 
42 
43 #include <SpatialDomains/SegGeom.h>
44 #include <SpatialDomains/TriGeom.h>
46 #include <SpatialDomains/TetGeom.h>
47 #include <SpatialDomains/PyrGeom.h>
49 #include <SpatialDomains/HexGeom.h>
50 
51 #include <SpatialDomains/Curve.hpp>
53 
54 class TiXmlDocument;
55 
56 namespace Nektar
57 {
58  namespace SpatialDomains
59  {
61  {
80  };
81 
82  // Keep this consistent with the enums in ExpansionType.
83  // This is used in the BC file to specify the expansion type.
84  const std::string kExpansionTypeStr[] =
85  {
86  "NOTYPE",
87  "MODIFIED",
88  "MODIFIEDQUADPLUS1",
89  "MODIFIEDQUADPLUS2",
90  "ORTHOGONAL",
91  "GLL_LAGRANGE",
92  "GLL_LAGRANGE_SEM",
93  "GAUSS_LAGRANGE",
94  "GAUSS_LAGRANGE_SEM",
95  "FOURIER",
96  "FOURIERSINGLEMODE",
97  "FOURIERHALFMODERE",
98  "FOURIERHALFMODEIM",
99  "CHEBYSHEV",
100  "FOURIER-CHEBYSHEV",
101  "CHEBYSHEV-FOURIER",
102  "FOURIER-MODIFIED"
103  };
104 
106  typedef boost::shared_ptr< InterfaceComponent > SharedInterfaceCompPtr;
107  typedef std::vector< PointGeomSharedPtr > PointGeomVector;
108  typedef std::map<int, PointGeomSharedPtr> PointGeomMap;
109  typedef std::list< SharedInterfaceCompPtr > InterfaceCompList;
110 
111  typedef boost::shared_ptr< GeometryVector > Composite;
112  typedef std::map<int, Composite> CompositeMap;
114  typedef std::map<int, Composite>::const_iterator CompositeMapConstIter;
115 
116  struct ElementEdge
117  {
120  };
121 
122  struct ElementFace
123  {
126  };
127 
128 
129  typedef boost::shared_ptr<ElementEdge> ElementEdgeSharedPtr;
130  typedef std::vector<ElementEdgeSharedPtr> ElementEdgeVector;
131  typedef boost::shared_ptr<ElementEdgeVector> ElementEdgeVectorSharedPtr;
132 
133  typedef boost::shared_ptr<ElementFace> ElementFaceSharedPtr;
134  typedef std::vector<ElementFaceSharedPtr> ElementFaceVector;
135  typedef boost::shared_ptr<ElementFaceVector> ElementFaceVectorSharedPtr;
136 
137  // set restriction on domain range for post-processing.
138  struct DomainRange
139  {
149 
152  };
153 
154  typedef boost::shared_ptr<DomainRange> DomainRangeShPtr;
156 
157  struct Expansion
158  {
160  const LibUtilities::BasisKeyVector basiskeyvec):
161  m_geomShPtr(geomShPtr),
162  m_basisKeyVector(basiskeyvec)
163  {
164  }
165 
168  };
169 
170  typedef boost::shared_ptr<Expansion> ExpansionShPtr;
171  typedef std::map<int, ExpansionShPtr> ExpansionMap;
173  typedef std::map<int, ExpansionShPtr>::const_iterator ExpansionMapConstIter;
174 
175  typedef boost::shared_ptr<ExpansionMap> ExpansionMapShPtr;
176  typedef std::map<std::string, ExpansionMapShPtr> ExpansionMapShPtrMap;
178 
179 
180  typedef std::map<std::string, std::string> GeomInfoMap;
181 
182  /// Base class for a spectral/hp element mesh.
183  class MeshGraph
184  {
185  public:
187 
189  unsigned int meshDimension,
190  unsigned int spaceDimension);
191 
193  const LibUtilities::SessionReaderSharedPtr &pSession,
195 
196 
198 
199 
200  /* ---- Mesh Reading routines ---- */
201  SPATIAL_DOMAINS_EXPORT static boost::shared_ptr<MeshGraph> Read(
202  const LibUtilities::SessionReaderSharedPtr &pSession,
204 
205  /// \todo Remove updated routine
206  SPATIAL_DOMAINS_EXPORT static boost::shared_ptr<MeshGraph> Read(
207  const std::string& infilename,
208  bool pReadExpansions = true);
209 
210 
211  /// Read will read the meshgraph vertices given a filename.
213  const std::string& infilename);
214 
215  /// Read will read the meshgraph vertices given a TiXmlDocument.
217  TiXmlDocument &doc);
218 
219  /// Read geometric information from a file.
221  const std::string &infilename);
222 
223  /// Read geometric information from an XML document.
225  TiXmlDocument &doc);
226 
227  /// Read the expansions given the XML file path.
229  const std::string &infilename);
230 
231  /// Read the expansions given the XML document reference.
233  TiXmlDocument &doc);
234 
236  TiXmlDocument &doc);
237 
239  TiXmlDocument &doc);
240 
242  std::string &infilename);
243 
244  /* ---- Helper functions ---- */
245  /// Dimension of the mesh (can be a 1D curve in 3D space).
246  inline int GetMeshDimension() const;
247 
248  /// Dimension of the space (can be a 1D curve in 3D space).
249  inline int GetSpaceDimension() const;
250 
251 
252  /* Range definitions for postprorcessing */
254  (NekDouble xmin, NekDouble xmax,
259 
260  /// Check if goemetry is in range definition if activated
261  bool CheckRange(Geometry2D &geom);
262 
263  /// Check if goemetry is in range definition if activated
264  bool CheckRange(Geometry3D &geom);
265 
266  /* ---- Composites and Domain ---- */
267  inline Composite GetComposite(int whichComposite) const;
268 
270  int whichComposite,
271  int whichItem);
272 
274  const std::string &compositeStr,
275  CompositeMap &compositeVector) const;
276 
277  inline const CompositeMap &GetComposites() const;
278 
279  inline const std::vector<CompositeMap> &GetDomain(void) const;
280 
281  inline const CompositeMap &GetDomain(int domain) const;
282 
283 
284  /* ---- Expansions ---- */
285  inline const ExpansionMap &GetExpansions();
286 
288  const std::string variable);
289 
291  GeometrySharedPtr geom, const std::string variable = "DefaultVar");
292 
293  /// Sets expansions given field definitions
295  std::vector<LibUtilities::FieldDefinitionsSharedPtr>
296  &fielddef);
297 
298  /// Sets expansions given field definition, quadrature points.
300  std::vector<LibUtilities::FieldDefinitionsSharedPtr>
301  &fielddef,
302  std::vector< std::vector<LibUtilities::PointsType> >
303  &pointstype );
304 
305  /// Sets expansions to have equispaced points
307  int npoints = 0);
308 
309  /// This function sets the expansion #exp in map with entry #variable
310  inline void SetExpansions(
311  const std::string variable,
312  ExpansionMapShPtr &exp);
313 
314  /// Sets the basis key for all expansions of the given shape.
318  std::string var = "DefaultVar");
319 
320  inline bool SameExpansions(
321  const std::string var1,
322  const std::string var2);
323 
324  inline bool CheckForGeomInfo(std::string parameter);
325 
326  inline const std::string GetGeomInfo(std::string parameter);
327 
331  ExpansionType type,
332  const int order);
333 
337  ExpansionType type_x,
338  ExpansionType type_y,
339  ExpansionType type_z,
340  const int nummodes_x,
341  const int nummodes_y,
342  const int nummodes_z);
343 
344 
345  /* ---- Manipulation of mesh ---- */
346  inline int GetNvertices() const;
347 
348  inline PointGeomSharedPtr GetVertex(int id);
349  /// Adds a vertex to the with the next available ID.
351  NekDouble x,
352  NekDouble y,
353  NekDouble z);
354 
355  /// \brief Adds an edge between two points. If curveDefinition is
356  /// null, then the edge is straight, otherwise it is curved according
357  /// to the curveDefinition.
359  CurveSharedPtr curveDefinition = CurveSharedPtr());
361 
370 
372 
374  // void AddExpansion(ExpansionShPtr expansion) { m_expansions[expansion->m_geomShPtr->GetGlobalID()] = expansion; }
382 
383  /// Convenience method for ElVis.
384  template<typename ElementType>
385  const std::map<int, boost::shared_ptr<ElementType> >& GetAllElementsOfType() const;
386 
387  protected:
391 
394 
396 
403 
408 
410  std::vector<CompositeMap> m_domain;
412 
414 
416 
417 
419  };
420  typedef boost::shared_ptr<MeshGraph> MeshGraphSharedPtr;
421 
422 
423  /**
424  *
425  */
426  inline int MeshGraph::GetMeshDimension(void) const
427  {
428  return m_meshDimension;
429  }
430 
431 
432  /**
433  *
434  */
435  inline int MeshGraph::GetSpaceDimension(void) const
436  {
437  return m_spaceDimension;
438  }
439 
440 
441  /**
442  *
443  */
444  inline Composite MeshGraph::GetComposite(int whichComposite) const
445  {
446  Composite returnval;
447  ASSERTL0(m_meshComposites.find(whichComposite) != m_meshComposites.end(),
448  "Composite not found.");
449  return m_meshComposites.find(whichComposite)->second;
450  }
451 
452 
453  /**
454  *
455  */
457  {
458  return m_meshComposites;
459  }
460 
461 
462  /**
463  *
464  */
465  inline const std::vector<CompositeMap> &MeshGraph::GetDomain(void) const
466  {
467  return m_domain;
468  }
469 
470  /**
471  *
472  */
473  inline const CompositeMap &MeshGraph::GetDomain(const int domain) const
474  {
475  ASSERTL1(domain < m_domain.size(),"Request for domain which does not exist");
476  return m_domain[domain];
477  }
478 
479 
480  /**
481  *
482  */
484  {
485  std::string defstr = "DefaultVar";
486  return GetExpansions(defstr);
487  }
488 
489 
490  /**
491  *
492  */
493  void MeshGraph::SetExpansions(const std::string variable, ExpansionMapShPtr &exp)
494  {
495  if(m_expansionMapShPtrMap.count(variable) != 0)
496  {
497  ASSERTL0(false,(std::string("Expansion field is already set for variable ") + variable).c_str());
498  }
499  else
500  {
501  m_expansionMapShPtrMap[variable] = exp;
502  }
503  }
504 
505 
506  /**
507  *
508  */
509  inline bool MeshGraph::SameExpansions(const std::string var1, const std::string var2)
510  {
511  ExpansionMapShPtr expVec1 = m_expansionMapShPtrMap.find(var1)->second;
512  ExpansionMapShPtr expVec2 = m_expansionMapShPtrMap.find(var2)->second;
513 
514  if(expVec1.get() == expVec2.get())
515  {
516  return true;
517  }
518 
519  return false;
520  }
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  */
535  inline const std::string MeshGraph::GetGeomInfo(std::string parameter)
536  {
537  ASSERTL1(m_geomInfo.find(parameter) != m_geomInfo.end(),
538  "Parameter " + parameter + " does not exist.");
539  return m_geomInfo[parameter];
540  }
541 
542 
543  /**
544  *
545  */
546  inline int MeshGraph::GetNvertices() const
547  {
548  return int(m_vertSet.size());
549  }
550 
551 
552  /**
553  *
554  */
556  {
557  PointGeomSharedPtr returnval;
558  PointGeomMap::iterator x = m_vertSet.find(id);
559  ASSERTL0(x != m_vertSet.end(),
560  "Vertex " + boost::lexical_cast<string>(id)
561  + " not found.");
562  return x->second;
563  }
564 
565 
566  /**
567  *
568  */
569  template<>
570  inline const std::map<int, boost::shared_ptr<HexGeom> >& MeshGraph::GetAllElementsOfType() const
571  {
572  return GetAllHexGeoms();
573  }
574 
575 
576  /**
577  *
578  */
579  template<>
580  inline const std::map<int, boost::shared_ptr<PrismGeom> >& MeshGraph::GetAllElementsOfType() const
581  {
582  return GetAllPrismGeoms();
583  }
584 
585 
586  /**
587  *
588  */
589  template<>
590  inline const std::map<int, boost::shared_ptr<TetGeom> >& MeshGraph::GetAllElementsOfType() const
591  {
592  return GetAllTetGeoms();
593  }
594 
595 
596  /**
597  *
598  */
599  template<>
600  inline const std::map<int, boost::shared_ptr<PyrGeom> >& MeshGraph::GetAllElementsOfType() const
601  {
602  return GetAllPyrGeoms();
603  }
604  };
605 };
606 
607 #endif
608