Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // 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: Hexahedral elements
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <SpatialDomains/HexGeom.h>
38 
39 using namespace std;
40 
41 namespace Nektar
42 {
43 namespace NekMeshUtils
44 {
45 
46 LibUtilities::ShapeType Hexahedron::m_type =
48  LibUtilities::eHexahedron, Hexahedron::create, "Hexahedron");
49 
50 /**
51  * @brief Create a hexahedral element.
52  */
53 Hexahedron::Hexahedron(ElmtConfig pConf,
54  vector<NodeSharedPtr> pNodeList,
55  vector<int> pTagList)
56  : Element(pConf, GetNumNodes(pConf), pNodeList.size())
57 {
58  m_tag = "H";
59  m_dim = 3;
60  m_taglist = pTagList;
61  int n = m_conf.m_order - 1;
62 
63  // Create a map to relate edge nodes to a pair of vertices defining an edge
64  // This is based on the ordering produced by gmsh.
65  map<pair<int, int>, int> edgeNodeMap;
66  map<pair<int, int>, int>::iterator it;
67  edgeNodeMap[pair<int, int>(1, 2)] = 9;
68  edgeNodeMap[pair<int, int>(2, 3)] = 9 + n;
69  edgeNodeMap[pair<int, int>(3, 4)] = 9 + 2 * n;
70  edgeNodeMap[pair<int, int>(4, 1)] = 9 + 3 * n;
71  edgeNodeMap[pair<int, int>(1, 5)] = 9 + 4 * n;
72  edgeNodeMap[pair<int, int>(2, 6)] = 9 + 5 * n;
73  edgeNodeMap[pair<int, int>(3, 7)] = 9 + 6 * n;
74  edgeNodeMap[pair<int, int>(4, 8)] = 9 + 7 * n;
75  edgeNodeMap[pair<int, int>(5, 6)] = 9 + 8 * n;
76  edgeNodeMap[pair<int, int>(6, 7)] = 9 + 9 * n;
77  edgeNodeMap[pair<int, int>(7, 8)] = 9 + 10 * n;
78  edgeNodeMap[pair<int, int>(8, 5)] = 9 + 11 * n;
79 
80  // Add vertices
81  for (int i = 0; i < 8; ++i)
82  {
83  m_vertex.push_back(pNodeList[i]);
84  }
85 
86  // Create edges (with corresponding set of edge points)
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  }
102 
103  // Create faces
104  int face_edges[6][4];
105  int face_ids[6][4] = {{0, 1, 2, 3},
106  {0, 1, 5, 4},
107  {1, 2, 6, 5},
108  {3, 2, 6, 7},
109  {0, 3, 7, 4},
110  {4, 5, 6, 7}};
111  for (int j = 0; j < 6; ++j)
112  {
113  vector<NodeSharedPtr> faceVertices;
114  vector<EdgeSharedPtr> faceEdges;
115  vector<NodeSharedPtr> faceNodes;
116  for (int k = 0; k < 4; ++k)
117  {
118  faceVertices.push_back(m_vertex[face_ids[j][k]]);
119  NodeSharedPtr a = m_vertex[face_ids[j][k]];
120  NodeSharedPtr b = m_vertex[face_ids[j][(k + 1) % 4]];
121  for (unsigned int i = 0; i < m_edge.size(); ++i)
122  {
123  if (((*(m_edge[i]->m_n1) == *a) &&
124  (*(m_edge[i]->m_n2) == *b)) ||
125  ((*(m_edge[i]->m_n1) == *b) && (*(m_edge[i]->m_n2) == *a)))
126  {
127  face_edges[j][k] = i;
128  faceEdges.push_back(m_edge[i]);
129  break;
130  }
131  }
132  }
133 
134  if (m_conf.m_faceNodes)
135  {
136  int N = 8 + 12 * n + j * n * n;
137  for (int i = 0; i < n * n; ++i)
138  {
139  faceNodes.push_back(pNodeList[N + i]);
140  }
141  }
142  m_face.push_back(FaceSharedPtr(new Face(
143  faceVertices, faceNodes, faceEdges, m_conf.m_faceCurveType)));
144  }
145 
146  // Reorder edges to be consistent with Nektar++ ordering.
147  vector<EdgeSharedPtr> tmp(12);
148  tmp[0] = m_edge[face_edges[0][0]];
149  tmp[1] = m_edge[face_edges[0][1]];
150  tmp[2] = m_edge[face_edges[0][2]];
151  tmp[3] = m_edge[face_edges[0][3]];
152  tmp[4] = m_edge[face_edges[1][3]];
153  tmp[5] = m_edge[face_edges[1][1]];
154  tmp[6] = m_edge[face_edges[2][1]];
155  tmp[7] = m_edge[face_edges[4][1]];
156  tmp[8] = m_edge[face_edges[5][0]];
157  tmp[9] = m_edge[face_edges[5][1]];
158  tmp[10] = m_edge[face_edges[5][2]];
159  tmp[11] = m_edge[face_edges[5][3]];
160  m_edge = tmp;
161 }
162 
164 {
167 
168  for (int i = 0; i < 6; ++i)
169  {
170  faces[i] = boost::dynamic_pointer_cast<SpatialDomains::QuadGeom>(
171  m_face[i]->GetGeom(coordDim));
172  }
173 
175 
176  return ret;
177 }
178 
179 /**
180  * @brief Return the number of nodes defining a hexahedron.
181  */
183 {
184  int n = pConf.m_order;
185  if (pConf.m_faceNodes && pConf.m_volumeNodes)
186  return (n + 1) * (n + 1) * (n + 1);
187  else if (pConf.m_faceNodes && !pConf.m_volumeNodes)
188  return 6 * (n + 1) * (n + 1) - 12 * (n + 1) + 8;
189  else
190  return 12 * (n + 1) - 16;
191 }
192 }
193 }
bool m_faceNodes
Denotes whether the element contains face nodes. For 2D elements, if this is true then the element co...
Definition: Element.h:89
Basic information about an element.
Definition: Element.h:58
LibUtilities::PointsType m_faceCurveType
Distribution of points in faces.
Definition: Element.h:103
Represents an edge which joins two points.
Definition: Edge.h:61
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
boost::shared_ptr< QuadGeom > QuadGeomSharedPtr
Definition: QuadGeom.h:54
Represents a face comprised of three or more edges.
Definition: Face.h:60
STL namespace.
boost::shared_ptr< HexGeom > HexGeomSharedPtr
Definition: HexGeom.h:110
ElementFactory & GetElementFactory()
Definition: Element.cpp:47
ElmtConfig m_conf
Contains configuration of the element.
Definition: Element.h:496
std::vector< int > m_taglist
List of integers specifying properties of the element.
Definition: Element.h:500
LibUtilities::PointsType m_edgeCurveType
Distribution of points in edges.
Definition: Element.h:101
unsigned int m_order
Order of the element.
Definition: Element.h:96
std::vector< NodeSharedPtr > m_vertex
List of element vertex nodes.
Definition: Element.h:502
unsigned int m_dim
Dimension of the element.
Definition: Element.h:494
bool m_volumeNodes
Denotes whether the element contains volume (i.e. interior) nodes. These are not supported by either ...
Definition: Element.h:94
std::vector< EdgeSharedPtr > m_edge
List of element edges.
Definition: Element.h:504
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
static NEKMESHUTILS_EXPORT unsigned int GetNumNodes(ElmtConfig pConf)
Return the number of nodes defining a hexahedron.
Definition: Hexahedron.cpp:182
std::string m_tag
Tag character describing the element.
Definition: Element.h:498
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:196
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::vector< FaceSharedPtr > m_face
List of element faces.
Definition: Element.h:506
boost::shared_ptr< Face > FaceSharedPtr
Shared pointer to a face.
Definition: Face.h:378
virtual NEKMESHUTILS_EXPORT SpatialDomains::GeometrySharedPtr GetGeom(int coordDim)
Generate a Nektar++ geometry object for this element.
Definition: Hexahedron.cpp:163
boost::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
Base class for element definitions.
Definition: Element.h:115
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215