rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
tetgenrsvs.hpp
Go to the documentation of this file.
1 
7 #ifndef TETGEN_RSVS_API_H_INCLUDED
8 #define TETGEN_RSVS_API_H_INCLUDED
9 
10 //=================================
11 // forward declared dependencies
12 // class foo; //when you only need a pointer not the actual object
13 // and to avoid circular dependencies
14 
15 class snake;
16 
17 //=================================
18 // included dependencies
19 
20 #include <algorithm>
21 #include <array>
22 #include <string>
23 #include <vector>
24 
25 #include "mesh.hpp"
26 #include "tetgen.h"
27 
28 //-------------------------------------------------------------------------
29 // Tetgen namespace containing the interfacing functions
30 //
31 
32 namespace tetgen
33 {
34 
40 typedef std::array<std::array<double, 3>, 2> dombounds;
41 
50 class io_safe : public tetgenio
51 {
52  // Adds a semblance of prebuilt allocation functions
53  // to the io class build into tetgen
54  public:
55  // REAL *pointlist;
56  // REAL *pointattributelist;
57  // REAL *pointmtrlist;
58  // int *pointmarkerlist;
59 
60  using tetgenio::pointlist;
61 
62  using tetgenio::numberofpointmtrs;
63  using tetgenio::pointattributelist;
64  using tetgenio::pointmarkerlist;
65  using tetgenio::pointmtrlist;
66 
67  // int *tetrahedronlist;
68  // REAL *tetrahedronattributelist;
69  // REAL *tetrahedronvolumelist;
70  // int *neighborlist;
71  using tetgenio::neighborlist;
72  using tetgenio::tetrahedronattributelist;
73  using tetgenio::tetrahedronlist;
74  using tetgenio::tetrahedronvolumelist;
75 
76  // tetgenio::facet *facetlist;
77  // int *facetmarkerlist;
78  using tetgenio::facetlist;
79  using tetgenio::facetmarkerlist;
80  // REAL *facetconstraintlist;
81  // int numberoffacetconstraints;
82  using tetgenio::facetconstraintlist;
83  using tetgenio::numberoffacetconstraints;
84  // REAL *holelist;
85  // REAL *regionlist;
86  using tetgenio::holelist;
87  using tetgenio::regionlist;
88 
89  // REAL *segmentconstraintlist;
90  using tetgenio::segmentconstraintlist;
91 
92  // int *edgelist;
93  // int *edgemarkerlist;
94  // int *o2edgelist;
95  // int *edgeadjtetlist;
96  using tetgenio::edge2tetlist;
97  using tetgenio::edgelist;
98  using tetgenio::edgemarkerlist;
99  using tetgenio::face2edgelist;
100  using tetgenio::face2tetlist;
101  using tetgenio::o2edgelist;
102 
103  // REAL *vpointlist;
104  // tetgenio::voroedge *vedgelist;
105  // tetgenio::vorofacet *vfacetlist;
106  // int **vcelllist;
107  using tetgenio::vcelllist;
108  using tetgenio::vedgelist;
109  using tetgenio::vfacetlist;
110  using tetgenio::vpointlist;
111 
112  using tetgenio::initialize;
113 
114  void allocate();
115  void allocatefacet(int fIndex);
116  void allocatefacet(int fIndex, int numPoly);
117  void allocatefacetpolygon(int fIndex, int pIndex);
118  void allocatefacetpolygon(int fIndex, int pIndex, int numVerts);
119 
120  void SpecifyTetPointMetric(int startPnt, int numPnt, const std::vector<double> &mtrs);
121  void SpecifyIndividualTetPointMetric(int startPnt, int numPnt, const std::vector<double> &mtrs);
122  void SpecifyTetFacetMetric(int startPnt, int numPnt, int marker);
123 
124  void displaystats();
125  void displaypoints();
126 
127  io_safe()
128  {
129  initialize();
130  }
131 };
132 
133 class apiparam
134 {
135  public:
137  std::array<double, 3> lowerB;
139  std::array<double, 3> upperB;
142  std::array<double, 2> surfedgelengths;
143  int curvatureSmoothing;
145  std::vector<double> edgelengths;
147  double distanceTol;
148  // mesh the inside of the geometry? (or the outside)
149  bool generateMeshInside;
150 
151  // Commmand line string to be passed to tetgen
152  std::string command;
153 
154  void ReadJsonString(const std::string &jsonStr);
155  apiparam()
156  {
157  this->lowerB = {0.0, 0.0, 0.0};
158  this->upperB = {1.0, 1.0, 1.0};
159  this->surfedgelengths = {0.02, 0.005};
160  this->curvatureSmoothing = 4;
161  this->edgelengths = {0.03, 1.0};
162  this->distanceTol = 0.3;
163  this->generateMeshInside = false;
164  this->command = "";
165  }
171  apiparam(const std::string &jsonStr) : apiparam()
172  {
173  this->ReadJsonString(jsonStr);
174  }
175 };
176 
177 std::vector<int> RSVSVoronoiMesh(const std::vector<double> &vecPts, mesh &vosMesh, mesh &snakMesh,
178  tetgen::apiparam &inparam);
179 
180 void SnakeToSU2(const snake &snakein, const std::string &fileName, tetgen::apiparam &inparam);
181 
182 tetgenmesh *rsvstetrahedralize(const char *switches, tetgen::io_safe *in, tetgen::io_safe *out,
183  tetgen::io_safe *addin = NULL, tetgen::io_safe *bgmin = NULL);
184 
185 namespace input
186 {
187 void POINTGRIDS(const mesh &meshdomain, tetgen::io_safe &tetin, const tetgen::apiparam &tetgenParam,
188  bool generateVoroBound = false);
189 void RSVSGRIDS(const mesh &meshdomain, tetgen::io_safe &tetin, const tetgen::apiparam &tetgenParam);
190 void RSVSGRIDS(const mesh &meshdomain, const mesh &meshboundary, tetgen::io_safe &tetin,
191  const tetgen::apiparam &tetgenParam);
192 void RSVS2CFD(const snake &snakein, tetgen::io_safe &tetin, const tetgen::apiparam &tetgenParam);
193 } // namespace input
194 namespace output
195 {
196 mesh VORO2MESH(tetgen::io_safe &tetout);
197 void SU2(const char *fileName, const tetgenio &tetout);
198 dombounds GetBoundBox(io_safe &tetout);
199 mesh TET2MESH(tetgen::io_safe &tetout);
200 } // namespace output
201 namespace internal
202 {
203 void CloseVoronoiMesh(mesh &meshout, tetgen::io_safe &tetout, std::vector<int> &rayEdges, int DEINCR,
204  tetgen::dombounds boundBox);
205 template <class T, class V>
206 double ProjectRay(int count, const tetgen::dombounds &boundBox, const T &dir, const V &orig, double minDist = 0.0);
207 void MeshData2Tetgenio(const mesh &meshgeom, tetgen::io_safe &tetin, int facetOffset, int pointOffset, int pointMarker,
208  const std::vector<double> &pointMtrList, const std::vector<double> &facetConstr,
209  int facetConstrOffset);
210 void Mesh2Tetgenio(const mesh &meshgeom, const mesh &meshdomain, tetgen::io_safe &tetin, int numHoles);
211 void Mesh2TetgenioPoints(const mesh &meshgeom, const mesh &meshdomain, tetgen::io_safe &tetin);
212 void PointCurvature2Metric(std::vector<double> &vertCurvature, const tetgen::apiparam &inparam);
213 } // namespace internal
214 namespace voronoi
215 {
216 void GenerateInternalPoints(const mesh &meshin, int nLevels, tetgen::io_safe &tetinPts);
217 std::vector<bool> Points2VoroAndTetmesh(const std::vector<double> &vecPts, mesh &voroMesh, mesh &tetMesh,
218  const tetgen::apiparam &inparam);
219 std::vector<bool> BoundaryFacesFromPoints(const mesh &meshin, const std::vector<int> &boundaryPts);
220 } // namespace voronoi
221 
222 namespace test
223 {
224 void LoadData(mesh &snakeMesh, mesh &voluMesh, snake &snakein, mesh &triMesh);
225 int api();
226 int call();
227 int CFD();
228 int RSVSVORO();
229 int RSVSVORO_Contain();
230 int RSVSVOROFunc(const std::vector<double> &vecPts = {}, double distanceTol = 0.26,
231  const char *tecoutStr = "../TESTOUT/rsvs_voro.plt");
232 int RSVSVOROFunc_contain(int nPts = 0, double distanceTol = 0.26,
233  const char *tecoutStr = "../TESTOUT/rsvs_voro_contain.plt");
234 } // namespace test
235 } // namespace tetgen
236 
251 template <class T, class V>
252 double tetgen::internal::ProjectRay(int count, const tetgen::dombounds &boundBox, const T &dir, const V &orig,
253  double minDist)
254 {
255  /*
256  Calculates the distance to project a single ray to reach the bounding box
257 
258  It is templated to accept any types of containers with `count` elements,
259  accessible by operator[];
260  */
261 
262  double l = -INFINITY;
263 
264  for (int i = 0; i < count; ++i)
265  {
266  l = std::max(l, std::min((boundBox[0][i] - orig[i]) / dir[i], (boundBox[1][i] - orig[i]) / dir[i]));
267  }
268  return std::min(l, minDist);
269 }
270 int Test_RSVSvoro_init();
271 #endif
Class for mesh handling.
Definition: mesh.hpp:592
Definition: snake.hpp:83
double distanceTol
Distance tolerance.
Definition: tetgenrsvs.hpp:147
apiparam(const std::string &jsonStr)
Constructs the object from a json string.
Definition: tetgenrsvs.hpp:171
std::vector< double > edgelengths
Controls the edgelengths at regular intervals.
Definition: tetgenrsvs.hpp:145
std::array< double, 2 > surfedgelengths
Controls the surface edgelengths in CFD in the order: {point of lowest curvature, point of highest cu...
Definition: tetgenrsvs.hpp:142
std::array< double, 3 > lowerB
Lower domain bound.
Definition: tetgenrsvs.hpp:137
std::array< double, 3 > upperB
Upper domain bound.
Definition: tetgenrsvs.hpp:139
Class for memory safe interface with tetgen.h.
Definition: tetgenrsvs.hpp:51
Provides all the mesh tools used for the generation of 3D grids and geometries.
mesh TET2MESH(tetgen::io_safe &tetout)
Translates a tetgen output to the RSVS native mesh format.
double ProjectRay(int count, const tetgen::dombounds &boundBox, const T &dir, const V &orig, double minDist=0.0)
Project voronoi diagram rays to the bounding Box.
Definition: tetgenrsvs.hpp:252
std::array< std::array< double, 3 >, 2 > dombounds
Type defining domain boundaries.
Definition: tetgenrsvs.hpp:40
void GenerateInternalPoints(const mesh &meshin, int nLevels, tetgen::io_safe &tetinPts)
Generate points inside volume cells of a mesh.