Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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  string cmd = "pYzqQ";
93  char *cstr = new char[cmd.length() + 1];
94  strcpy(cstr, cmd.c_str());
95 
96  tetrahedralize(cstr, &surface, &output);
97 }
98 
99 void TetGenInterface::GetNewPoints(int num,
100  vector<Array<OneD, NekDouble> > &newp)
101 {
102  for (int i = num; i < output.numberofpoints; i++)
103  {
104  Array<OneD, NekDouble> loc(3);
105  loc[0] = output.pointlist[i * 3 + 0];
106  loc[1] = output.pointlist[i * 3 + 1];
107  loc[2] = output.pointlist[i * 3 + 2];
108  newp.push_back(loc);
109  }
110 }
111 
112 void TetGenInterface::RefineMesh(std::map<int, NekDouble> delta)
113 {
114  input = output;
115 
116  input.numberofpointmtrs = 1;
117 
118  input.pointmtrlist = new REAL[input.numberofpoints];
119 
120  for (int i = 0; i < input.numberofpoints; i++)
121  {
122  input.pointmtrlist[i] = delta[i];
123  }
124 
125  string cmd = "pYrmzq1.1/0QO2/7";
126  char *cstr = new char[cmd.length() + 1];
127  strcpy(cstr, cmd.c_str());
128 
129  tetrahedralize(cstr, &input, &output);
130 }
131 
132 vector<Array<OneD, int> > TetGenInterface::Extract()
133 {
134  vector<Array<OneD, int> > tets;
135  for (int i = 0; i < output.numberoftetrahedra; i++)
136  {
137  Array<OneD, int> tet(4);
138  tet[0] = output.tetrahedronlist[i * 4 + 0];
139  tet[1] = output.tetrahedronlist[i * 4 + 1];
140  tet[2] = output.tetrahedronlist[i * 4 + 2];
141  tet[3] = output.tetrahedronlist[i * 4 + 3];
142  tets.push_back(tet);
143  }
144 
145  return tets;
146 }
147 
148 void TetGenInterface::freetet()
149 {
150  surface.deinitialize();
151  input.deinitialize();
152  output.deinitialize();
153 }
154 }
155 }
STL namespace.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
void RefineMesh(Mesh *LocMesh)