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