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  {
140  bool doXrange;
143  bool doYrange;
146  bool doZrange;
149  };
150 
151  typedef boost::shared_ptr<DomainRange> DomainRangeShPtr;
153 
154  struct Expansion
155  {
157  const LibUtilities::BasisKeyVector basiskeyvec):
158  m_geomShPtr(geomShPtr),
159  m_basisKeyVector(basiskeyvec)
160  {
161  }
162 
165  };
166 
167  typedef boost::shared_ptr<Expansion> ExpansionShPtr;
168  typedef std::map<int, ExpansionShPtr> ExpansionMap;
170  typedef std::map<int, ExpansionShPtr>::const_iterator ExpansionMapConstIter;
171 
172  typedef boost::shared_ptr<ExpansionMap> ExpansionMapShPtr;
173  typedef std::map<std::string, ExpansionMapShPtr> ExpansionMapShPtrMap;
175 
176 
177  typedef std::map<std::string, std::string> GeomInfoMap;
178 
179  /// Base class for a spectral/hp element mesh.
180  class MeshGraph
181  {
182  public:
184 
186  unsigned int meshDimension,
187  unsigned int spaceDimension);
188 
190  const LibUtilities::SessionReaderSharedPtr &pSession,
192 
193 
195 
196 
197  /* ---- Mesh Reading routines ---- */
198  SPATIAL_DOMAINS_EXPORT static boost::shared_ptr<MeshGraph> Read(
199  const LibUtilities::SessionReaderSharedPtr &pSession,
201 
202  /// \todo Remove updated routine
203  SPATIAL_DOMAINS_EXPORT static boost::shared_ptr<MeshGraph> Read(
204  const std::string& infilename,
205  bool pReadExpansions = true);
206 
207 
208  /// Read will read the meshgraph vertices given a filename.
210  const std::string& infilename);
211 
212  /// Read will read the meshgraph vertices given a TiXmlDocument.
214  TiXmlDocument &doc);
215 
216  /// Read geometric information from a file.
218  const std::string &infilename);
219 
220  /// Read geometric information from an XML document.
222  TiXmlDocument &doc);
223 
224  /// Read the expansions given the XML file path.
226  const std::string &infilename);
227 
228  /// Read the expansions given the XML document reference.
230  TiXmlDocument &doc);
231 
233  TiXmlDocument &doc);
234 
236  TiXmlDocument &doc);
237 
239  std::string &infilename);
240 
241  /* ---- Helper functions ---- */
242  /// Dimension of the mesh (can be a 1D curve in 3D space).
243  inline int GetMeshDimension() const;
244 
245  /// Dimension of the space (can be a 1D curve in 3D space).
246  inline int GetSpaceDimension() const;
247 
248 
249  /* Range definitions for postprorcessing */
251  (NekDouble xmin, NekDouble xmax,
256 
257  /// Check if goemetry is in range definition if activated
258  bool CheckRange(Geometry2D &geom);
259 
260  /// Check if goemetry is in range definition if activated
261  bool CheckRange(Geometry3D &geom);
262 
263  /* ---- Composites and Domain ---- */
264  inline Composite GetComposite(int whichComposite) const;
265 
267  int whichComposite,
268  int whichItem);
269 
271  const std::string &compositeStr,
272  CompositeMap &compositeVector) const;
273 
274  inline const CompositeMap &GetComposites() const;
275 
276  inline const std::vector<CompositeMap> &GetDomain(void) const;
277 
278  inline const CompositeMap &GetDomain(int domain) const;
279 
280 
281  /* ---- Expansions ---- */
282  inline const ExpansionMap &GetExpansions();
283 
285  const std::string variable);
286 
288  GeometrySharedPtr geom, const std::string variable = "DefaultVar");
289 
290  /// Sets expansions given field definitions
292  std::vector<LibUtilities::FieldDefinitionsSharedPtr>
293  &fielddef);
294 
295  /// Sets expansions given field definition, quadrature points.
297  std::vector<LibUtilities::FieldDefinitionsSharedPtr>
298  &fielddef,
299  std::vector< std::vector<LibUtilities::PointsType> >
300  &pointstype );
301 
302  /// Sets expansions to have equispaced points
304  int npoints = 0);
305 
306  /// This function sets the expansion #exp in map with entry #variable
307  inline void SetExpansions(
308  const std::string variable,
309  ExpansionMapShPtr &exp);
310 
311  /// Sets the basis key for all expansions of the given shape.
315  std::string var = "DefaultVar");
316 
317  inline bool SameExpansions(
318  const std::string var1,
319  const std::string var2);
320 
321  inline bool CheckForGeomInfo(std::string parameter);
322 
323  inline const std::string GetGeomInfo(std::string parameter);
324 
328  ExpansionType type,
329  const int order);
330 
334  ExpansionType type_x,
335  ExpansionType type_y,
336  ExpansionType type_z,
337  const int nummodes_x,
338  const int nummodes_y,
339  const int nummodes_z);
340 
341 
342  /* ---- Manipulation of mesh ---- */
343  inline int GetNvertices() const;
344 
345  inline PointGeomSharedPtr GetVertex(int id);
346  /// Adds a vertex to the with the next available ID.
348  NekDouble x,
349  NekDouble y,
350  NekDouble z);
351 
352  /// \brief Adds an edge between two points. If curveDefinition is
353  /// null, then the edge is straight, otherwise it is curved according
354  /// to the curveDefinition.
356  CurveSharedPtr curveDefinition = CurveSharedPtr());
358 
367 
369 
371  // void AddExpansion(ExpansionShPtr expansion) { m_expansions[expansion->m_geomShPtr->GetGlobalID()] = expansion; }
379 
380  /// Convenience method for ElVis.
381  template<typename ElementType>
382  const std::map<int, boost::shared_ptr<ElementType> >& GetAllElementsOfType() const;
383 
384  protected:
388 
391 
393 
400 
405 
407  std::vector<CompositeMap> m_domain;
409 
411 
413 
414 
416  };
417  typedef boost::shared_ptr<MeshGraph> MeshGraphSharedPtr;
418 
419 
420  /**
421  *
422  */
423  inline int MeshGraph::GetMeshDimension(void) const
424  {
425  return m_meshDimension;
426  }
427 
428 
429  /**
430  *
431  */
432  inline int MeshGraph::GetSpaceDimension(void) const
433  {
434  return m_spaceDimension;
435  }
436 
437 
438  /**
439  *
440  */
441  inline Composite MeshGraph::GetComposite(int whichComposite) const
442  {
443  Composite returnval;
444  ASSERTL0(m_meshComposites.find(whichComposite) != m_meshComposites.end(),
445  "Composite not found.");
446  return m_meshComposites.find(whichComposite)->second;
447  }
448 
449 
450  /**
451  *
452  */
454  {
455  return m_meshComposites;
456  }
457 
458 
459  /**
460  *
461  */
462  inline const std::vector<CompositeMap> &MeshGraph::GetDomain(void) const
463  {
464  return m_domain;
465  }
466 
467  /**
468  *
469  */
470  inline const CompositeMap &MeshGraph::GetDomain(const int domain) const
471  {
472  ASSERTL1(domain < m_domain.size(),"Request for domain which does not exist");
473  return m_domain[domain];
474  }
475 
476 
477  /**
478  *
479  */
481  {
482  std::string defstr = "DefaultVar";
483  return GetExpansions(defstr);
484  }
485 
486 
487  /**
488  *
489  */
490  void MeshGraph::SetExpansions(const std::string variable, ExpansionMapShPtr &exp)
491  {
492  if(m_expansionMapShPtrMap.count(variable) != 0)
493  {
494  ASSERTL0(false,(std::string("Expansion field is already set for variable ") + variable).c_str());
495  }
496  else
497  {
498  m_expansionMapShPtrMap[variable] = exp;
499  }
500  }
501 
502 
503  /**
504  *
505  */
506  inline bool MeshGraph::SameExpansions(const std::string var1, const std::string var2)
507  {
508  ExpansionMapShPtr expVec1 = m_expansionMapShPtrMap.find(var1)->second;
509  ExpansionMapShPtr expVec2 = m_expansionMapShPtrMap.find(var2)->second;
510 
511  if(expVec1.get() == expVec2.get())
512  {
513  return true;
514  }
515 
516  return false;
517  }
518 
519 
520  /**
521  *
522  */
523  inline bool MeshGraph::CheckForGeomInfo(std::string parameter)
524  {
525  return m_geomInfo.find(parameter) != m_geomInfo.end();
526  }
527 
528 
529  /**
530  *
531  */
532  inline const std::string MeshGraph::GetGeomInfo(std::string parameter)
533  {
534  ASSERTL1(m_geomInfo.find(parameter) != m_geomInfo.end(),
535  "Parameter " + parameter + " does not exist.");
536  return m_geomInfo[parameter];
537  }
538 
539 
540  /**
541  *
542  */
543  inline int MeshGraph::GetNvertices() const
544  {
545  return int(m_vertSet.size());
546  }
547 
548 
549  /**
550  *
551  */
553  {
554  PointGeomSharedPtr returnval;
555  PointGeomMap::iterator x = m_vertSet.find(id);
556  ASSERTL0(x != m_vertSet.end(),
557  "Vertex " + boost::lexical_cast<string>(id)
558  + " not found.");
559  return x->second;
560  }
561 
562 
563  /**
564  *
565  */
566  template<>
567  inline const std::map<int, boost::shared_ptr<HexGeom> >& MeshGraph::GetAllElementsOfType() const
568  {
569  return GetAllHexGeoms();
570  }
571 
572 
573  /**
574  *
575  */
576  template<>
577  inline const std::map<int, boost::shared_ptr<PrismGeom> >& MeshGraph::GetAllElementsOfType() const
578  {
579  return GetAllPrismGeoms();
580  }
581 
582 
583  /**
584  *
585  */
586  template<>
587  inline const std::map<int, boost::shared_ptr<TetGeom> >& MeshGraph::GetAllElementsOfType() const
588  {
589  return GetAllTetGeoms();
590  }
591 
592 
593  /**
594  *
595  */
596  template<>
597  inline const std::map<int, boost::shared_ptr<PyrGeom> >& MeshGraph::GetAllElementsOfType() const
598  {
599  return GetAllPyrGeoms();
600  }
601  };
602 };
603 
604 #endif
605