Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Mesh.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Mesh.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: Mesh object.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44 namespace NekMeshUtils
45 {
46 
47 /**
48  * @brief Return the number of elements of the expansion dimension.
49  */
50 unsigned int Mesh::GetNumElements()
51 {
52  return m_element[m_expDim].size();
53 }
54 
55 /**
56  * @brief Return the number of boundary elements (i.e. one below the
57  * expansion dimension).
58  */
59 unsigned int Mesh::GetNumBndryElements()
60 {
61  unsigned int i, nElmt = 0;
62 
63  for (i = 0; i < m_expDim; ++i)
64  nElmt += m_element[i].size();
65 
66  return nElmt;
67 }
68 
69 /**
70  * @brief Return the total number of entities in the mesh (i.e. all
71  * elements, regardless of dimension).
72  */
73 unsigned int Mesh::GetNumEntities()
74 {
75  unsigned int nEnt = 0;
76 
77  for (unsigned int d = 0; d <= m_expDim; ++d)
78  {
79  nEnt += m_element[d].size();
80  }
81 
82  return nEnt;
83 }
84 
85 /**
86  * @brief Convert this mesh into a mesh of uniform polynomial order @p order
87  * with a curve point distribution @p distType.
88  *
89  * This routine adds curvature points into a mesh so that the resulting elements
90  * are all of a uniform order @p order and all high-order vertices are
91  * consistently ordered. It proceeds in a bottom-up fashion:
92  *
93  * - First construct all edge, face and elemental geometry mappings.
94  * - Then call the local MakeOrder functions on each edge, face and element of
95  * dimension Mesh::m_expDim.
96  * - Finally, any boundary elements are updated so that they have the same
97  * interior degrees of freedom as their corresponding edge or face links.
98  */
99 void Mesh::MakeOrder(int order, LibUtilities::PointsType distType)
100 {
101  // Going to make a copy of the curavture information, since this is cheaper
102  // than using Nektar's Geometry objects. Currently, the geometry objects
103  // which make up a 3D element dont use the volume nodes, they are just
104  // stored, so we can get away without copying them.
105 
106  int id = m_vertexSet.size();
107 
108  EdgeSet::iterator eit;
109  FaceSet::iterator fit;
110 
111  boost::unordered_map<int, EdgeSharedPtr> edgeCopies;
112  boost::unordered_map<int, FaceSharedPtr> faceCopies;
113 
114  // Decide on distribution of points to use for each shape type based on the
115  // input we've been supplied.
116  std::map<LibUtilities::ShapeType, LibUtilities::PointsType> pTypes;
117  if (distType == LibUtilities::ePolyEvenlySpaced)
118  {
126  }
127  else if (distType == LibUtilities::eGaussLobattoLegendre)
128  {
136  }
137  else
138  {
139  ASSERTL1(false, "Mesh::MakeOrder does not support this points type.");
140  }
141 
142  // Begin by copying mesh objects for edges and faces so that we don't affect
143  // any neighbouring elements in the mesh as we process each element. At the
144  // same time we delete the curvature from the original edge and face, which
145  // will be re-added with the MakeOrder routine.
146 
147  // First, we fill in the volume-interior nodes. This preserves the original
148  // curvature of the mesh.
149  const int nElmt = m_element[m_expDim].size();
150  int tmpId = 0;
151  for (int i = 0; i < nElmt; ++i)
152  {
153  if (m_verbose)
154  {
155  LibUtilities::PrintProgressbar(i, nElmt, "MakeOrder: Elements: ");
156  }
157  ElementSharedPtr el = m_element[m_expDim][i];
158  SpatialDomains::GeometrySharedPtr geom = el->GetGeom(m_spaceDim);
159  geom->FillGeom();
160  el->MakeOrder(order, geom, pTypes[el->GetConf().m_e], m_spaceDim, tmpId);
161  }
162 
163  // Now make copies of each of the edges.
164  for (eit = m_edgeSet.begin(); eit != m_edgeSet.end(); eit++)
165  {
166  edgeCopies[(*eit)->m_id] = EdgeSharedPtr(new Edge(*(*eit)));
167  (*eit)->m_edgeNodes.clear();
168  }
169 
170  // Now copy faces. Make sure that this is a "deep copy", so that the face's
171  // edge list corresponds to the copied edges, otherwise we end up in a
172  // non-consistent state.
173  for (fit = m_faceSet.begin(); fit != m_faceSet.end(); fit++)
174  {
175  FaceSharedPtr tmpFace = FaceSharedPtr(new Face(*(*fit)));
176 
177  for (int i = 0; i < tmpFace->m_edgeList.size(); ++i)
178  {
179  tmpFace->m_edgeList[i] = edgeCopies[tmpFace->m_edgeList[i]->m_id];
180  }
181 
182  faceCopies[(*fit)->m_id] = tmpFace;
183  (*fit)->m_faceNodes.clear();
184  }
185 
186  boost::unordered_set<int> processedEdges, processedFaces, processedVolumes;
187 
188  // note if CAD previously existed on the face or edge, the new points need
189  // to be projected onto the CAD entity.
190 
191  // Call MakeOrder with our generated geometries on each edge to fill in edge
192  // interior nodes.
193  int ct = 0;
194  for (eit = m_edgeSet.begin(); eit != m_edgeSet.end(); eit++, ct++)
195  {
196  if (m_verbose)
197  {
198  LibUtilities::PrintProgressbar(ct, m_edgeSet.size(),
199  "MakeOrder: Edges: ");
200  }
201  int edgeId = (*eit)->m_id;
202 
203  if (processedEdges.find(edgeId) != processedEdges.end())
204  {
205  continue;
206  }
207 
208  EdgeSharedPtr cpEdge = edgeCopies[edgeId];
209  SpatialDomains::GeometrySharedPtr geom = cpEdge->GetGeom(m_spaceDim);
210  geom->FillGeom();
211 
212  (*eit)->MakeOrder(order, geom, pTypes[LibUtilities::eSegment],
213  m_spaceDim, id);
214  processedEdges.insert(edgeId);
215  }
216 
217  // Call MakeOrder with our generated geometries on each face to fill in face
218  // interior nodes.
219  ct = 0;
220  for (fit = m_faceSet.begin(); fit != m_faceSet.end(); fit++, ct++)
221  {
222  if (m_verbose)
223  {
224  LibUtilities::PrintProgressbar(ct, m_faceSet.size(),
225  "MakeOrder: Faces: ");
226  }
227  int faceId = (*fit)->m_id;
228 
229  if (processedFaces.find(faceId) != processedFaces.end())
230  {
231  continue;
232  }
233 
234  FaceSharedPtr cpFace = faceCopies[faceId];
235  SpatialDomains::GeometrySharedPtr geom = cpFace->GetGeom(m_spaceDim);
236  geom->FillGeom();
237 
238  LibUtilities::ShapeType type = (*fit)->m_vertexList.size() == 3
241  (*fit)->MakeOrder(order, geom, pTypes[type], m_spaceDim, id);
242  processedFaces.insert(faceId);
243  }
244 
245  // Copy curvature into boundary conditions
246  for (int i = 0; i < m_element[1].size(); ++i)
247  {
248  ElementSharedPtr el = m_element[1][i];
249  EdgeSharedPtr edge = el->GetEdgeLink();
250 
251  if (!edge)
252  {
253  continue;
254  }
255 
256  // Copy face curvature
257  el->MakeOrder(order, SpatialDomains::GeometrySharedPtr(),
258  pTypes[el->GetConf().m_e], m_spaceDim, id, true);
259  el->SetVolumeNodes(edge->m_edgeNodes);
260  }
261 
262  for (int i = 0; i < m_element[2].size(); ++i)
263  {
264  ElementSharedPtr el = m_element[2][i];
265  FaceSharedPtr face = el->GetFaceLink();
266 
267  if (!face)
268  {
269  continue;
270  }
271 
272  // Copy face curvature
273  el->MakeOrder(order, SpatialDomains::GeometrySharedPtr(),
274  pTypes[el->GetConf().m_e], m_spaceDim, id, true);
275  el->SetVolumeNodes(face->m_faceNodes);
276  }
277 
278  for (int i = 0; i < nElmt; ++i)
279  {
280  vector<NodeSharedPtr> tmp = m_element[m_expDim][i]->GetVolumeNodes();
281  for (int j = 0; j < tmp.size(); ++j)
282  {
283  tmp[j]->m_id = id++;
284  }
285  }
286 
287  if (m_verbose)
288  {
289  cout << endl;
290  }
291 }
292 }
293 }
Represents an edge which joins two points.
Definition: Edge.h:58
int PrintProgressbar(const int position, const int goal, const string message, int lastprogress=-1)
Prints a progressbar.
Definition: Progressbar.hpp:69
Represents a face comprised of three or more edges.
Definition: Face.h:61
STL namespace.
1D Evenly-spaced points using Lagrange polynomial
Definition: PointsType.h:65
3D Nodal Electrostatic Points on a Tetrahedron
Definition: PointsType.h:74
3D Evenly-spaced points on a Tetrahedron
Definition: PointsType.h:73
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
3D Evenly-spaced points on a Prism
Definition: PointsType.h:75
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:72
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
boost::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:153
#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
1D Gauss-Lobatto-Legendre quadrature points
Definition: PointsType.h:52
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:70
3D electrostatically spaced points on a Prism
Definition: PointsType.h:76