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,
100  LibUtilities::PointsType distType)
101 {
102  int id = m_vertexSet.size();
103 
104  EdgeSet::iterator eit;
105  FaceSet::iterator fit;
106 
107  boost::unordered_map<int, SpatialDomains::Geometry1DSharedPtr> edgeGeoms;
108  boost::unordered_map<int, SpatialDomains::Geometry2DSharedPtr> faceGeoms;
109  boost::unordered_map<int, SpatialDomains::GeometrySharedPtr> volGeoms;
110 
111  // Decide on distribution of points to use for each shape type based on the
112  // input we've been supplied.
113  std::map<LibUtilities::ShapeType, LibUtilities::PointsType> pTypes;
114  if (distType == LibUtilities::ePolyEvenlySpaced)
115  {
123  }
124  else if (distType == LibUtilities::eGaussLobattoLegendre)
125  {
133  }
134  else
135  {
136  ASSERTL1(false, "Mesh::MakeOrder does not support this points type.");
137  }
138 
139  // Begin by generating Nektar++ geometry objects for edges, faces and
140  // elements so that we don't affect any neighbouring elements in the mesh as
141  // we process each element.
142  for(eit = m_edgeSet.begin(); eit != m_edgeSet.end(); eit++)
143  {
145  (*eit)->GetGeom(m_spaceDim);
146  geom->FillGeom();
147  edgeGeoms[(*eit)->m_id] = geom;
148  }
149 
150  for(fit = m_faceSet.begin(); fit != m_faceSet.end(); fit++)
151  {
153  (*fit)->GetGeom(m_spaceDim);
154  geom->FillGeom();
155  faceGeoms[(*fit)->m_id] = geom;
156  }
157 
158  for(int i = 0; i < m_element[m_expDim].size(); i++)
159  {
160  ElementSharedPtr el = m_element[m_expDim][i];
162  el->GetGeom(m_spaceDim);
163  geom->FillGeom();
164  volGeoms[el->GetId()] = geom;
165  }
166 
167  boost::unordered_set<int> processedEdges, processedFaces, processedVolumes;
168 
169  // note if CAD previously existed on the face or edge, the new points need
170  // to be projected onto the CAD entity.
171 
172  // Call MakeOrder with our generated geometries on each edge to fill in edge
173  // interior nodes.
174  int ct = 0;
175  for (eit = m_edgeSet.begin(); eit != m_edgeSet.end(); eit++, ct++)
176  {
177  if (m_verbose)
178  {
180  ct, m_edgeSet.size(), "MakeOrder: Edges: ");
181  }
182  int edgeId = (*eit)->m_id;
183 
184  if (processedEdges.find(edgeId) != processedEdges.end())
185  {
186  continue;
187  }
188 
189  (*eit)->MakeOrder(order, edgeGeoms[edgeId],
190  pTypes[LibUtilities::eSegment], m_spaceDim, id);
191  processedEdges.insert(edgeId);
192  }
193 
194  // Call MakeOrder with our generated geometries on each face to fill in face
195  // interior nodes.
196  ct = 0;
197  for (fit = m_faceSet.begin(); fit != m_faceSet.end(); fit++, ct++)
198  {
199  if (m_verbose)
200  {
202  ct, m_faceSet.size(), "MakeOrder: Faces: ");
203  }
204  int faceId = (*fit)->m_id;
205 
206  if (processedFaces.find(faceId) != processedFaces.end())
207  {
208  continue;
209  }
210 
211  LibUtilities::ShapeType type = (*fit)->m_vertexList.size() == 3 ?
213  (*fit)->MakeOrder(order, faceGeoms[faceId], pTypes[type], m_spaceDim,
214  id);
215  processedFaces.insert(faceId);
216  }
217 
218  // Copy curvature into boundary conditions
219  for (int i = 0; i < m_element[1].size(); ++i)
220  {
221  ElementSharedPtr el = m_element[1][i];
222  EdgeSharedPtr edge = el->GetEdgeLink();
223 
224  if (!edge)
225  {
226  continue;
227  }
228 
229  // Copy face curvature
230  el->MakeOrder(order, SpatialDomains::GeometrySharedPtr(),
231  pTypes[el->GetConf().m_e], m_spaceDim, id, true);
232  el->SetVolumeNodes(edge->m_edgeNodes);
233  }
234 
235  for (int i = 0; i < m_element[2].size(); ++i)
236  {
237  ElementSharedPtr el = m_element[2][i];
238  FaceSharedPtr face = el->GetFaceLink();
239 
240  if (!face)
241  {
242  continue;
243  }
244 
245  // Copy face curvature
246  el->MakeOrder(order, SpatialDomains::GeometrySharedPtr(),
247  pTypes[el->GetConf().m_e], m_spaceDim, id, true);
248  el->SetVolumeNodes(face->m_faceNodes);
249  }
250 
251  // Finally, fill in volumes.
252  const int nElmt = m_element[m_expDim].size();
253  for (int i = 0; i < nElmt; ++i)
254  {
255  if (m_verbose)
256  {
257  LibUtilities::PrintProgressbar(i, nElmt, "MakeOrder: Elements: ");
258  }
259  ElementSharedPtr el = m_element[m_expDim][i];
260  el->MakeOrder(order, volGeoms[el->GetId()], pTypes[el->GetConf().m_e],
261  m_spaceDim, id);
262  }
263 
264  if (m_verbose)
265  {
266  cout << endl;
267  }
268 }
269 
270 }
271 }
int PrintProgressbar(const int position, const int goal, const string message, int lastprogress=-1)
Prints a progressbar.
Definition: Progressbar.hpp:69
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< Geometry2D > Geometry2DSharedPtr
Definition: Geometry2D.h:59
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:135
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
boost::shared_ptr< Geometry1D > Geometry1DSharedPtr
Definition: Geometry1D.h:48
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:148
#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