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