Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / examples / gridsolution / gridsolution.cpp
blobf960357157466c47a947f260fcaae12205aad1a6
1 /* This example illustrates using separate grid
2 * and solution files.
3 */
5 #include "TECIO.h"
6 #include "MASTER.h" /* for defintion of NULL */
8 int main()
10 /* DOCSTART:gridsolution_grid_tecini.txt*/
11 INTEGER4 I; /* use to check return values */
13 INTEGER4 Debug = 1;
14 INTEGER4 VIsDouble = 0;
15 INTEGER4 FileType = 1; /* 1 = grid file. */
17 I = TECINI112((char*)"Example: Separate grid and solution files",
18 (char*)"X Y Z", /* Defines the variables for the data file.
19 * Each zone must contain each of the vars
20 * listed here. The order of the variables
21 * in the list is used to define the
22 * variable number (e.g. X is Variable 1).
23 * When referring to variables in other
24 * TecIO functions, you will refer to the
25 * variable by its number.
27 (char*)"grid.plt",
28 (char*)".", /* scratch directory */
29 &FileType,
30 &Debug,
31 &VIsDouble);
32 /* DOCEND */
34 /* DOCSTART:gridsolution_grid_teczne.txt*/
35 /* TECZNE Parameters */
36 INTEGER4 ZoneType = 7; /* FE Polyhedron */
37 INTEGER4 NumPts = 20; /* the number of unique
38 * nodes in the zone.
40 INTEGER4 NumElems = 1;
41 INTEGER4 NumFaces = 12; /* the number of unique
42 * faces in the zone.
44 INTEGER4 ICellMax = 0; /* not used */
45 INTEGER4 JCellMax = 0; /* not used */
46 INTEGER4 KCellMax = 0; /* not used */
47 double SolutionTime = 0.0;
48 INTEGER4 StrandID = 1; /* time strand for
49 * unsteady solution.
51 INTEGER4 ParentZone = 0;
52 INTEGER4 IsBlock = 1;
53 INTEGER4 NumFaceConnections = 0;
54 INTEGER4 FaceNeighborMode = 1;
55 INTEGER4 SharConn = 0;
57 /* For this zone, the total number of face nodes is
58 * five times number of faces, because each face
59 * is a pentagon.
61 INTEGER4 TotalNumFaceNodes = 5 * NumFaces;
63 /* This zone has no connected boundary faces.
65 INTEGER4 TotalNumBndryFaces = 0;
66 INTEGER4 TotalNumBndryConns = 0;
68 I = TECZNE112((char*)"Dodecahedron", /* Name of the zone. */
69 &ZoneType,
70 &NumPts,
71 &NumElems,
72 &NumFaces,
73 &ICellMax,
74 &JCellMax,
75 &KCellMax,
76 &SolutionTime,
77 &StrandID,
78 &ParentZone,
79 &IsBlock,
80 &NumFaceConnections,
81 &FaceNeighborMode,
82 &TotalNumFaceNodes,
83 &TotalNumBndryFaces,
84 &TotalNumBndryConns,
85 NULL,
86 NULL, /* All nodal variables */
87 NULL,
88 &SharConn);
89 /* DOCEND */
91 /* DOCSTART:gridsolution_grid_tecdat.txt*/
93 /* TECDAT Parameters */
94 double Phi = 0.5 * (1.0 + sqrt(5.0));
95 double Pi = 3.141592653578;
96 double *X = new double[NumPts];
97 double *Y = new double[NumPts];
98 double *Z = new double[NumPts];
99 int Count = 0;
101 for(int J = 0; J <= 4; J++)
103 X[Count] = 2.0 * cos(2.0 / 5.0 * Pi * J);
104 Y[Count] = 2.0 * sin(2.0 / 5.0 * Pi * J);
105 Z[Count] = Phi + 1.0;
106 Count++;
108 X[Count] = -X[Count - 1];
109 Y[Count] = -Y[Count - 1];
110 Z[Count] = -Z[Count - 1];
111 Count++;
113 X[Count] = 2.0 * Phi * cos(2.0 / 5.0 * Pi * J);
114 Y[Count] = 2.0 * Phi * sin(2.0 / 5.0 * Pi * J);
115 Z[Count] = Phi - 1.0;
116 Count++;
118 X[Count] = -X[Count - 1];
119 Y[Count] = -Y[Count - 1];
120 Z[Count] = -Z[Count - 1];
121 Count++;
124 INTEGER4 IsDouble = 1;
126 I = TECDAT112(&NumPts, X, &IsDouble);
127 I = TECDAT112(&NumPts, Y, &IsDouble);
128 I = TECDAT112(&NumPts, Z, &IsDouble);
130 delete X;
131 delete Y;
132 delete Z;
134 /* DOCEND */
136 /* DOCSTART:gridsolution_grid_facenodes.txt*/
137 /* TecPoly Parameters */
139 /* Create a FaceNodes array, dimensioned by the total number
140 * of face nodes in the zone.
142 INTEGER4 *FaceNodes = new INTEGER4[TotalNumFaceNodes];
143 int n = 0;
145 /* Face Nodes for face 1 of the dodecahedron */
146 FaceNodes[n++] = 2;
147 FaceNodes[n++] = 6;
148 FaceNodes[n++] = 10;
149 FaceNodes[n++] = 14;
150 FaceNodes[n++] = 18;
152 /* Face Nodes for face 2 */
153 FaceNodes[n++] = 6;
154 FaceNodes[n++] = 8;
155 FaceNodes[n++] = 19;
156 FaceNodes[n++] = 12;
157 FaceNodes[n++] = 10;
159 /* Face Nodes for face 3 */
160 FaceNodes[n++] = 3;
161 FaceNodes[n++] = 12;
162 FaceNodes[n++] = 10;
163 FaceNodes[n++] = 14;
164 FaceNodes[n++] = 16;
166 /* Face Nodes for face 4 */
167 FaceNodes[n++] = 7;
168 FaceNodes[n++] = 16;
169 FaceNodes[n++] = 14;
170 FaceNodes[n++] = 18;
171 FaceNodes[n++] = 20;
173 /* Face Nodes for face 5 */
174 FaceNodes[n++] = 2;
175 FaceNodes[n++] = 4;
176 FaceNodes[n++] = 11;
177 FaceNodes[n++] = 20;
178 FaceNodes[n++] = 18;
180 /* Face Nodes for face 6 */
181 FaceNodes[n++] = 2;
182 FaceNodes[n++] = 4;
183 FaceNodes[n++] = 15;
184 FaceNodes[n++] = 8;
185 FaceNodes[n++] = 6;
187 /* Face Nodes for face 7 */
188 FaceNodes[n++] = 1;
189 FaceNodes[n++] = 3;
190 FaceNodes[n++] = 12;
191 FaceNodes[n++] = 19;
192 FaceNodes[n++] = 17;
194 /* Face Nodes for face 8 */
195 FaceNodes[n++] = 1;
196 FaceNodes[n++] = 3;
197 FaceNodes[n++] = 16;
198 FaceNodes[n++] = 7;
199 FaceNodes[n++] = 5;
201 /* Face Nodes for face 9 */
202 FaceNodes[n++] = 5;
203 FaceNodes[n++] = 7;
204 FaceNodes[n++] = 20;
205 FaceNodes[n++] = 11;
206 FaceNodes[n++] = 9;
208 /* Face Nodes for face 10 */
209 FaceNodes[n++] = 4;
210 FaceNodes[n++] = 11;
211 FaceNodes[n++] = 9;
212 FaceNodes[n++] = 13;
213 FaceNodes[n++] = 15;
215 /* Face Nodes for face 11 */
216 FaceNodes[n++] = 8;
217 FaceNodes[n++] = 15;
218 FaceNodes[n++] = 13;
219 FaceNodes[n++] = 17;
220 FaceNodes[n++] = 19;
222 /* Face Nodes for face 12 */
223 FaceNodes[n++] = 1;
224 FaceNodes[n++] = 5;
225 FaceNodes[n++] = 9;
226 FaceNodes[n++] = 13;
227 FaceNodes[n++] = 17;
229 /* DOCEND */
231 /* Specify the number of nodes for each face, and the right and
232 * left neighboring elements. The neighboring elements can be
233 * determined using the right-hand rule. For each face, curl
234 * the fingers of your right hand in the direction of
235 * incrementing node numbers (i.e. from Node 1 to Node 2 and
236 * so on). Your thumb will point toward the right element.
237 * A value of zero indicates that there is no
238 * neighboring element on that side. A negative value
239 * indicates that the neighboring element is in another zone.
240 * In that case, the number is a pointer into the
241 * FaceBndryConnectionElems and FaceBndryConnectionZones arrays.
244 /* DOCSTART:gridsolution_grid_tecpoly.txt*/
245 INTEGER4 *FaceNodeCounts = new INTEGER4[NumFaces];
246 INTEGER4 *FaceLeftElems = new INTEGER4[NumFaces];
247 INTEGER4 *FaceRightElems = new INTEGER4[NumFaces];
249 /* For this particular zone, each face has the 5 nodes. */
250 for(int J = 0; J < NumFaces; J++)
251 FaceNodeCounts[J] = 5;
253 /* Set the right and left elements for each face. */
254 FaceRightElems[0] = 1;
255 FaceRightElems[1] = 1;
256 FaceRightElems[2] = 0;
257 FaceRightElems[3] = 0;
258 FaceRightElems[4] = 0;
259 FaceRightElems[5] = 1;
260 FaceRightElems[6] = 1;
261 FaceRightElems[7] = 0;
262 FaceRightElems[8] = 0;
263 FaceRightElems[9] = 1;
264 FaceRightElems[10] = 1;
265 FaceRightElems[11] = 0;
267 FaceLeftElems[0] = 0;
268 FaceLeftElems[1] = 0;
269 FaceLeftElems[2] = 1;
270 FaceLeftElems[3] = 1;
271 FaceLeftElems[4] = 1;
272 FaceLeftElems[5] = 0;
273 FaceLeftElems[6] = 0;
274 FaceLeftElems[7] = 1;
275 FaceLeftElems[8] = 1;
276 FaceLeftElems[9] = 0;
277 FaceLeftElems[10] = 0;
278 FaceLeftElems[11] = 1;
280 I = TECPOLY112(FaceNodeCounts,
281 FaceNodes,
282 FaceLeftElems,
283 FaceRightElems,
284 NULL, /* No boundary connections. */
285 NULL,
286 NULL);
288 delete FaceNodes;
289 delete FaceLeftElems;
290 delete FaceRightElems;
292 /* DOCEND */
295 /* DOCSTART:gridsolution_grid_tecend.txt*/
296 I = TECEND112();
297 /* DOCEND */
299 /* DOCSTART:gridsolution_solution_tecini.txt*/
300 for(int J = 0; J < 5; J++)
302 char SolutionFileName[128];
303 sprintf(SolutionFileName, "solution%d.plt", J);
305 /* DOCSTART:gridsolution_solution_tecini.txt*/
306 FileType = 2; /* 1 = solution file. */
308 I = TECINI112((char*)"Example: Separate grid and solution files",
309 (char*)"P T", /* Defines the variables for the solution file.
310 * Note that these are different variables from
311 * the grid file.
313 SolutionFileName,
314 (char*)".", /* scratch directory */
315 &FileType,
316 &Debug,
317 &VIsDouble);
318 /* DOCEND */
320 /* DOCSTART:gridsolution_solution_teczne.txt*/
321 /* TECZNE Parameters are mostly unchanged from creation of the grid file. */
322 TotalNumFaceNodes = 0;
323 SolutionTime = J;
325 char ZoneName[128];
326 sprintf(ZoneName, "Dodecahedron Time=%g", SolutionTime);
327 I = TECZNE112(ZoneName,
328 &ZoneType,
329 &NumPts,
330 &NumElems,
331 &NumFaces,
332 &ICellMax,
333 &JCellMax,
334 &KCellMax,
335 &SolutionTime,
336 &StrandID,
337 &ParentZone,
338 &IsBlock,
339 &NumFaceConnections,
340 &FaceNeighborMode,
341 &TotalNumFaceNodes,
342 &TotalNumBndryFaces,
343 &TotalNumBndryConns,
344 NULL,
345 NULL, /* All nodal variables */
346 NULL,
347 &SharConn);
348 /* DOCEND */
350 /* DOCSTART:gridsolution_solution_tecdat.txt*/
352 /* TECDAT Parameters */
353 double *P = new double[NumPts];
354 double *T = new double[NumPts];
356 for(int K = 0; K < NumPts; K++)
358 P[K] = (double)(K + J);
359 T[K] = 1.0 + K + K;
362 I = TECDAT112(&NumPts, P, &IsDouble);
363 I = TECDAT112(&NumPts, T, &IsDouble);
365 delete P;
366 delete T;
368 /* DOCEND */
370 /* DOCSTART:gridsolution_solution_tecend.txt*/
371 I = TECEND112();
372 /* DOCEND */
375 return 0;