Nektar++
Hexahedron.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Hexahedron.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: Hexahedral elements
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <SpatialDomains/HexGeom.h>
37 
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44 namespace NekMeshUtils
45 {
46 
47 LibUtilities::ShapeType Hexahedron::m_type =
49  LibUtilities::eHexahedron, Hexahedron::create, "Hexahedron");
50 
51 /// Vertex IDs that make up hexahedron faces.
52 int Hexahedron::m_faceIds[6][4] = {
53  {0, 1, 2, 3}, {0, 1, 5, 4}, {1, 2, 6, 5},
54  {3, 2, 6, 7}, {0, 3, 7, 4}, {4, 5, 6, 7}
55 };
56 
57 Hexahedron::Hexahedron(ElmtConfig pConf,
58  vector<NodeSharedPtr> pNodeList,
59  vector<int> pTagList)
60  : Element(pConf, GetNumNodes(pConf), pNodeList.size())
61 {
62  m_tag = "H";
63  m_dim = 3;
64  m_taglist = pTagList;
65  int n = m_conf.m_order - 1;
66 
67  // Create a map to relate edge nodes to a pair of vertices defining an edge
68  // This is based on the ordering produced by gmsh.
69  map<pair<int, int>, int> edgeNodeMap;
70  map<pair<int, int>, int>::iterator it;
71  edgeNodeMap[pair<int, int>(1, 2)] = 9;
72  edgeNodeMap[pair<int, int>(2, 3)] = 9 + n;
73  edgeNodeMap[pair<int, int>(3, 4)] = 9 + 2 * n;
74  edgeNodeMap[pair<int, int>(4, 1)] = 9 + 3 * n;
75  edgeNodeMap[pair<int, int>(1, 5)] = 9 + 4 * n;
76  edgeNodeMap[pair<int, int>(2, 6)] = 9 + 5 * n;
77  edgeNodeMap[pair<int, int>(3, 7)] = 9 + 6 * n;
78  edgeNodeMap[pair<int, int>(4, 8)] = 9 + 7 * n;
79  edgeNodeMap[pair<int, int>(5, 6)] = 9 + 8 * n;
80  edgeNodeMap[pair<int, int>(6, 7)] = 9 + 9 * n;
81  edgeNodeMap[pair<int, int>(7, 8)] = 9 + 10 * n;
82  edgeNodeMap[pair<int, int>(8, 5)] = 9 + 11 * n;
83 
84  // Add vertices
85  for (int i = 0; i < 8; ++i)
86  {
87  m_vertex.push_back(pNodeList[i]);
88  }
89 
90  // Create edges (with corresponding set of edge points)
91  for (it = edgeNodeMap.begin(); it != edgeNodeMap.end(); ++it)
92  {
93  vector<NodeSharedPtr> edgeNodes;
94  if (m_conf.m_order > 1)
95  {
96  for (int j = it->second; j < it->second + n; ++j)
97  {
98  edgeNodes.push_back(pNodeList[j - 1]);
99  }
100  }
101  m_edge.push_back(EdgeSharedPtr(new Edge(pNodeList[it->first.first - 1],
102  pNodeList[it->first.second - 1],
103  edgeNodes,
105  }
106 
107  // Create faces
108  int face_edges[6][4];
109  for (int j = 0; j < 6; ++j)
110  {
111  vector<NodeSharedPtr> faceVertices;
112  vector<EdgeSharedPtr> faceEdges;
113  vector<NodeSharedPtr> faceNodes;
114  for (int k = 0; k < 4; ++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) % 4]];
119  for (unsigned int i = 0; i < m_edge.size(); ++i)
120  {
121  if (((*(m_edge[i]->m_n1) == *a) &&
122  (*(m_edge[i]->m_n2) == *b)) ||
123  ((*(m_edge[i]->m_n1) == *b) && (*(m_edge[i]->m_n2) == *a)))
124  {
125  face_edges[j][k] = i;
126  faceEdges.push_back(m_edge[i]);
127  break;
128  }
129  }
130  }
131 
132  if (m_conf.m_faceNodes)
133  {
134  int N = 8 + 12 * n + j * n * n;
135  for (int i = 0; i < n * n; ++i)
136  {
137  faceNodes.push_back(pNodeList[N + i]);
138  }
139  }
140  m_face.push_back(FaceSharedPtr(new Face(
141  faceVertices, faceNodes, faceEdges, m_conf.m_faceCurveType)));
142  }
143 
144  // Reorder edges to be consistent with Nektar++ ordering.
145  vector<EdgeSharedPtr> tmp(12);
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][3]];
151  tmp[5] = m_edge[face_edges[1][1]];
152  tmp[6] = m_edge[face_edges[2][1]];
153  tmp[7] = m_edge[face_edges[4][1]];
154  tmp[8] = m_edge[face_edges[5][0]];
155  tmp[9] = m_edge[face_edges[5][1]];
156  tmp[10] = m_edge[face_edges[5][2]];
157  tmp[11] = m_edge[face_edges[5][3]];
158  m_edge = tmp;
159 }
160 
162 {
165 
166  for (int i = 0; i < 6; ++i)
167  {
168  faces[i] = std::dynamic_pointer_cast<SpatialDomains::QuadGeom>(
169  m_face[i]->GetGeom(coordDim));
170  }
171 
173  m_id, faces);
174 
175  ret->Setup();
176  return ret;
177 }
178 
180  int edgeId, EdgeSharedPtr edge)
181 {
182  static int edgeVerts[12][2] = { {0,1}, {1,2}, {2,3}, {3,0}, {0,4}, {1,5},
183  {2,6}, {3,7}, {4,5}, {5,6}, {6,7}, {7,4} };
184 
185  if (edge->m_n1 == m_vertex[edgeVerts[edgeId][0]])
186  {
187  return StdRegions::eForwards;
188  }
189  else if (edge->m_n1 == m_vertex[edgeVerts[edgeId][1]])
190  {
191  return StdRegions::eBackwards;
192  }
193  else
194  {
195  ASSERTL1(false, "Edge is not connected to this hexahedron.");
196  }
197 
199 }
200 
201 void Hexahedron::MakeOrder(int order,
204  int coordDim,
205  int &id,
206  bool justConfig)
207 {
208  m_curveType = pType;
209  m_conf.m_order = order;
210  m_volumeNodes.clear();
211 
212  if (order == 1)
213  {
215  return;
216  }
217 
218  m_conf.m_faceNodes = true;
219  m_conf.m_volumeNodes = true;
220 
221  if (justConfig)
222  {
223  return;
224  }
225 
226  int nPoints = order + 1;
227  StdRegions::StdExpansionSharedPtr xmap = geom->GetXmap();
228 
230  LibUtilities::PointsKey pKey(nPoints, pType);
231  ASSERTL1(pKey.GetPointsDim() == 1, "Points distribution must be 1D");
232  LibUtilities::PointsManager()[pKey]->GetPoints(px);
233 
234  Array<OneD, Array<OneD, NekDouble> > phys(coordDim);
235 
236  for (int i = 0; i < coordDim; ++i)
237  {
238  phys[i] = Array<OneD, NekDouble>(xmap->GetTotPoints());
239  xmap->BwdTrans(geom->GetCoeffs(i), phys[i]);
240  }
241 
242  int nHexIntPts = (nPoints - 2) * (nPoints - 2) * (nPoints - 2);
243  m_volumeNodes.resize(nHexIntPts);
244 
245  for (int i = 1, cnt = 0; i < nPoints-1; ++i)
246  {
247  for (int j = 1; j < nPoints-1; ++j)
248  {
249  for (int k = 1; k < nPoints-1; ++k, ++cnt)
250  {
252  xp[0] = px[k];
253  xp[1] = px[j];
254  xp[2] = px[i];
255 
256  Array<OneD, NekDouble> x(3, 0.0);
257  for (int k = 0; k < coordDim; ++k)
258  {
259  x[k] = xmap->PhysEvaluate(xp, phys[k]);
260  }
261 
262  m_volumeNodes[cnt] = std::shared_ptr<Node>(
263  new Node(id++, x[0], x[1], x[2]));
264  }
265  }
266  }
267 }
268 
269 /**
270  * @brief Return the number of nodes defining a hexahedron.
271  */
273 {
274  int n = pConf.m_order;
275  if (pConf.m_faceNodes && pConf.m_volumeNodes)
276  return (n + 1) * (n + 1) * (n + 1);
277  else if (pConf.m_faceNodes && !pConf.m_volumeNodes)
278  return 6 * (n + 1) * (n + 1) - 12 * (n + 1) + 8;
279  else
280  return 12 * (n + 1) - 16;
281 }
282 }
283 }
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
static int m_faceIds[6][4]
Vertex IDs that make up hexahedron faces.
Definition: Hexahedron.h:94
LibUtilities::PointsType m_faceCurveType
Distribution of points in faces.
Definition: ElementConfig.h:95
Represents an edge which joins two points.
Definition: Edge.h:58
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: Hexahedron.cpp:179
Represents a face comprised of three or more edges.
Definition: Face.h:63
std::shared_ptr< QuadGeom > QuadGeomSharedPtr
Definition: HexGeom.h:46
STL namespace.
unsigned int GetPointsDim() const
Definition: Points.h:150
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
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::shared_ptr< StdExpansion > StdExpansionSharedPtr
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
bool m_volumeNodes
Denotes whether the element contains volume (i.e. interior) nodes. These are not supported by either ...
Definition: ElementConfig.h:86
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.
PointsManagerT & PointsManager(void)
virtual NEKMESHUTILS_EXPORT void MakeOrder(int order, SpatialDomains::GeometrySharedPtr geom, LibUtilities::PointsType pType, 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: Hexahedron.cpp:201
Defines a specification for a set of points.
Definition: Points.h:59
std::vector< NodeSharedPtr > m_volumeNodes
List of element volume nodes.
Definition: Element.h:474
static NEKMESHUTILS_EXPORT unsigned int GetNumNodes(ElmtConfig pConf)
Return the number of nodes defining a hexahedron.
Definition: Hexahedron.cpp:272
std::string m_tag
Tag character describing the element.
Definition: Element.h:464
std::shared_ptr< HexGeom > HexGeomSharedPtr
Definition: HexGeom.h:90
unsigned int m_id
ID of the element.
Definition: Element.h:458
LibUtilities::PointsType m_curveType
Volume curve type.
Definition: Element.h:476
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
virtual NEKMESHUTILS_EXPORT SpatialDomains::GeometrySharedPtr GetGeom(int coordDim)
Generate a Nektar++ geometry object for this element.
Definition: Hexahedron.cpp:161
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
Base class for element definitions.
Definition: Element.h:60