Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TetGenInterface.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: TetGenInterface.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: tetgen interface methods
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
37 
38 #define TETLIBRARY
39 #include <tetgen.h>
40 
41 using namespace std;
42 
43 namespace Nektar
44 {
45 namespace NekMeshUtils
46 {
47 
48 void TetGenInterface::InitialMesh(map<int, NodeSharedPtr> tgidton,
49  vector<Array<OneD, int> > tri)
50 {
51  surface.initialize();
52  output.initialize();
53 
54  // build surface input
55  tetgenio::facet *f;
56  tetgenio::polygon *p;
57 
58  surface.firstnumber = 0;
59  surface.numberofpoints = tgidton.size();
60  surface.pointlist = new REAL[surface.numberofpoints * 3];
61 
63  for (it = tgidton.begin(); it != tgidton.end(); it++)
64  {
65  Array<OneD, NekDouble> loc = it->second->GetLoc();
66 
67  surface.pointlist[it->first * 3 + 0] = loc[0];
68  surface.pointlist[it->first * 3 + 1] = loc[1];
69  surface.pointlist[it->first * 3 + 2] = loc[2];
70  }
71 
72  surface.numberoffacets = tri.size();
73  surface.facetlist = new tetgenio::facet[surface.numberoffacets];
74  surface.facetmarkerlist = new int[surface.numberoffacets];
75 
76  for (int i = 0; i < tri.size(); i++)
77  {
78  f = &surface.facetlist[i];
79  f->numberofpolygons = 1;
80  f->polygonlist = new tetgenio::polygon[f->numberofpolygons];
81  f->numberofholes = 0;
82  f->holelist = NULL;
83  p = &f->polygonlist[0];
84  p->numberofvertices = 3;
85  p->vertexlist = new int[p->numberofvertices];
86  p->vertexlist[0] = tri[i][0];
87  p->vertexlist[1] = tri[i][1];
88  p->vertexlist[2] = tri[i][2];
89  surface.facetmarkerlist[i] = 0;
90  }
91 
92  tetrahedralize("pYzqQ", &surface, &output);
93 }
94 
95 void TetGenInterface::GetNewPoints(int num,
96  vector<Array<OneD, NekDouble> > &newp)
97 {
98  for (int i = num; i < output.numberofpoints; i++)
99  {
100  Array<OneD, NekDouble> loc(3);
101  loc[0] = output.pointlist[i * 3 + 0];
102  loc[1] = output.pointlist[i * 3 + 1];
103  loc[2] = output.pointlist[i * 3 + 2];
104  newp.push_back(loc);
105  }
106 }
107 
108 void TetGenInterface::RefineMesh(std::map<int, NekDouble> delta)
109 {
110  input = output;
111 
112  input.numberofpointmtrs = 1;
113 
114  input.pointmtrlist = new REAL[input.numberofpoints];
115 
116  for (int i = 0; i < input.numberofpoints; i++)
117  {
118  input.pointmtrlist[i] = delta[i];
119  }
120 
121  tetrahedralize("pYrmzqQO2/7o/120", &input, &output);
122 }
123 
124 vector<Array<OneD, int> > TetGenInterface::Extract()
125 {
126  vector<Array<OneD, int> > tets;
127  for (int i = 0; i < output.numberoftetrahedra; i++)
128  {
129  Array<OneD, int> tet(4);
130  tet[0] = output.tetrahedronlist[i * 4 + 0];
131  tet[1] = output.tetrahedronlist[i * 4 + 1];
132  tet[2] = output.tetrahedronlist[i * 4 + 2];
133  tet[3] = output.tetrahedronlist[i * 4 + 3];
134  tets.push_back(tet);
135  }
136  return tets;
137 }
138 
139 void TetGenInterface::freetet()
140 {
141  surface.deinitialize();
142  input.deinitialize();
143  output.deinitialize();
144 }
145 }
146 }
STL namespace.
#define REAL
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
void RefineMesh(Mesh *LocMesh)