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