Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Element.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Element.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: Mesh element.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKMESHUTILS_MESHELEMENTS_ELEMENT
37 #define NEKMESHUTILS_MESHELEMENTS_ELEMENT
38 
42 
46 
47 namespace Nektar
48 {
49 namespace NekMeshUtils
50 {
51 
52 /**
53  * @brief Base class for element definitions.
54  *
55  * An element is defined by a list of vertices, edges and faces
56  * (depending on the dimension of the problem). This base class
57  * provides the underlying structure.
58  */
59 class Element
60 {
61 public:
63  ElmtConfig pConf, unsigned int pNumNodes, unsigned int pGotNodes);
64 
65  /// Returns the ID of the element (or associated edge or face for
66  /// boundary elements).
67  NEKMESHUTILS_EXPORT unsigned int GetId() const
68  {
69  if (m_faceLink.get() != 0)
70  return m_faceLink->m_id;
71  if (m_edgeLink.get() != 0)
72  return m_edgeLink->m_id;
73  return m_id;
74  }
75  /// Returns the expansion dimension of the element.
76  NEKMESHUTILS_EXPORT unsigned int GetDim() const
77  {
78  return m_dim;
79  }
80  /// Returns the configuration of the element.
82  {
83  return m_conf;
84  }
85  ///returns the shapetype
87  {
88  return m_conf.m_e;
89  }
90  /// Returns the tag which defines the element shape.
91  NEKMESHUTILS_EXPORT std::string GetTag() const
92  {
93  if (m_faceLink.get() != 0)
94  return "F";
95  if (m_edgeLink.get() != 0)
96  return "E";
97  return m_tag;
98  }
99  /// Access a vertex node.
101  {
102  return m_vertex[i];
103  }
104  /// Access an edge.
106  {
107  return m_edge[i];
108  }
109  /// Access a face.
111  {
112  return m_face[i];
113  }
114  /// Access the list of vertex nodes.
115  NEKMESHUTILS_EXPORT std::vector<NodeSharedPtr> GetVertexList() const
116  {
117  return m_vertex;
118  }
119  /// Access the list of edges.
120  NEKMESHUTILS_EXPORT std::vector<EdgeSharedPtr> GetEdgeList() const
121  {
122  return m_edge;
123  }
124  /// Access the list of faces.
125  NEKMESHUTILS_EXPORT std::vector<FaceSharedPtr> GetFaceList() const
126  {
127  return m_face;
128  }
129  /// Access the list of volume nodes.
130  NEKMESHUTILS_EXPORT std::vector<NodeSharedPtr> GetVolumeNodes() const
131  {
132  return m_volumeNodes;
133  }
134  NEKMESHUTILS_EXPORT void SetVolumeNodes(std::vector<NodeSharedPtr> &nodes)
135  {
136  m_volumeNodes = nodes;
137  }
139  {
140  return m_curveType;
141  }
143  {
144  m_curveType = cT;
145  }
146  /// Returns the total number of nodes (vertices, edge nodes and
147  /// face nodes and volume nodes).
148  NEKMESHUTILS_EXPORT unsigned int GetNodeCount();
149  /// Access the list of tags associated with this element.
150  NEKMESHUTILS_EXPORT std::vector<int> GetTagList() const
151  {
152  return m_taglist;
153  }
154  /// Returns the number of vertices.
155  NEKMESHUTILS_EXPORT unsigned int GetVertexCount() const
156  {
157  return m_vertex.size();
158  }
159  /// Returns the number of edges.
160  NEKMESHUTILS_EXPORT unsigned int GetEdgeCount() const
161  {
162  return m_edge.size();
163  }
164  /// Returns the number of faces.
165  NEKMESHUTILS_EXPORT unsigned int GetFaceCount() const
166  {
167  return m_face.size();
168  }
169  /// Change the ID of the element.
170  NEKMESHUTILS_EXPORT void SetId(unsigned int p)
171  {
172  m_id = p;
173  }
174  /**
175  * @brief Replace a vertex in the element.
176  *
177  * When a vertex is replaced, the element edges and faces are also
178  * searched and the corresponding edge/face nodes are updated to
179  * maintain consistency.
180  *
181  * @param p Index of the vertex to replace.
182  * @param pNew New vertex.
183  * @param descend If true, we loop over edges and faces and replace the
184  * corresponding vertices with @p pNew.
185  */
187  unsigned int p, NodeSharedPtr pNew, bool descend = true);
188  /**
189  * @brief Replace an edge in the element.
190  *
191  * When an edge is replaced, the element faces are also searched and
192  * the corresponding face edges are updated to maintain consistency.
193  *
194  * @param p Index of the edge to replace.
195  * @param pNew New edge.
196  * @param descend If true, we loop over faces and replace the corresponding
197  * face edge with @p pNew.
198  */
200  unsigned int p, EdgeSharedPtr pNew, bool descend = true);
201  /**
202  * @brief Replace a face in the element.
203  *
204  * When a face is replaced, no other consistency checks are required.
205  *
206  * @param p Index of the face to replace.
207  * @param pNew New face.
208  */
209  NEKMESHUTILS_EXPORT void SetFace(unsigned int p, FaceSharedPtr pNew);
210  /// Set a correspondence between this element and an edge
211  /// (2D boundary element).
213  {
214  m_edgeLink = pLink;
215  }
216  /// Get correspondence between this element and an edge.
218  {
219  return m_edgeLink;
220  }
221  /// Set a correspondence between this element and a face
222  /// (3D boundary element).
224  {
225  m_faceLink = pLink;
226  }
227  /// Get correspondence between this element and a face.
229  {
230  return m_faceLink;
231  }
232  /// Set a correspondence between edge or face i and its
233  /// representative boundary element m->element[expDim-1][j].
235  {
236  m_boundaryLinks[i] = j;
237  }
238  /// Get the location of the boundary face/edge i for this element.
240  {
242  if (it == m_boundaryLinks.end())
243  {
244  return -1;
245  }
246  else
247  {
248  return it->second;
249  }
250  }
251  /// Set the list of tags associated with this element.
252  NEKMESHUTILS_EXPORT void SetTagList(const std::vector<int> &tags)
253  {
254  m_taglist = tags;
255  }
256  /// Generate a list of vertices (1D), edges (2D), or faces (3D).
257  NEKMESHUTILS_EXPORT virtual std::string GetXmlString();
258  /// get list of volume interior nodes
260  std::vector<NodeSharedPtr> &nodeList) const
261  {
262  ASSERTL0(false,
263  "This function should be implemented at a shape level.");
264  }
265 
266  /// Generates a string listing the coordinates of all nodes
267  /// associated with this element.
269  /// Generate a Nektar++ geometry object for this element.
271  int coordDim)
272  {
273  ASSERTL0(false,
274  "This function should be implemented at a shape level.");
275  return boost::shared_ptr<SpatialDomains::Geometry>();
276  }
277 
278  /**
279  * @brief Obtain the order of an element by looking at edges.
280  */
282 
283  /**
284  * @brief Insert interior (i.e. volume) points into this element to make the
285  * geometry an order @p order representation.
286  *
287  * @param order The desired polynomial order.
288  * @param geom The geometry object used to describe the curvature
289  * mapping.
290  * @param edgeType The points distribution to use on the volume.
291  * @param coordDim The coordinate (i.e. space) dimension.
292  * @param id Counter which should be incremented to supply
293  * consistent vertex IDs.
294  * @param justConfig If true, then the configuration Element::m_conf
295  * will be updated but no nodes will be
296  * generated. This is used when considering boundary
297  * elements, which just require copying of face or
298  * edge interior nodes.
299  */
301  int order,
303  LibUtilities::PointsType edgeType,
304  int coordDim,
305  int &id,
306  bool justConfig = false)
307  {
308  ASSERTL0(false,
309  "This function should be implemented at a shape level.");
310  }
311 
312  /**
313  * @brief Get the edge orientation of @p edge with respect to the local
314  * element, which lies at edge index @p edgeId.
315  */
317  int edgeId, EdgeSharedPtr edge)
318  {
319  ASSERTL0(false,
320  "This function should be implemented at a shape level.");
322  }
323 
324  /**
325  * @brief Returns the local index of vertex @p j of face @p i.
326  */
327  NEKMESHUTILS_EXPORT virtual int GetFaceVertex(int i, int j)
328  {
329  ASSERTL0(false,
330  "This function should be implemented at a shape level.");
331  return 0;
332  }
333 
335  {
336  int i, j;
337  for (i = 0; i < m_vertex.size(); ++i)
338  {
339  std::cout << m_vertex[i]->m_x << " " << m_vertex[i]->m_y << " "
340  << m_vertex[i]->m_z << std::endl;
341  }
342  for (i = 0; i < m_edge.size(); ++i)
343  {
344  for (j = 0; j < m_edge[i]->m_edgeNodes.size(); ++j)
345  {
346  NodeSharedPtr n = m_edge[i]->m_edgeNodes[j];
347  std::cout << n->m_x << " " << n->m_y << " " << n->m_z
348  << std::endl;
349  }
350  }
351  for (i = 0; i < m_face.size(); ++i)
352  {
353  for (j = 0; j < m_face[i]->m_faceNodes.size(); ++j)
354  {
355  NodeSharedPtr n = m_face[i]->m_faceNodes[j];
356  std::cout << n->m_x << " " << n->m_y << " " << n->m_z
357  << std::endl;
358  }
359  }
360  }
361 
362  /**
363  * @brief returns the normal to the element
364  */
365  NEKMESHUTILS_EXPORT virtual Array<OneD, NekDouble> Normal(bool inward = false)
366  {
367  ASSERTL0(false,
368  "This function should be implemented at a shape level.");
369  return Array<OneD, NekDouble>();
370  }
371 
373 
374 protected:
375  /// ID of the element.
376  unsigned int m_id;
377  /// Dimension of the element.
378  unsigned int m_dim;
379  /// Contains configuration of the element.
381  /// Tag character describing the element.
382  std::string m_tag;
383  /// List of integers specifying properties of the element.
384  std::vector<int> m_taglist;
385  /// List of element vertex nodes.
386  std::vector<NodeSharedPtr> m_vertex;
387  /// List of element edges.
388  std::vector<EdgeSharedPtr> m_edge;
389  /// List of element faces.
390  std::vector<FaceSharedPtr> m_face;
391  /// List of element volume nodes.
392  std::vector<NodeSharedPtr> m_volumeNodes;
393  /// Volume curve type
395  /// Pointer to the corresponding edge if element is a 2D boundary.
397  /// Pointer to the corresponding face if element is a 3D boundary.
399  /// Array mapping faces/edges to the location of the appropriate
400  /// boundary elements in m->element.
401  std::map<int, int> m_boundaryLinks;
402  /// Nektar++ geometry object for this element.
404 };
405 
406 typedef boost::shared_ptr<Element> ElementSharedPtr;
407 /// Container for elements; key is expansion dimension, value is
408 /// vector of elements of that dimension.
409 typedef std::map<unsigned int, std::vector<ElementSharedPtr> > ElementMap;
410 /// Element factory definition.
412  Element,
413  ElmtConfig,
414  std::vector<NodeSharedPtr>,
415  std::vector<int> > ElementFactory;
416 
417 NEKMESHUTILS_EXPORT ElementFactory &GetElementFactory();
418 
419 NEKMESHUTILS_EXPORT bool operator==(ElementSharedPtr const &e1,
420  ElementSharedPtr const &e2);
421 
422 /// Define element ordering based on ID.
424 {
425  typedef boost::shared_ptr<Element> pT;
426  bool operator()(const pT a, const pT b) const
427  {
428  // check for 0
429  if (a.get() == 0)
430  {
431  // if b is also 0, then they are equal, hence a is not
432  // less than b
433  return b.get() != 0;
434  }
435  else if (b.get() == 0)
436  {
437  return false;
438  }
439  else
440  {
441  return a->GetId() < b->GetId();
442  }
443  }
444 };
445 }
446 }
447 
448 #endif
virtual NEKMESHUTILS_EXPORT void GetCurvedNodes(std::vector< NodeSharedPtr > &nodeList) const
get list of volume interior nodes
Definition: Element.h:259
CADObjectSharedPtr m_parentCAD
Definition: Element.h:372
NEKMESHUTILS_EXPORT unsigned int GetDim() const
Returns the expansion dimension of the element.
Definition: Element.h:76
NEKMESHUTILS_EXPORT std::string GetTag() const
Returns the tag which defines the element shape.
Definition: Element.h:91
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
Basic information about an element.
Definition: ElementConfig.h:50
NEKMESHUTILS_EXPORT unsigned int GetEdgeCount() const
Returns the number of edges.
Definition: Element.h:160
virtual NEKMESHUTILS_EXPORT SpatialDomains::GeometrySharedPtr GetGeom(int coordDim)
Generate a Nektar++ geometry object for this element.
Definition: Element.h:270
NEKMESHUTILS_EXPORT void SetBoundaryLink(int i, int j)
Set a correspondence between edge or face i and its representative boundary element m->element[expDim...
Definition: Element.h:234
NEKMESHUTILS_EXPORT std::string GetXmlCurveString()
Generates a string listing the coordinates of all nodes associated with this element.
Definition: Element.cpp:214
NEKMESHUTILS_EXPORT int GetMaxOrder()
Obtain the order of an element by looking at edges.
Definition: Element.cpp:139
NEKMESHUTILS_EXPORT LibUtilities::PointsType GetCurveType() const
Definition: Element.h:138
Define element ordering based on ID.
Definition: Element.h:423
NEKMESHUTILS_EXPORT void SetEdgeLink(EdgeSharedPtr pLink)
Set a correspondence between this element and an edge (2D boundary element).
Definition: Element.h:212
ElementFactory & GetElementFactory()
Definition: Element.cpp:47
ElmtConfig m_conf
Contains configuration of the element.
Definition: Element.h:380
NEKMESHUTILS_EXPORT unsigned int GetId() const
Returns the ID of the element (or associated edge or face for boundary elements). ...
Definition: Element.h:67
NEKMESHUTILS_EXPORT void SetFace(unsigned int p, FaceSharedPtr pNew)
Replace a face in the element.
Definition: Element.cpp:134
FaceSharedPtr m_faceLink
Pointer to the corresponding face if element is a 3D boundary.
Definition: Element.h:398
NEKMESHUTILS_EXPORT EdgeSharedPtr GetEdge(unsigned int i) const
Access an edge.
Definition: Element.h:105
std::vector< int > m_taglist
List of integers specifying properties of the element.
Definition: Element.h:384
bool operator()(const pT a, const pT b) const
Definition: Element.h:426
bool operator==(ElmtConfig const &c1, ElmtConfig const &c2)
Compares two element config structs.
NEKMESHUTILS_EXPORT void SetVertex(unsigned int p, NodeSharedPtr pNew, bool descend=true)
Replace a vertex in the element.
Definition: Element.cpp:67
NEKMESHUTILS_EXPORT unsigned int GetFaceCount() const
Returns the number of faces.
Definition: Element.h:165
NEKMESHUTILS_EXPORT unsigned int GetNodeCount()
Returns the total number of nodes (vertices, edge nodes and face nodes and volume nodes)...
Definition: Element.cpp:155
std::map< int, int > m_boundaryLinks
Array mapping faces/edges to the location of the appropriate boundary elements in m->element...
Definition: Element.h:401
NEKMESHUTILS_EXPORT void SetCurveType(LibUtilities::PointsType cT)
Definition: Element.h:142
boost::shared_ptr< Element > pT
Definition: Element.h:425
EdgeSharedPtr m_edgeLink
Pointer to the corresponding edge if element is a 2D boundary.
Definition: Element.h:396
NEKMESHUTILS_EXPORT void SetTagList(const std::vector< int > &tags)
Set the list of tags associated with this element.
Definition: Element.h:252
NEKMESHUTILS_EXPORT std::vector< NodeSharedPtr > GetVertexList() const
Access the list of vertex nodes.
Definition: Element.h:115
std::vector< NodeSharedPtr > m_vertex
List of element vertex nodes.
Definition: Element.h:386
unsigned int m_dim
Dimension of the element.
Definition: Element.h:378
NEKMESHUTILS_EXPORT NodeSharedPtr GetVertex(unsigned int i) const
Access a vertex node.
Definition: Element.h:100
NEKMESHUTILS_EXPORT FaceSharedPtr GetFace(unsigned int i) const
Access a face.
Definition: Element.h:110
virtual NEKMESHUTILS_EXPORT Array< OneD, NekDouble > Normal(bool inward=false)
returns the normal to the element
Definition: Element.h:365
std::vector< EdgeSharedPtr > m_edge
List of element edges.
Definition: Element.h:388
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
NEKMESHUTILS_EXPORT int GetBoundaryLink(int i)
Get the location of the boundary face/edge i for this element.
Definition: Element.h:239
virtual NEKMESHUTILS_EXPORT StdRegions::Orientation GetEdgeOrient(int edgeId, EdgeSharedPtr edge)
Get the edge orientation of edge with respect to the local element, which lies at edge index edgeId...
Definition: Element.h:316
std::vector< NodeSharedPtr > m_volumeNodes
List of element volume nodes.
Definition: Element.h:392
NEKMESHUTILS_EXPORT void SetVolumeNodes(std::vector< NodeSharedPtr > &nodes)
Definition: Element.h:134
boost::shared_ptr< CADObject > CADObjectSharedPtr
Definition: CADObject.h:112
std::string m_tag
Tag character describing the element.
Definition: Element.h:382
NEKMESHUTILS_EXPORT EdgeSharedPtr GetEdgeLink()
Get correspondence between this element and an edge.
Definition: Element.h:217
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:135
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
SpatialDomains::GeometrySharedPtr m_geom
Nektar++ geometry object for this element.
Definition: Element.h:403
virtual NEKMESHUTILS_EXPORT std::string GetXmlString()
Generate a list of vertices (1D), edges (2D), or faces (3D).
Definition: Element.cpp:187
NEKMESHUTILS_EXPORT void SetEdge(unsigned int p, EdgeSharedPtr pNew, bool descend=true)
Replace an edge in the element.
Definition: Element.cpp:112
NEKMESHUTILS_EXPORT void SetFaceLink(FaceSharedPtr pLink)
Set a correspondence between this element and a face (3D boundary element).
Definition: Element.h:223
NEKMESHUTILS_EXPORT std::vector< EdgeSharedPtr > GetEdgeList() const
Access the list of edges.
Definition: Element.h:120
NEKMESHUTILS_EXPORT Element(ElmtConfig pConf, unsigned int pNumNodes, unsigned int pGotNodes)
Definition: Element.cpp:54
unsigned int m_id
ID of the element.
Definition: Element.h:376
NEKMESHUTILS_EXPORT std::vector< NodeSharedPtr > GetVolumeNodes() const
Access the list of volume nodes.
Definition: Element.h:130
#define NEKMESHUTILS_EXPORT
std::map< unsigned int, std::vector< ElementSharedPtr > > ElementMap
Container for elements; key is expansion dimension, value is vector of elements of that dimension...
Definition: Element.h:409
NEKMESHUTILS_EXPORT void SetId(unsigned int p)
Change the ID of the element.
Definition: Element.h:170
virtual NEKMESHUTILS_EXPORT void MakeOrder(int order, SpatialDomains::GeometrySharedPtr geom, LibUtilities::PointsType edgeType, int coordDim, int &id, bool justConfig=false)
Insert interior (i.e. volume) points into this element to make the geometry an order order representa...
Definition: Element.h:300
LibUtilities::PointsType m_curveType
Volume curve type.
Definition: Element.h:394
std::vector< FaceSharedPtr > m_face
List of element faces.
Definition: Element.h:390
NEKMESHUTILS_EXPORT std::vector< FaceSharedPtr > GetFaceList() const
Access the list of faces.
Definition: Element.h:125
NEKMESHUTILS_EXPORT void Print()
Definition: Element.h:334
NEKMESHUTILS_EXPORT std::vector< int > GetTagList() const
Access the list of tags associated with this element.
Definition: Element.h:150
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
NEKMESHUTILS_EXPORT ElmtConfig GetConf() const
Returns the configuration of the element.
Definition: Element.h:81
boost::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:148
Nektar::LibUtilities::NekFactory< LibUtilities::ShapeType, Element, ElmtConfig, std::vector< NodeSharedPtr >, std::vector< int > > ElementFactory
Element factory definition.
Definition: Element.h:415
NEKMESHUTILS_EXPORT LibUtilities::ShapeType GetShapeType() const
returns the shapetype
Definition: Element.h:86
boost::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
NEKMESHUTILS_EXPORT FaceSharedPtr GetFaceLink()
Get correspondence between this element and a face.
Definition: Element.h:228
LibUtilities::ShapeType m_e
Element type (e.g. triangle, quad, etc).
Definition: ElementConfig.h:77
virtual NEKMESHUTILS_EXPORT int GetFaceVertex(int i, int j)
Returns the local index of vertex j of face i.
Definition: Element.h:327
Base class for element definitions.
Definition: Element.h:59
Provides a generic Factory class.
Definition: NekFactory.hpp:116
NEKMESHUTILS_EXPORT unsigned int GetVertexCount() const
Returns the number of vertices.
Definition: Element.h:155