Nektar++
Pyramid.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Pyramid.cpp
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: Mesh pyramid object.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <SpatialDomains/PyrGeom.h>
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42 namespace NekMeshUtils
43 {
44 
45 LibUtilities::ShapeType Pyramid::type =
47  LibUtilities::ePyramid, Pyramid::create, "Pyramid");
48 
49 /// Vertex IDs that make up pyramid faces.
50 int Pyramid::m_faceIds[5][4] = {
51  {0, 1, 2, 3}, {0, 1, 4, -1}, {1, 2, 4, -1}, {3, 2, 4, -1}, {0, 3, 4, -1}
52 };
53 
54 /**
55  * @brief Create a pyramidic element.
56  */
57 Pyramid::Pyramid(ElmtConfig pConf,
58  vector<NodeSharedPtr> pNodeList,
59  vector<int> pTagList)
60  : Element(pConf, GetNumNodes(pConf), pNodeList.size())
61 {
62  m_tag = "P";
63  m_dim = 3;
64  m_taglist = pTagList;
65  int n = m_conf.m_order - 1;
66 
67  // This edge-node map is based on Nektar++ ordering.
68  map<pair<int, int>, int> edgeNodeMap;
69  map<pair<int, int>, int>::iterator it;
70  edgeNodeMap[pair<int, int>(1, 2)] = 6;
71  edgeNodeMap[pair<int, int>(2, 3)] = 6 + n;
72  edgeNodeMap[pair<int, int>(4, 3)] = 6 + 2 * n;
73  edgeNodeMap[pair<int, int>(1, 4)] = 6 + 3 * n;
74  edgeNodeMap[pair<int, int>(1, 5)] = 6 + 4 * n;
75  edgeNodeMap[pair<int, int>(2, 5)] = 6 + 5 * n;
76  edgeNodeMap[pair<int, int>(3, 5)] = 6 + 6 * n;
77  edgeNodeMap[pair<int, int>(4, 5)] = 6 + 7 * n;
78 
79  // Add vertices
80  for (int i = 0; i < 5; ++i)
81  {
82  m_vertex.push_back(pNodeList[i]);
83  }
84 
85  // Create edges (with corresponding set of edge points)
86  int eid = 0;
87  for (it = edgeNodeMap.begin(); it != edgeNodeMap.end(); ++it)
88  {
89  vector<NodeSharedPtr> edgeNodes;
90  if (m_conf.m_order > 1)
91  {
92  for (int j = it->second; j < it->second + n; ++j)
93  {
94  edgeNodes.push_back(pNodeList[j - 1]);
95  }
96  }
97  m_edge.push_back(EdgeSharedPtr(new Edge(pNodeList[it->first.first - 1],
98  pNodeList[it->first.second - 1],
99  edgeNodes,
101  m_edge.back()->m_id = eid++;
102  }
103 
104  // Create faces
105  int face_edges[5][4];
106  int faceoffset = 5 + 8 * n;
107  for (int j = 0; j < 5; ++j)
108  {
109  vector<NodeSharedPtr> faceVertices;
110  vector<EdgeSharedPtr> faceEdges;
111  vector<NodeSharedPtr> faceNodes;
112  int nEdge = j > 0 ? 3 : 4;
113 
114  for (int k = 0; k < nEdge; ++k)
115  {
116  faceVertices.push_back(m_vertex[m_faceIds[j][k]]);
117  NodeSharedPtr a = m_vertex[m_faceIds[j][k]];
118  NodeSharedPtr b = m_vertex[m_faceIds[j][(k + 1) % nEdge]];
119  for (unsigned int i = 0; i < m_edge.size(); ++i)
120  {
121  if ((m_edge[i]->m_n1 == a && m_edge[i]->m_n2 == b) ||
122  (m_edge[i]->m_n1 == b && m_edge[i]->m_n2 == a))
123  {
124  faceEdges.push_back(m_edge[i]);
125  face_edges[j][k] = i;
126  break;
127  }
128  }
129  }
130 
131  if (m_conf.m_faceNodes)
132  {
133  int facenodes = j == 0 ? n * n : n * (n - 1) / 2;
134  for (int i = 0; i < facenodes; ++i)
135  {
136  faceNodes.push_back(pNodeList[faceoffset + i]);
137  }
138  faceoffset += facenodes;
139  }
140  m_face.push_back(FaceSharedPtr(new Face(
141  faceVertices, faceNodes, faceEdges, m_conf.m_faceCurveType)));
142  }
143 
144  // Reorder edges to align with Nektar++ order.
145  vector<EdgeSharedPtr> tmp(8);
146  tmp[0] = m_edge[face_edges[0][0]];
147  tmp[1] = m_edge[face_edges[0][1]];
148  tmp[2] = m_edge[face_edges[0][2]];
149  tmp[3] = m_edge[face_edges[0][3]];
150  tmp[4] = m_edge[face_edges[1][2]];
151  tmp[5] = m_edge[face_edges[1][1]];
152  tmp[6] = m_edge[face_edges[3][1]];
153  tmp[7] = m_edge[face_edges[3][2]];
154  m_edge = tmp;
155 }
156 
158 {
160 
161  for (int i = 0; i < 5; ++i)
162  {
163  faces[i] = m_face[i]->GetGeom(coordDim);
164  }
165 
167  m_id, faces);
168  m_geom->Setup();
169 
170  return m_geom;
171 }
172 
173 /**
174  * @brief Return the number of nodes defining a pyramid.
175  */
176 unsigned int Pyramid::GetNumNodes(ElmtConfig pConf)
177 {
178  int n = pConf.m_order;
179 
180  if (pConf.m_faceNodes)
181  {
182  // @todo currently only valid for 2nd order pyramids
183  return 5 + 8 * (n - 1) + (n - 1)*(n - 1);
184  }
185  else
186  {
187  return 5 + 8 * (n - 1);
188  }
189 }
190 }
191 }
bool m_faceNodes
Denotes whether the element contains face nodes. For 2D elements, if this is true then the element co...
Definition: ElementConfig.h:81
Basic information about an element.
Definition: ElementConfig.h:49
LibUtilities::PointsType m_faceCurveType
Distribution of points in faces.
Definition: ElementConfig.h:95
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
Definition: Geometry.h:65
Represents an edge which joins two points.
Definition: Edge.h:58
Represents a face comprised of three or more edges.
Definition: Face.h:63
STL namespace.
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
virtual NEKMESHUTILS_EXPORT SpatialDomains::GeometrySharedPtr GetGeom(int coordDim)
Generate a Nektar++ geometry object for this element.
Definition: Pyramid.cpp:157
ElementFactory & GetElementFactory()
Definition: Element.cpp:44
ElmtConfig m_conf
Contains configuration of the element.
Definition: Element.h:462
std::shared_ptr< Node > NodeSharedPtr
Definition: CADVert.h:49
std::vector< int > m_taglist
List of integers specifying properties of the element.
Definition: Element.h:466
std::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:155
LibUtilities::PointsType m_edgeCurveType
Distribution of points in edges.
Definition: ElementConfig.h:93
unsigned int m_order
Order of the element.
Definition: ElementConfig.h:88
std::vector< NodeSharedPtr > m_vertex
List of element vertex nodes.
Definition: Element.h:468
unsigned int m_dim
Dimension of the element.
Definition: Element.h:460
std::vector< EdgeSharedPtr > m_edge
List of element edges.
Definition: Element.h:470
std::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::string m_tag
Tag character describing the element.
Definition: Element.h:464
SpatialDomains::GeometrySharedPtr m_geom
Nektar++ geometry object for this element.
Definition: Element.h:485
unsigned int m_id
ID of the element.
Definition: Element.h:458
static NEKMESHUTILS_EXPORT unsigned int GetNumNodes(ElmtConfig pConf)
Return the number of nodes defining a pyramid.
Definition: Pyramid.cpp:176
std::vector< FaceSharedPtr > m_face
List of element faces.
Definition: Element.h:472
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
static int m_faceIds[5][4]
Vertex IDs that make up pyramid faces.
Definition: Pyramid.h:83
Base class for element definitions.
Definition: Element.h:60