Nektar++
TetMesh.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: TetMesh.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: tet meshing methods
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
37 
38 using namespace std;
39 namespace Nektar
40 {
41 namespace NekMeshUtils
42 {
43 
45 {
46  if (m_mesh->m_verbose)
47  cout << endl << endl << "Tetrahdral mesh generation" << endl;
48 
50 
51  map<int, NodeSharedPtr> IdToNode;
52  map<NodeSharedPtr, int> IdToNodeRev;
53 
54  // build sequentially ordered maps of nodes that exist and there delta value
55  // in the octree
56  map<int, NekDouble> IdToDelta;
57  vector<Array<OneD, int> > surfacetris;
58  NodeSet alreadyInSurface;
59 
60  if(m_surface.size() == 0)
61  {
62  m_surface = m_mesh->m_element[2];
63  }
64 
65  int cnt = 0;
66  for(int i = 0; i < m_surface.size(); i++)
67  {
68  vector<NodeSharedPtr> n = m_surface[i]->GetVertexList();
69  Array<OneD, int> tri(3);
70  for(int j = 0; j < n.size(); j++)
71  {
72  pair<NodeSet::iterator,bool> testIns =
73  alreadyInSurface.insert(n[j]);
74 
75  if (testIns.second)
76  {
77  if(cnt == 2114)
78  {
79  //cout << n[j]->m_x << " " << n[j]->m_y << " " << n[j]->m_z << endl;
80  }
81  tri[j] = cnt;
82  IdToNode[cnt] = n[j];
83  IdToNodeRev[n[j]] = cnt;
84  IdToDelta[cnt] = m_mesh->m_octree->Query(n[j]->GetLoc());
85  cnt++;
86  }
87  else
88  {
89  tri[j] = IdToNodeRev[(*testIns.first)];
90  }
91  }
92  surfacetris.push_back(tri);
93  }
94 
95  //m_mesh->m_expDim--;
96  //m_mesh->m_element[3].clear();
97  //m_mesh->m_element[2] = m_surface;
98  //return;
99 
100  if (m_mesh->m_verbose)
101  {
102  cout << "\tInital Node Count: " << IdToNode.size() << endl;
103  }
104 
105  tetgen->InitialMesh(IdToNode, surfacetris);
106 
107  vector<Array<OneD, NekDouble> > newp;
108  int ctbefore = IdToNode.size();
109  int newpb;
110  do
111  {
112  newpb = newp.size();
113  newp.clear();
114  tetgen->GetNewPoints(ctbefore, newp);
115  for (int i = 0; i < newp.size(); i++)
116  {
117  NekDouble d = m_mesh->m_octree->Query(newp[i]);
118  IdToDelta[ctbefore + i] = d;
119  }
120  tetgen->RefineMesh(IdToDelta);
121  } while (newpb != newp.size());
122 
123  // make new map of all nodes to build tets.
124  newp.clear();
125  tetgen->GetNewPoints(ctbefore, newp);
126  for (int i = 0; i < newp.size(); i++)
127  {
128  NodeSharedPtr n = std::shared_ptr<Node>(
129  new Node(ctbefore + i, newp[i][0], newp[i][1], newp[i][2]));
130  IdToNode[ctbefore + i] = n;
131  }
132 
133  m_tetconnect = tetgen->Extract();
134 
135  // tetgen->freetet();
136 
137  // create tets
138  for (int i = 0; i < m_tetconnect.size(); i++)
139  {
140  vector<NodeSharedPtr> n;
141  n.push_back(IdToNode[m_tetconnect[i][0]]);
142  n.push_back(IdToNode[m_tetconnect[i][1]]);
143  n.push_back(IdToNode[m_tetconnect[i][2]]);
144  n.push_back(IdToNode[m_tetconnect[i][3]]);
145  ElmtConfig conf(LibUtilities::eTetrahedron, 1, false, false);
146  vector<int> tags;
147  tags.push_back(m_id);
149  LibUtilities::eTetrahedron, conf, n, tags);
150 
151  m_mesh->m_element[3].push_back(E);
152  }
153 
154  if (m_mesh->m_verbose)
155  cout << "\tTets :" << m_tetconnect.size() << endl;
156 }
157 }
158 }
Basic information about an element.
Definition: ElementConfig.h:49
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
STL namespace.
ElementFactory & GetElementFactory()
Definition: Element.cpp:44
std::shared_ptr< Node > NodeSharedPtr
Definition: CADVert.h:49
std::unordered_set< NodeSharedPtr, NodeHash > NodeSet
Definition: Node.h:447
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
double NekDouble