File: tecplotWriter.C

package info (click to toggle)
openfoam 4.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 163,028 kB
  • ctags: 58,990
  • sloc: cpp: 830,760; sh: 10,227; ansic: 8,215; xml: 745; lex: 437; awk: 194; sed: 91; makefile: 77; python: 18
file content (515 lines) | stat: -rw-r--r-- 14,804 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "tecplotWriter.H"
#include "fvMesh.H"

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

// Construct from components
Foam::tecplotWriter::tecplotWriter(const Time& runTime)
:
    runTime_(runTime)
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void Foam::tecplotWriter::writeInit
(
    const word& name,
    const string& varNames,
    const fileName& fName,
    INTEGER4 tecplotFileType
) const
{
Pout<< endl
    << endl
    << "Name:" << name
    << " varNames:" << varNames
    << " to file:" << fName
    << " of type:" << tecplotFileType
    << endl;

    INTEGER4 IsDouble = 0;  //float
    INTEGER4 Debug = 0;     //nodebug
    if
    (
        !TECINI112
        (
            const_cast<char*>(name.c_str()),       /* Data Set Title       */
            const_cast<char*>(varNames.c_str()),   /* Variable List        */
            const_cast<char*>(fName.c_str()),      /* File Name            */
            const_cast<char*>(runTime_.path().c_str()), /* Scratch Directory */
            &tecplotFileType,
            &Debug,
            &IsDouble
        )
    )
    {
//        FatalErrorInFunction
//            << "Error in TECINI112." << exit(FatalError);
    }
}


void Foam::tecplotWriter::writePolyhedralZone
(
    const word& zoneName,
    INTEGER4 strandID,
    const fvMesh& mesh,
    const List<INTEGER4>& varLocArray,
    INTEGER4 nFaceNodes
) const
{
    /* Call TECZNE112 */
    INTEGER4  NumNodes   = mesh.nPoints();         /* number of unique nodes */
    INTEGER4  NumElems   = mesh.nCells();         /* number of elements */
    INTEGER4  NumFaces   = mesh.nFaces();         /* number of unique faces */

    INTEGER4  ICellMax   = 0;         /* Not Used, set to zero */
    INTEGER4  JCellMax   = 0;         /* Not Used, set to zero */
    INTEGER4  KCellMax   = 0;         /* Not Used, set to zero */

    double    SolTime    = runTime_.value();     /* solution time   */
    INTEGER4  ParentZone = 0;         /* no parent zone  */

    INTEGER4  IsBlock    = 1;         /* block format  */

    INTEGER4  NFConns    = 0;         /* not used for FEPolyhedron
                                       * zones
                                       */
    INTEGER4  FNMode     = 0;         /* not used for FEPolyhedron
                                       * zones
                                       */
Pout<< "zoneName:" << zoneName
    //<< " varLocArray:" << varLocArray
    << " solTime:" << SolTime
    << endl;



    INTEGER4 *PassiveVarArray = NULL;
    INTEGER4 *VarShareArray   = NULL;
    INTEGER4  ShrConn         = 0;

    INTEGER4  NumBConns       = 0;   /* No Boundary Connections */
    INTEGER4  NumBItems       = 0;   /* No Boundary Items */

    INTEGER4  ZoneType = ZoneType_FEPolyhedron;

    if
    (
       !TECZNE112
        (
            const_cast<char*>(zoneName.c_str()),
            &ZoneType,
            &NumNodes,
            &NumElems,
            &NumFaces,
            &ICellMax,
            &JCellMax,
            &KCellMax,
            &SolTime,
            &strandID,
            &ParentZone,
            &IsBlock,
            &NFConns,
            &FNMode,
            &nFaceNodes,
            &NumBConns,
            &NumBItems,
            PassiveVarArray,
            const_cast<INTEGER4*>(varLocArray.begin()),
            VarShareArray,
            &ShrConn
        )
    )
    {
//        FatalErrorInFunction
//            << "Error in TECZNE112." << exit(FatalError);
    }
}


void Foam::tecplotWriter::writePolygonalZone
(
    const word& zoneName,
    INTEGER4 strandID,
    const indirectPrimitivePatch& pp,
    const List<INTEGER4>& varLocArray
) const
{
    /* Call TECZNE112 */
    INTEGER4  NumNodes   = pp.nPoints();         /* number of unique nodes */
    INTEGER4  NumElems   = pp.size();         /* number of elements */
    INTEGER4  NumFaces   = pp.nEdges();         /* number of unique faces */

    INTEGER4  ICellMax   = 0;         /* Not Used, set to zero */
    INTEGER4  JCellMax   = 0;         /* Not Used, set to zero */
    INTEGER4  KCellMax   = 0;         /* Not Used, set to zero */

    double    SolTime    = runTime_.value();     /* solution time   */
    INTEGER4  ParentZone = 0;         /* no parent zone  */

    INTEGER4  IsBlock    = 1;         /* block format  */

    INTEGER4  NFConns    = 0;         /* not used for FEPolyhedron
                                       * zones
                                       */
    INTEGER4  FNMode     = 0;         /* not used for FEPolyhedron
                                       * zones
                                       */
    INTEGER4  NumFaceNodes    = 2*pp.nEdges();

Pout<< "zoneName:" << zoneName
    << " strandID:" << strandID
    //<< " varLocArray:" << varLocArray
    << " solTime:" << SolTime
    << endl;


    INTEGER4 *PassiveVarArray = NULL;
    INTEGER4 *VarShareArray   = NULL;
    INTEGER4  ShrConn         = 0;

    INTEGER4  NumBConns       = 0;   /* No Boundary Connections */
    INTEGER4  NumBItems       = 0;   /* No Boundary Items */

    INTEGER4  ZoneType = ZoneType_FEPolygon;

    if
    (
       !TECZNE112
        (
            const_cast<char*>(zoneName.c_str()),
            &ZoneType,
            &NumNodes,
            &NumElems,
            &NumFaces,
            &ICellMax,
            &JCellMax,
            &KCellMax,
            &SolTime,
            &strandID,
            &ParentZone,
            &IsBlock,
            &NFConns,
            &FNMode,
            &NumFaceNodes,
            &NumBConns,
            &NumBItems,
            PassiveVarArray,
            const_cast<INTEGER4*>(varLocArray.begin()),
            VarShareArray,
            &ShrConn
        )
    )
    {
//        FatalErrorInFunction
//            << "Error in TECZNE112." << exit(FatalError);
    }
}


void Foam::tecplotWriter::writeOrderedZone
(
    const word& zoneName,
    INTEGER4 strandID,
    const label n,
    const List<INTEGER4>& varLocArray
) const
{
    /* Call TECZNE112 */
    INTEGER4  IMax   = n;         /* number of unique nodes */
    INTEGER4  JMax   = 1;         /* number of elements */
    INTEGER4  KMax   = 1;         /* number of unique faces */

    INTEGER4  ICellMax   = 0;         /* Not Used, set to zero */
    INTEGER4  JCellMax   = 0;         /* Not Used, set to zero */
    INTEGER4  KCellMax   = 0;         /* Not Used, set to zero */

    double    SolTime    = runTime_.value();     /* solution time   */
    INTEGER4  ParentZone = 0;         /* no parent zone  */

    INTEGER4  IsBlock    = 1;         /* block format  */

    INTEGER4  NFConns    = 0;         /* not used for FEPolyhedron
                                       * zones
                                       */
    INTEGER4  FNMode     = 0;         /* not used for FEPolyhedron
                                       * zones
                                       */
    INTEGER4  NumFaceNodes    = 1;
    INTEGER4  NumBConns       = 1;   /* No Boundary Connections */
    INTEGER4  NumBItems       = 1;   /* No Boundary Items */

Pout<< "zoneName:" << zoneName
    << " strandID:" << strandID
    //<< " varLocArray:" << varLocArray
    << " solTime:" << SolTime
    << endl;


    INTEGER4 *PassiveVarArray = NULL;
    INTEGER4 *VarShareArray   = NULL;
    INTEGER4  ShrConn         = 0;


    INTEGER4  ZoneType = ZoneType_Ordered;

    if
    (
       !TECZNE112
        (
            const_cast<char*>(zoneName.c_str()),
            &ZoneType,
            &IMax,
            &JMax,
            &KMax,
            &ICellMax,
            &JCellMax,
            &KCellMax,
            &SolTime,
            &strandID,
            &ParentZone,
            &IsBlock,
            &NFConns,
            &FNMode,
            &NumFaceNodes,
            &NumBConns,
            &NumBItems,
            PassiveVarArray,
            const_cast<INTEGER4*>(varLocArray.begin()),
            VarShareArray,
            &ShrConn
        )
    )
    {
//        FatalErrorInFunction
//            << "Error in TECZNE112." << exit(FatalError);
    }
}


void Foam::tecplotWriter::writeConnectivity(const fvMesh& mesh) const
{
    List<INTEGER4> FaceNodeCounts(mesh.nFaces());

    forAll(mesh.faces(), facei)
    {
        const face& f = mesh.faces()[facei];
        FaceNodeCounts[facei] = INTEGER4(f.size());
    }


    INTEGER4 nFaceNodes = 0;
    forAll(mesh.faces(), facei)
    {
        nFaceNodes += mesh.faces()[facei].size();
    }


    List<INTEGER4> FaceNodes(nFaceNodes);
    label nodeI = 0;
    forAll(mesh.faces(), facei)
    {
        const face& f = mesh.faces()[facei];
        forAll(f, fp)
        {
            FaceNodes[nodeI++] = INTEGER4(f[fp]+1);
        }
    }


    List<INTEGER4> FaceLeftElems(mesh.nFaces());
    forAll(mesh.faceOwner(), facei)
    {
        FaceLeftElems[facei] = mesh.faceOwner()[facei]+1;
    }

    List<INTEGER4> FaceRightElems(mesh.nFaces());
    forAll(mesh.faceNeighbour(), facei)
    {
        FaceRightElems[facei] = mesh.faceNeighbour()[facei]+1;
    }
    for
    (
        label facei = mesh.nInternalFaces();
        facei < mesh.nFaces();
        facei++
    )
    {
        FaceRightElems[facei] = 0;
    }

    if
    (
       !TECPOLY112
        (
            FaceNodeCounts.begin(), /* The face node counts array */
            FaceNodes.begin(),      /* The face nodes array */
            FaceLeftElems.begin(),  /* The left elements array  */
            FaceRightElems.begin(), /* The right elements array  */
            NULL,       /* No boundary connection counts */
            NULL,       /* No boundary connection elements */
            NULL        /* No boundary connection zones */
        )
    )
    {
//        FatalErrorInFunction
//            << "Error in TECPOLY112." << exit(FatalError);
    }
}


void Foam::tecplotWriter::writeConnectivity
(
    const indirectPrimitivePatch& pp
) const
{
    INTEGER4  NumFaces   = pp.nEdges();         /* number of unique faces */
    INTEGER4  NumFaceNodes    = 2*pp.nEdges();

    // All faces (=edges) have 2 nodes
    List<INTEGER4> FaceNodeCounts(NumFaces, 2);

    List<INTEGER4> FaceNodes(NumFaceNodes);
    label nodeI = 0;
    forAll(pp.edges(), edgeI)
    {
        edge e = pp.edges()[edgeI];
        if (e[0] > e[1])
        {
            e.flip();
        }

        FaceNodes[nodeI++] = INTEGER4(e[0]+1);
        FaceNodes[nodeI++] = INTEGER4(e[1]+1);
    }

    /* Define the right and left elements of each face.
     *
     * The last step for writing out the polyhedral data is to
     * define the right and left neighboring elements for each
     * face.  The neighboring elements can be determined using the
     * right-hand rule.  For each face, place your right-hand along
     * the face which your fingers pointing the direction of
     * incrementing node numbers (i.e. from node 1 to node 2).
     * Your right thumb will point towards the right element; the
     * element on the other side of your hand is the left element.
     *
     * The number zero is used to indicate that there isn't an
     * element on that side of the face.
     *
     * Because of the way we numbered the nodes and faces, the
     * right element for every face is the element itself
     * (element 1) and the left element is "no-neighboring element"
     * (element 0).
     */

    List<INTEGER4> FaceLeftElems(NumFaces);
    List<INTEGER4> FaceRightElems(NumFaces);

    const labelListList& edgeFaces = pp.edgeFaces();
    forAll(edgeFaces, edgeI)
    {
        const labelList& eFaces = edgeFaces[edgeI];

        if (eFaces.size() == 1)
        {
            FaceLeftElems[edgeI] = 0;
            FaceRightElems[edgeI] = eFaces[0]+1;
        }
        else if (eFaces.size() == 2)
        {
            edge e = pp.edges()[edgeI];
            if (e[0] > e[1])
            {
                e.flip();
            }

            const face& f0 = pp.localFaces()[eFaces[0]];

            // The face that uses the vertices of e in increasing order
            // is the left face.

            label fp = findIndex(f0, e[0]);
            bool f0IsLeft = (f0.nextLabel(fp) == e[1]);

            if (f0IsLeft)
            {
                FaceLeftElems[edgeI] = eFaces[0]+1;
                FaceRightElems[edgeI] = eFaces[1]+1;
            }
            else
            {
                FaceLeftElems[edgeI] = eFaces[1]+1;
                FaceRightElems[edgeI] = eFaces[0]+1;
            }
        }
        else
        {
            // non-manifold. Treat as if open.
            FaceLeftElems[edgeI] = 0;
            FaceRightElems[edgeI] = eFaces[0]+1;
        }
    }

    /* Write the face map (created above) using TECPOLY112. */
    if
    (
       !TECPOLY112
        (
            FaceNodeCounts.begin(), /* The face node counts array */
            FaceNodes.begin(),      /* The face nodes array */
            FaceLeftElems.begin(),  /* The left elements array  */
            FaceRightElems.begin(), /* The right elements array  */
            NULL,       /* No boundary connection counts */
            NULL,       /* No boundary connection elements */
            NULL        /* No boundary connection zones */
        )
    )
    {
//        FatalErrorInFunction
//            << "Error in TECPOLY112." << exit(FatalError);
    }
}


void Foam::tecplotWriter::writeEnd() const
{
Pout<< "writeEnd" << endl;

    if (!TECEND112())
    {
//        FatalErrorInFunction
//            << "Error in TECEND112." << exit(FatalError);
    }

}


// ************************************************************************* //