foam to Tecplot360 converter
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / examples / arrow / arrow.cpp
blob432022be519670677b74d0458f74ece1b5001650
1 /* This example creates two simple polyhedral zones in the shape
2 * of a three-dimensional arrow. Obscured boundary faces are used.
3 */
5 #include <stdio.h>
6 #include "TECIO.h"
8 int main()
10 /* DOCSTART:arrow_tecini.txt*/
11 INTEGER4 Debug = 1;
12 INTEGER4 VIsDouble = 1;
13 INTEGER4 FileType = 0;
14 INTEGER4 I;
16 /* Open the file and write the Tecplot datafile
17 * header information
19 I = TECINI112((char*)"Multiple polyhedral zones", /* Name of the entire
20 * dataset.
22 (char*)"X Y Z P", /* Defines the variables for the data
23 * file. Each zone must contain each of
24 * the variables listed here. The order
25 * of the variables in the list is used
26 * to define the variable number (e.g.
27 * X is Var 1).
29 (char*)"Arrow.plt",
30 (char*)".", /* Scratch Directory */
31 &FileType,
32 &Debug,
33 &VIsDouble);
35 /* DOCEND */
38 /* After TECINI is called, call TECZNE to create one or more
39 * zones for your data file. In this example, Zone 1 contains a
40 * single rectangular solid created as a face-based finite-element
41 * (i.e. polyhedral zone). The zone has eight points (or nodes),
42 * six faces and one element.
44 /* DOCSTART:arrow_teczne_rect.txt*/
45 /* TECZNE Parameters */
46 INTEGER4 ZoneType = 7; /* sets the zone type
47 * to polyhedral */
48 INTEGER4 NumPts_Rect = 8;
49 INTEGER4 NumElems_Rect = 1;
50 INTEGER4 NumFaces_Rect = 6;
51 INTEGER4 ICellMax = 0; /* not used */
52 INTEGER4 JCellMax = 0; /* not used */
53 INTEGER4 KCellMax = 0; /* not used */
54 double SolutionTime = 0.0;
55 INTEGER4 StrandID = 0;
56 INTEGER4 ParentZone = 0;
57 INTEGER4 IsBlock = 1;
58 INTEGER4 NumFaceConnections = 0; /* not used */
59 INTEGER4 FaceNeighborMode = 1; /* not used */
60 INTEGER4 SharConn = 0;
62 /* In a rectangular solid, each face is composed of four nodes.
63 * As such, the total number of face nodes is twenty-four (four
64 * nodes for each of the six faces).
66 INTEGER4 TotalNumFaceNodes_Rect = 24;
68 /* There is one connected boundary face in this zone (the face on
69 * the rectangle adjacent to the arrowhead). Refer to the Data
70 * Format Guide for additional information. */
71 INTEGER4 NumConnBndryFaces_Rect = 1;
73 /* The connected boundary face has one connection, the face on
74 * the bottom of the arrowhead. A connection is an element-zone
75 * tuple that indicates a neighboring element (and its zone) when
76 * the neighboring element is in a different zone. Generally,
77 * there will be one boundary connection for each boundary face.
79 INTEGER4 TotalNumBndryConns_Rect = 1;
81 /* For illustrative purposes, the grid variables (X, Y, and Z)
82 * are nodal variables (i.e. ValueLocation = 1), and the pressure
83 * variable (P) is a cell-centered variable (i.e.
84 * ValueLocation = 0).
86 INTEGER4 ValueLocation[4] = { 1, 1, 1, 0 };
88 I = TECZNE112((char*)"Zone 1: Rectangular Solid",
89 &ZoneType,
90 &NumPts_Rect,
91 &NumElems_Rect,
92 &NumFaces_Rect,
93 &ICellMax,
94 &JCellMax,
95 &KCellMax,
96 &SolutionTime,
97 &StrandID,
98 &ParentZone,
99 &IsBlock,
100 &NumFaceConnections,
101 &FaceNeighborMode,
102 &TotalNumFaceNodes_Rect,
103 &NumConnBndryFaces_Rect,
104 &TotalNumBndryConns_Rect,
105 NULL,
106 ValueLocation,
107 NULL,
108 &SharConn);
110 /* DOCEND */
112 /* DOCSTART:arrow_tecdat_rect.txt*/
113 //set variable values (X_Rect, Y_Rect, Z_Rect & P_Rect)
114 double *X_Rect = new double[NumPts_Rect];
115 double *Y_Rect = new double[NumPts_Rect];
116 double *Z_Rect = new double[NumPts_Rect];
117 double *P_Rect = new double[NumElems_Rect];
119 for (INTEGER4 ii = 0; ii <= NumPts_Rect / 2; ii += 4)
121 X_Rect[ii] = 0;
122 X_Rect[ii+1] = 3;
123 X_Rect[ii+2] = 3;
124 X_Rect[ii+3] = 0;
126 Y_Rect[ii] = 3;
127 Y_Rect[ii+1] = 3;
128 Y_Rect[ii+2] = 1;
129 Y_Rect[ii+3] = 1;
132 for (INTEGER4 ii = 0; ii < 4; ii++)
133 Z_Rect[ii] = 0;
135 for (INTEGER4 ii = 4; ii < NumPts_Rect; ii++)
136 Z_Rect[ii] = -2;
138 P_Rect[0] = 10;
141 INTEGER4 IsDouble = 1;
142 I = TECDAT112(&NumPts_Rect, X_Rect, &IsDouble);
143 I = TECDAT112(&NumPts_Rect, Y_Rect, &IsDouble);
144 I = TECDAT112(&NumPts_Rect, Z_Rect, &IsDouble);
145 I = TECDAT112(&NumElems_Rect, P_Rect, &IsDouble);
146 /* DOCEND */
148 /* DOCSTART:arrow_facenodes_rect.txt*/
150 /* The FaceNodeCounts array is used to describe the number of
151 * nodes in each face of the zone. The first value in the array
152 * is the number of nodes in Face 1, the second value is the
153 * number of nodes in Face 2 and so forth. In this example, each
154 * face of the zone has four nodes.
157 INTEGER4 *FaceNodeCounts_Rect = new INTEGER4[NumFaces_Rect];
158 //For this particular zone, each face has the 4 nodes
159 for (INTEGER4 ii = 0; ii < NumFaces_Rect; ii++)
160 FaceNodeCounts_Rect[ii] = 4;
162 /* The FaceNodes array is used to specify the nodes that compose
163 * each face. For each face (n of N), the number of nodes used
164 * to define the face is specified by the nth value in the
165 * FaceNodeCounts array. For example, if the first value in the
166 * FaceNodeCounts array is 4 (indicating Face 1 is composed of
167 * four nodes), the first four values in the FaceNodes array are
168 * the node numbers of the nodes in Face 1.
170 * ------------
171 * WARNING
172 * When providing the node numbers for each face, you must
173 * provide the node numbers in a consistent order (either
174 * clockwise or counter-clockwise. Providing the node numbers
175 * out of order results in contorted faces.
176 * ------------
179 INTEGER4 *FaceNodes_Rect = new INTEGER4[TotalNumFaceNodes_Rect];
181 //Nodes for Face 1
182 FaceNodes_Rect[0] = 1;
183 FaceNodes_Rect[1] = 2;
184 FaceNodes_Rect[2] = 3;
185 FaceNodes_Rect[3] = 4;
187 //Nodes for Face 2
188 FaceNodes_Rect[4] = 1;
189 FaceNodes_Rect[5] = 4;
190 FaceNodes_Rect[6] = 8;
191 FaceNodes_Rect[7] = 5;
193 //Nodes for Face 3
194 FaceNodes_Rect[8] = 5;
195 FaceNodes_Rect[9] = 8;
196 FaceNodes_Rect[10] = 7;
197 FaceNodes_Rect[11] = 6;
199 //Nodes for Face 4
200 FaceNodes_Rect[12] = 2;
201 FaceNodes_Rect[13] = 6;
202 FaceNodes_Rect[14] = 7;
203 FaceNodes_Rect[15] = 3;
205 //Nodes for Face 5
206 FaceNodes_Rect[16] = 6;
207 FaceNodes_Rect[17] = 2;
208 FaceNodes_Rect[18] = 1;
209 FaceNodes_Rect[19] = 5;
211 //Nodes for Face 6
212 FaceNodes_Rect[20] = 3;
213 FaceNodes_Rect[21] = 7;
214 FaceNodes_Rect[22] = 8;
215 FaceNodes_Rect[23] = 4;
216 /* DOCEND */
218 /* DOCSTART:arrow_neighbors_rect.txt*/
219 INTEGER4 *FaceLeftElems_Rect = new INTEGER4[NumFaces_Rect];
220 INTEGER4 *FaceRightElems_Rect = new INTEGER4[NumFaces_Rect];
222 /* Since this zone has just one element, all leftelems are
223 * NoNeighboring Element and all right elems are itself
225 for (INTEGER4 ii = 0; ii < NumFaces_Rect; ii++)
227 FaceRightElems_Rect[ii] = 1;
228 FaceLeftElems_Rect[ii] = 0;
231 /* The negative value in the FaceLeftElems array indicates that
232 * the face is connected to an element in another zone. In this
233 * case, Face 4 is connected to a face in Zone 2 (to be defined
234 * later in the example). The FaceBoundaryConnectionElems array
235 * lists all of the element numbers in other zones that the
236 * current zone shares boundary connections with. Similarly, the
237 * FaceBoundaryConnectionZones array lists all of the zone numbers
238 * with which the current zone shares boundaries. A negative
239 * value in the FaceLeftElems or FaceRightElems array indicates
240 * the position within these arrays that defines the neighboring
241 * element and zone for a face.
243 * For example, if the FaceBoundaryConnectionElems array is:
244 * [1 8 2] and the FaceBoundaryConnectionZones array is: [2 5 3],
245 * a FaceLeftElems or FaceRightElems value of -2 indicates that
246 * the face in question has a boundary connection with Element 8
247 * in Zone 5.
249 FaceLeftElems_Rect[3] = -1;
250 /* DOCEND */
252 /* DOCSTART:arrow_tecpoly_rect.txt*/
253 /* The FaceBndryConnectionCounts array is used to define the
254 * number of boundary connections for each face that has a
255 * boundary connection. For example, if a zone has three boundary
256 * connections in total (NumConnectedBoundaryFaces), two of those
257 * boundary connections are in one face, and the remaining
258 * boundary connection is in a second face, the
259 * FaceBndryConnectionCounts array would be: [2 1].
260 * In this example, the total number of connected boundary faces
261 * (specified via TECZNE) is equal to one, so the
262 * FaceBoundaryConnectionCounts array contains a single value (1).
264 INTEGER4 *FaceBndryConnCounts_Rect = new INTEGER4[NumConnBndryFaces_Rect];
265 FaceBndryConnCounts_Rect[0] = 1;
267 /* The value(s) in the FaceBndryConnectionElems and
268 * FaceBndryConnectionZones arrays specify the element number and
269 * zone number, respectively, that a given boundary connection is
270 * connected to. In this case, the boundary connection face is
271 * connected to Element 1 in Zone 2.
273 INTEGER4 *FaceBndryConnElems_Rect = new INTEGER4[TotalNumBndryConns_Rect];
274 INTEGER4 *FaceBndryConnZones_Rect = new INTEGER4[TotalNumBndryConns_Rect];
276 FaceBndryConnElems_Rect[0] = 1;
277 FaceBndryConnZones_Rect[0] = 2;
279 I = TECPOLY112(FaceNodeCounts_Rect,
280 FaceNodes_Rect,
281 FaceLeftElems_Rect,
282 FaceRightElems_Rect,
283 FaceBndryConnCounts_Rect,
284 FaceBndryConnElems_Rect,
285 FaceBndryConnZones_Rect);
287 /* cleanup */
288 delete X_Rect;
289 delete Y_Rect;
290 delete Z_Rect;
291 delete P_Rect;
292 delete FaceNodeCounts_Rect;
293 delete FaceNodes_Rect;
294 delete FaceLeftElems_Rect;
295 delete FaceRightElems_Rect;
296 delete FaceBndryConnCounts_Rect;
297 delete FaceBndryConnElems_Rect;
298 delete FaceBndryConnZones_Rect;
299 /* DOCEND */
301 /* The data for Zone 1 has been written to the data file, so we
302 * are ready to create Zone 2. For simplicity, we will reuse many
303 * of the variables created for the rectangular zone that are not
304 * relevant to this tutorial. */
306 /* Zone 2 (the arrowhead or prism) has a single element composed
307 * of six nodes and five faces.
310 /* DOCSTART:arrow_teczne_prism.txt*/
311 //TECZNE Parameters
312 INTEGER4 NumPts_Prism = 6;
313 INTEGER4 NumElems_Prism = 1;
314 INTEGER4 NumFaces_Prism = 5;
316 /* The prism is composed of two triangular faces and three
317 * rectangular faces. The total number of face nodes is the sum
318 * of the nodes in each triangular face (2 times 3) and the nodes
319 * in each rectangular face (3 times 4).
321 INTEGER4 TotalNumFaceNodes_Prism = 18;
323 /* As with Zone 1, Zone 2 has one connected boundary face, the
324 * face that is connected to Zone 1.
326 INTEGER4 NumConnBndryFaces_Prism = 1;
328 /* In this case, we have set the total number of boundary
329 * connections for the connected face to two. The first boundary
330 * connection is the connection to Zone 1. The second boundary
331 * connection is used to indicate that the face is only partially
332 * obscured by the face from Zone 1. If we omitted the second
333 * boundary connection, the connected face of the prism would
334 * disappear if the rectangular zone was deactivated.
336 INTEGER4 TotalNumBndryConns_Prism = 2;
338 I = TECZNE112((char*)"Zone 2: Prism",
339 &ZoneType,
340 &NumPts_Prism,
341 &NumElems_Prism,
342 &NumFaces_Prism,
343 &ICellMax,
344 &JCellMax,
345 &KCellMax,
346 &SolutionTime,
347 &StrandID,
348 &ParentZone,
349 &IsBlock,
350 &NumFaceConnections,
351 &FaceNeighborMode,
352 &TotalNumFaceNodes_Prism,
353 &NumConnBndryFaces_Prism,
354 &TotalNumBndryConns_Prism,
355 NULL,
356 ValueLocation,
357 NULL,
358 &SharConn);
359 /* DOCEND */
361 /* DOCSTART:arrow_tecdat_prism.txt*/
364 double *X_Prism = new double[NumPts_Prism];
365 double *Y_Prism = new double[NumPts_Prism];
366 double *Z_Prism = new double[NumPts_Prism];
369 /* Set the X and Y variable values, one z-plane at a time */
370 double ZVal = 0;
371 for (INTEGER4 ii = 0; ii < 2; ii++)
373 // triangle in Z=ZVal plane
374 X_Prism[3*ii] = 3;
375 Y_Prism[3*ii] = 4;
376 Z_Prism[3*ii] = ZVal;
378 X_Prism[3*ii+1] = 7;
379 Y_Prism[3*ii+1] = 2;
380 Z_Prism[3*ii+1] = ZVal;
382 X_Prism[3*ii+2] = 3;
383 Y_Prism[3*ii+2] = 0;
384 Z_Prism[3*ii+2] = ZVal;
386 ZVal = ZVal - 2;
389 /* When we called TecZne, we specified that the variable 4
390 * (pressure) is cell-centered. As such, only NumElements number
391 * of values needs to be written to the data file for the pressure
392 * variable.
394 double *P_Prism = new double[NumElems_Prism];
395 P_Prism[0] = 20;
397 I = TECDAT112(&NumPts_Prism, X_Prism, &IsDouble);
398 I = TECDAT112(&NumPts_Prism, Y_Prism, &IsDouble);
399 I = TECDAT112(&NumPts_Prism, Z_Prism, &IsDouble);
400 I = TECDAT112(&NumElems_Prism, P_Prism, &IsDouble);
401 /* DOCEND */
403 /* DOCSTART:arrow_facemap_prism.txt*/
404 INTEGER4 *FaceNodeCounts_Prism = new INTEGER4[NumFaces_Prism];
405 INTEGER4 *FaceNodes_Prism = new INTEGER4[TotalNumFaceNodes_Prism];
407 /* Because of the way we chose to number our faces, the first
408 * three faces are rectangular and the last two are triangular.
409 * The numbering of the faces is arbitrary, but the faces must
410 * be referred to consistently.
412 for (INTEGER4 ii = 0; ii < 3; ii++)
413 FaceNodeCounts_Prism[ii] = 4;
415 for (INTEGER4 ii = 3; ii < NumFaces_Prism; ii++)
416 FaceNodeCounts_Prism[ii] = 3;
418 //Nodes for Face 1
419 FaceNodes_Prism[0] = 1;
420 FaceNodes_Prism[1] = 3;
421 FaceNodes_Prism[2] = 6;
422 FaceNodes_Prism[3] = 4;
424 //Nodes for Face 2
425 FaceNodes_Prism[4] = 1;
426 FaceNodes_Prism[5] = 4;
427 FaceNodes_Prism[6] = 5;
428 FaceNodes_Prism[7] = 2;
430 //Nodes for Face 3
431 FaceNodes_Prism[8] = 3;
432 FaceNodes_Prism[9] = 2;
433 FaceNodes_Prism[10] = 5;
434 FaceNodes_Prism[11] = 6;
436 //Nodes for Face 4
437 FaceNodes_Prism[12] = 5;
438 FaceNodes_Prism[13] = 4;
439 FaceNodes_Prism[14] = 6;
441 //Nodes for Face 5
442 FaceNodes_Prism[15] = 1;
443 FaceNodes_Prism[16] = 2;
444 FaceNodes_Prism[17] = 3;
445 /* DOCEND */
447 /* DOCSTART:arrow_neighbors_prism.txt*/
448 /* Since this zone has just one element, all leftelems are
449 * NoNeighboring Element and all right elems are itself.
451 INTEGER4 *FaceLeftElems_Prism = new INTEGER4[NumFaces_Prism];
452 INTEGER4 *FaceRightElems_Prism = new INTEGER4[NumFaces_Prism];
454 for (INTEGER4 ii = 0; ii < NumFaces_Prism; ii++)
456 FaceRightElems_Prism[ii] = 1;
457 FaceLeftElems_Prism[ii] = 0;
460 /* The negative value in the FaceLeftElems array indicates that
461 * the face is connected to an element in another zone. In this
462 * case, Face 1 is connected to a face in Zone 1 (as indicated in
463 * Line 6). The FaceBoundaryConnectionElems array lists all of
464 * the element numbers in other zones that the current zone shares
465 * boundary connections with. Similarly, the
466 * FaceBoundaryConnectionZones array lists all of the zone numbers
467 * with which the current zone shares boundaries. A negative
468 * value in the FaceLeftElems or FaceRightElems array indicates
469 * the position within these arrays that defines the neighboring
470 * element and zone for a face.
472 FaceLeftElems_Prism[0] = -1;
473 /* DOCEND */
475 /* DOCSTART:arrow_tecpoly_prism.txt*/
477 INTEGER4 *FaceBndryConnCounts_Prism = new INTEGER4[NumConnBndryFaces_Prism];
478 FaceBndryConnCounts_Prism[0] = 2;
480 INTEGER4 *FaceBndryConnElems_Prism = new INTEGER4[TotalNumBndryConns_Prism];
481 INTEGER4 *FaceBndryConnZones_Prism = new INTEGER4[TotalNumBndryConns_Prism];
483 /* As previously mentioned, a connected boundary face is a face
484 * that has either multiple neighboring faces or neighbor(s) that
485 * belong to another zone. Those cases are sufficient when the
486 * combination of all of the face’s neighbors completely cover the
487 * face. However, there are some cases (such as the bottom of the
488 * arrowhead) where the face is not completely covered by its
489 * neighbors. In those cases the face is referred to as “partially
490 * obscured”. A partially obscured face is indicated by
491 * incrementing the value in TotalNumConnectedBoundaryFaces and
492 * entering a value of 0 in both the FaceBndryConnectionElems and
493 * FaceBoundaryConnectionZones arrays for the boundary connection
494 * for the partially obscured face.
496 FaceBndryConnElems_Prism[0] = 0;
497 FaceBndryConnZones_Prism[0] = 0;
499 /* Indicates that Face 1 is connected to Element 1 in Zone 1. */
500 FaceBndryConnElems_Prism[1] = 1;
501 FaceBndryConnZones_Prism[1] = 1;
503 I = TECPOLY112(FaceNodeCounts_Prism,
504 FaceNodes_Prism,
505 FaceLeftElems_Prism,
506 FaceRightElems_Prism,
507 FaceBndryConnCounts_Prism,
508 FaceBndryConnElems_Prism,
509 FaceBndryConnZones_Prism);
511 /* cleanup */
512 delete X_Prism;
513 delete Y_Prism;
514 delete Z_Prism;
515 delete P_Prism;
516 delete FaceNodeCounts_Prism;
517 delete FaceNodes_Prism;
518 delete FaceLeftElems_Prism;
519 delete FaceRightElems_Prism;
520 delete FaceBndryConnCounts_Prism;
521 delete FaceBndryConnElems_Prism;
522 delete FaceBndryConnZones_Prism;
523 /* DOCEND */
525 /* DOCSTART:arrow_tecend.txt*/
526 I = TECEND112();
527 /* DOCEND */
529 return 0;