Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
45 void TetMesh::Mesh()
46 {
47  if (m_mesh->m_verbose)
48  cout << endl << endl << "Tetrahdral mesh generation" << endl;
49 
52 
53  map<int, NodeSharedPtr> TetgenIdToNode;
54  map<int, int> NodeIdToTetgenId;
55  // at this point all nodes are in m_mesh->m_vertexset, but if there is a
56  // boundary layer, we dont want all of them, also, tetgen ids must be
57  // sequential so there is a map from tetgen id to real nodes
58 
59  // build sequentially ordered maps of nodes that exist and there delta value
60  // in the octree
61  map<int, NekDouble> TetgenIdToDelta;
62  vector<Array<OneD, int> >
63  surfacetris; // surface mesh connectivity based on tetgenids
64 
65  int cnt = 0;
66  if (!m_pseudosurface)
67  {
68  // build surface mesh and node map from all surface elements
69  for (int i = 0; i < m_mesh->m_element[2].size(); i++)
70  {
71  ASSERTL0(m_mesh->m_element[2][i]->GetConf().m_e ==
73  "quad found in surface mesh with no prism mapping");
74 
75  vector<NodeSharedPtr> n = m_mesh->m_element[2][i]->GetVertexList();
76  Array<OneD, int> tri(3);
77  for (int j = 0; j < n.size(); j++)
78  {
80  it = NodeIdToTetgenId.find(n[j]->m_id);
81  if (it == NodeIdToTetgenId.end())
82  {
83  tri[j] = cnt;
84  NodeIdToTetgenId[n[j]->m_id] = cnt;
85  TetgenIdToNode[cnt] = n[j];
86  TetgenIdToDelta[cnt] = m_octree->Query(n[j]->GetLoc());
87  cnt++;
88  }
89  else
90  {
91  tri[j] = it->second;
92  }
93  }
94  surfacetris.push_back(tri);
95  }
96  }
97  else
98  {
99  m_surftopriface = m_blmesh->GetSurfToPri();
100  // surface triangles will need to be checked against surftopriface to
101  // get the right face
102  // all surface elements are sequentially numbered so this should be easy
103  // to find in map
104  for (int i = 0; i < m_mesh->m_element[2].size(); i++)
105  {
106  if (m_mesh->m_element[2][i]->GetConf().m_e !=
108  continue; // no quads for tetgen
109 
111  fit = m_surftopriface.find(m_mesh->m_element[2][i]->GetId());
112  if (fit == m_surftopriface.end())
113  {
114  // surface element does not have a correspoding prism, build
115  // tetgen surface
116  // tri from surface element
117  vector<NodeSharedPtr> n =
118  m_mesh->m_element[2][i]->GetVertexList();
119  Array<OneD, int> tri(3);
120  for (int j = 0; j < n.size(); j++)
121  {
123  it = NodeIdToTetgenId.find(n[j]->m_id);
124  if (it == NodeIdToTetgenId.end())
125  {
126  tri[j] = cnt;
127  NodeIdToTetgenId[n[j]->m_id] = cnt;
128  TetgenIdToNode[cnt] = n[j];
129  TetgenIdToDelta[cnt] = m_octree->Query(n[j]->GetLoc());
130  cnt++;
131  }
132  else
133  {
134  tri[j] = it->second;
135  }
136  }
137  surfacetris.push_back(tri);
138  }
139  else
140  {
141  // surface element has a prism on it, build tetgen surface
142  // element from the face
143  vector<NodeSharedPtr> n = fit->second->m_vertexList;
144  Array<OneD, int> tri(3);
145  for (int j = 0; j < n.size(); j++)
146  {
148  it = NodeIdToTetgenId.find(n[j]->m_id);
149  if (it == NodeIdToTetgenId.end())
150  {
151  tri[j] = cnt;
152  NodeIdToTetgenId[n[j]->m_id] = cnt;
153  TetgenIdToNode[cnt] = n[j];
154  TetgenIdToDelta[cnt] = m_octree->Query(n[j]->GetLoc());
155  cnt++;
156  }
157  else
158  {
159  tri[j] = it->second;
160  }
161  }
162  surfacetris.push_back(tri);
163  }
164  }
165  }
166 
167  if (m_mesh->m_verbose)
168  {
169  cout << "\tInital Node Count: " << TetgenIdToNode.size() << endl;
170  }
171 
172  tetgen->InitialMesh(TetgenIdToNode, surfacetris);
173 
174  vector<Array<OneD, NekDouble> > newp;
175  int ctbefore = TetgenIdToNode.size();
176  int newpb;
177 
178  do
179  {
180  newpb = newp.size();
181  newp.clear();
182  tetgen->GetNewPoints(ctbefore, newp);
183  for (int i = 0; i < newp.size(); i++)
184  {
185  NekDouble d = m_octree->Query(newp[i]);
186  TetgenIdToDelta[ctbefore + i] = d;
187  }
188  tetgen->RefineMesh(TetgenIdToDelta);
189  } while (newpb != newp.size());
190 
191  // make new map of all nodes to build tets.
192 
193  tetgen->GetNewPoints(ctbefore, newp);
194  for (int i = 0; i < newp.size(); i++)
195  {
196  NodeSharedPtr n = boost::shared_ptr<Node>(
197  new Node(m_mesh->m_numNodes++, newp[i][0], newp[i][1], newp[i][2]));
198  TetgenIdToNode[ctbefore + i] = n;
199  }
200 
201  m_tetconnect = tetgen->Extract();
202 
203  // tetgen->freetet();
204 
205  // create tets
206  for (int i = 0; i < m_tetconnect.size(); i++)
207  {
208  vector<NodeSharedPtr> n;
209  n.push_back(TetgenIdToNode[m_tetconnect[i][0]]);
210  n.push_back(TetgenIdToNode[m_tetconnect[i][1]]);
211  n.push_back(TetgenIdToNode[m_tetconnect[i][2]]);
212  n.push_back(TetgenIdToNode[m_tetconnect[i][3]]);
213  ElmtConfig conf(LibUtilities::eTetrahedron, 1, false, false);
214  vector<int> tags;
215  tags.push_back(0);
217  LibUtilities::eTetrahedron, conf, n, tags);
218 
219  m_mesh->m_element[3].push_back(E);
220  }
221 
222  if (m_mesh->m_verbose)
223  cout << "\tTets :" << m_tetconnect.size() << endl;
224 }
225 }
226 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
Basic information about an element.
Definition: Element.h:58
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
Represents a point in the domain.
Definition: Node.h:60
boost::shared_ptr< TetGenInterface > TetGenInterfaceSharedPtr
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
double NekDouble
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:52