vtkPV3FoamUpdateInfo.C 12.1 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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
     \\/     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 2 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, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

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

#include "vtkPV3Foam.H"

// Foam includes
#include "cellSet.H"
#include "faceSet.H"
32
#include "pointSet.H"
33
34
35
36
#include "IOobjectList.H"
#include "IOPtrList.H"
#include "polyBoundaryMeshEntries.H"
#include "entry.H"
Mark Olesen's avatar
Mark Olesen committed
37
#include "Cloud.H"
38
39
#include "vtkPV3FoamReader.h"

Mark Olesen's avatar
Mark Olesen committed
40
41
// local headers
#include "vtkPV3FoamAddToSelection.H"
Mark Olesen's avatar
Mark Olesen committed
42
#include "vtkPV3FoamUpdateInfoFields.H"
Mark Olesen's avatar
Mark Olesen committed
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
// VTK includes
#include "vtkDataArraySelection.h"


// * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //

namespace Foam
{

//- A class for reading zone information without requiring a mesh
class zonesEntries
:
    public regIOobject,
    public PtrList<entry>
{

public:

    // Constructors

        explicit zonesEntries(const IOobject& io)
        :
            regIOobject(io),
            PtrList<entry>(readStream("regIOobject"))
        {
            close();
        }

   // Member functions

        bool writeData(Ostream&) const
        {
            notImplemented("zonesEntries::writeData(Ostream&) const");
            return false;
        }
};

}

Mark Olesen's avatar
Mark Olesen committed
83
84
85
86
87
88
89
90
91
92
93
94
// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

Foam::wordList Foam::vtkPV3Foam::readZoneNames(const word& zoneType)
{
    wordList zoneNames;

    // mesh not loaded - read from file
    IOobject ioObj
    (
        zoneType,
        dbPtr_().findInstance
        (
95
            meshDir_,
Mark Olesen's avatar
Mark Olesen committed
96
97
98
            zoneType,
            IOobject::READ_IF_PRESENT
        ),
99
        meshDir_,
Mark Olesen's avatar
Mark Olesen committed
100
101
102
103
104
105
106
107
108
109
110
        dbPtr_(),
        IOobject::READ_IF_PRESENT,
        IOobject::NO_WRITE,
        false
    );

    if (ioObj.headerOk())
    {
        zonesEntries zones(ioObj);

        zoneNames.setSize(zones.size());
Mark Olesen's avatar
Mark Olesen committed
111
        forAll(zones, zoneI)
Mark Olesen's avatar
Mark Olesen committed
112
113
114
115
116
117
118
        {
            zoneNames[zoneI] = zones[zoneI].keyword();
        }
    }

    return zoneNames;
}
119
120


Mark Olesen's avatar
Mark Olesen committed
121
void Foam::vtkPV3Foam::updateInfoInternalMesh()
122
123
124
{
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
125
        Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
126
127
    }

Mark Olesen's avatar
Mark Olesen committed
128
    vtkDataArraySelection* partSelection = reader_->GetPartSelection();
129

Mark Olesen's avatar
Mark Olesen committed
130
    // Determine mesh parts (internalMesh, patches...)
131
    //- Add internal mesh as first entry
Mark Olesen's avatar
Mark Olesen committed
132
133
134
    partInfoVolume_ = partSelection->GetNumberOfArrays();
    partSelection->AddArray("internalMesh");
    partInfoVolume_ += 1;
135
136
137

    if (debug)
    {
138
        // just for debug info
Mark Olesen's avatar
Mark Olesen committed
139
        getSelectedArrayEntries(partSelection);
140

Mark Olesen's avatar
Mark Olesen committed
141
        Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
142
143
    }

144
145
146
}


Mark Olesen's avatar
Mark Olesen committed
147
void Foam::vtkPV3Foam::updateInfoLagrangian()
148
149
150
{
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
151
        Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangian" << nl
152
            << "    " << dbPtr_->timePath()/cloud::prefix << endl;
153
154
    }

155
156
157

    // use the db directly since this might be called without a mesh,
    // but the region must get added back in
158
    fileName lagrangianPrefix(cloud::prefix);
159
160
    if (meshRegion_ != polyMesh::defaultRegion)
    {
161
        lagrangianPrefix = meshRegion_/cloud::prefix;
162
163
    }

164
165
166
    // Search for list of lagrangian objects for this time
    fileNameList cloudDirs
    (
167
        readDir(dbPtr_->timePath()/lagrangianPrefix, fileName::DIRECTORY)
168
169
    );

Mark Olesen's avatar
Mark Olesen committed
170
171
    vtkDataArraySelection* partSelection = reader_->GetPartSelection();
    partInfoLagrangian_ = partSelection->GetNumberOfArrays();
172

Mark Olesen's avatar
Mark Olesen committed
173
174
    int nClouds = 0;
    forAll(cloudDirs, cloudI)
175
    {
Mark Olesen's avatar
Mark Olesen committed
176
        // Add cloud to GUI list
Mark Olesen's avatar
Mark Olesen committed
177
        partSelection->AddArray
Mark Olesen's avatar
Mark Olesen committed
178
179
180
        (
            (cloudDirs[cloudI] + " - lagrangian").c_str()
        );
181

Mark Olesen's avatar
Mark Olesen committed
182
        ++nClouds;
183
184
    }

Mark Olesen's avatar
Mark Olesen committed
185
    partInfoLagrangian_ += nClouds;
Mark Olesen's avatar
Mark Olesen committed
186

187
188
    if (debug)
    {
189
        // just for debug info
Mark Olesen's avatar
Mark Olesen committed
190
        getSelectedArrayEntries(partSelection);
191

Mark Olesen's avatar
Mark Olesen committed
192
        Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl;
193
    }
194
195
196
}


Mark Olesen's avatar
Mark Olesen committed
197
void Foam::vtkPV3Foam::updateInfoPatches()
198
199
200
{
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
201
        Info<< "<beg> Foam::vtkPV3Foam::updateInfoPatches"
202
            << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
203
204
    }

Mark Olesen's avatar
Mark Olesen committed
205
206
    vtkDataArraySelection* partSelection = reader_->GetPartSelection();
    partInfoPatches_ = partSelection->GetNumberOfArrays();
Mark Olesen's avatar
Mark Olesen committed
207

208
    int nPatches = 0;
Mark Olesen's avatar
Mark Olesen committed
209
    if (meshPtr_)
210
    {
Mark Olesen's avatar
Mark Olesen committed
211
        const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
Mark Olesen's avatar
Mark Olesen committed
212
        forAll(patches, patchI)
213
        {
Mark Olesen's avatar
Mark Olesen committed
214
215
216
217
            const polyPatch& pp = patches[patchI];

            if (pp.size())
            {
Mark Olesen's avatar
Mark Olesen committed
218
                // Add patch to GUI list
Mark Olesen's avatar
Mark Olesen committed
219
                partSelection->AddArray
Mark Olesen's avatar
Mark Olesen committed
220
221
222
223
224
225
226
227
228
229
                (
                    (pp.name() + " - patch").c_str()
                );

                ++nPatches;
            }
        }
    }
    else
    {
230
231
232
        // mesh not loaded - read from file
        // but this could fail if we've supplied a bad region name
        IOobject ioObj
Mark Olesen's avatar
Mark Olesen committed
233
        (
234
235
            "boundary",
            dbPtr_().findInstance
236
            (
237
                meshDir_,
Mark Olesen's avatar
Mark Olesen committed
238
                "boundary",
239
240
241
242
243
244
245
                IOobject::READ_IF_PRESENT
            ),
            meshDir_,
            dbPtr_(),
            IOobject::READ_IF_PRESENT,
            IOobject::NO_WRITE,
            false
Mark Olesen's avatar
Mark Olesen committed
246
247
        );

248
249
        // this should only ever fail if the mesh region doesn't exist
        if (ioObj.headerOk())
Mark Olesen's avatar
Mark Olesen committed
250
        {
251
            polyBoundaryMeshEntries patchEntries(ioObj);
252

253
254
            // Add (non-zero) patches to the list of mesh parts
            forAll(patchEntries, entryI)
Mark Olesen's avatar
Mark Olesen committed
255
            {
256
                label nFaces
Mark Olesen's avatar
Mark Olesen committed
257
                (
258
                    readLabel(patchEntries[entryI].dict().lookup("nFaces"))
Mark Olesen's avatar
Mark Olesen committed
259
260
                );

261
262
263
264
265
266
267
268
269
270
                // Valid patch if nFace > 0 - add patch to GUI list
                if (nFaces)
                {
                    partSelection->AddArray
                    (
                        (patchEntries[entryI].keyword() + " - patch").c_str()
                    );

                    ++nPatches;
                }
Mark Olesen's avatar
Mark Olesen committed
271
            }
272
273
        }
    }
Mark Olesen's avatar
Mark Olesen committed
274
    partInfoPatches_ += nPatches;
275

276
277
    if (debug)
    {
278
        // just for debug info
Mark Olesen's avatar
Mark Olesen committed
279
        getSelectedArrayEntries(partSelection);
280

Mark Olesen's avatar
Mark Olesen committed
281
        Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl;
282
    }
283
284
285
}


Mark Olesen's avatar
Mark Olesen committed
286
void Foam::vtkPV3Foam::updateInfoZones()
287
{
Mark Olesen's avatar
Mark Olesen committed
288
289
290
291
292
    if (!reader_->GetIncludeZones())
    {
        return;
    }

293
294
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
295
        Info<< "<beg> Foam::vtkPV3Foam::updateInfoZones"
296
            << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
297
298
    }

Mark Olesen's avatar
Mark Olesen committed
299
    vtkDataArraySelection* partSelection = reader_->GetPartSelection();
Mark Olesen's avatar
Mark Olesen committed
300
    wordList namesLst;
301
302
303
304
305

    //
    // cellZones information
    // ~~~~~~~~~~~~~~~~~~~~~
    if (meshPtr_)
306
    {
Mark Olesen's avatar
Mark Olesen committed
307
        namesLst = meshPtr_->cellZones().names();
308
309
310
    }
    else
    {
Mark Olesen's avatar
Mark Olesen committed
311
        namesLst = readZoneNames("cellZones");
312
    }
313

Mark Olesen's avatar
Mark Olesen committed
314
    partInfoCellZones_ = partSelection->GetNumberOfArrays();
Mark Olesen's avatar
Mark Olesen committed
315
    forAll(namesLst, elemI)
316
    {
Mark Olesen's avatar
Mark Olesen committed
317
        partSelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
318
    }
Mark Olesen's avatar
Mark Olesen committed
319
    partInfoCellZones_ += namesLst.size();
320

321

322
323
324
325
    //
    // faceZones information
    // ~~~~~~~~~~~~~~~~~~~~~
    if (meshPtr_)
326
    {
Mark Olesen's avatar
Mark Olesen committed
327
        namesLst = meshPtr_->faceZones().names();
328
329
330
    }
    else
    {
Mark Olesen's avatar
Mark Olesen committed
331
        namesLst = readZoneNames("faceZones");
332
333
    }

Mark Olesen's avatar
Mark Olesen committed
334
    partInfoFaceZones_ = partSelection->GetNumberOfArrays();
Mark Olesen's avatar
Mark Olesen committed
335
    forAll(namesLst, elemI)
336
    {
Mark Olesen's avatar
Mark Olesen committed
337
        partSelection->AddArray
Mark Olesen's avatar
Mark Olesen committed
338
339
340
        (
            (namesLst[elemI] + " - faceZone").c_str()
        );
341
    }
Mark Olesen's avatar
Mark Olesen committed
342
    partInfoFaceZones_ += namesLst.size();
343
344
345
346
347
348
349


    //
    // pointZones information
    // ~~~~~~~~~~~~~~~~~~~~~~
    if (meshPtr_)
    {
Mark Olesen's avatar
Mark Olesen committed
350
        namesLst = meshPtr_->pointZones().names();
351
352
353
    }
    else
    {
Mark Olesen's avatar
Mark Olesen committed
354
        namesLst = readZoneNames("pointZones");
355
356
    }

Mark Olesen's avatar
Mark Olesen committed
357
    partInfoPointZones_ = partSelection->GetNumberOfArrays();
Mark Olesen's avatar
Mark Olesen committed
358
    forAll(namesLst, elemI)
359
    {
Mark Olesen's avatar
Mark Olesen committed
360
        partSelection->AddArray
Mark Olesen's avatar
Mark Olesen committed
361
362
363
        (
            (namesLst[elemI] + " - pointZone").c_str()
        );
364
    }
Mark Olesen's avatar
Mark Olesen committed
365
    partInfoPointZones_ += namesLst.size();
366

367
368
369

    if (debug)
    {
370
        // just for debug info
Mark Olesen's avatar
Mark Olesen committed
371
        getSelectedArrayEntries(partSelection);
372

Mark Olesen's avatar
Mark Olesen committed
373
        Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl;
374
    }
375
376
377
}


Mark Olesen's avatar
Mark Olesen committed
378
void Foam::vtkPV3Foam::updateInfoSets()
379
{
Mark Olesen's avatar
Mark Olesen committed
380
381
382
383
384
    if (!reader_->GetIncludeSets())
    {
        return;
    }

385
386
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
387
        Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl;
388
389
    }

Mark Olesen's avatar
Mark Olesen committed
390
    vtkDataArraySelection* partSelection = reader_->GetPartSelection();
391

392
    // Add names of sets
393
394
395
    IOobjectList objects
    (
        dbPtr_(),
396
397
        dbPtr_().findInstance(meshDir_, "faces", IOobject::READ_IF_PRESENT),
        meshDir_/"sets"
398
399
400
    );


Mark Olesen's avatar
Mark Olesen committed
401
402
    partInfoCellSets_ = partSelection->GetNumberOfArrays();
    partInfoCellSets_ += addToSelection<cellSet>
403
    (
Mark Olesen's avatar
Mark Olesen committed
404
        partSelection,
405
406
407
408
        objects,
        " - cellSet"
    );

Mark Olesen's avatar
Mark Olesen committed
409
410
    partInfoFaceSets_ = partSelection->GetNumberOfArrays();
    partInfoFaceSets_ += addToSelection<faceSet>
411
    (
Mark Olesen's avatar
Mark Olesen committed
412
        partSelection,
413
414
415
416
        objects,
        " - faceSet"
    );

Mark Olesen's avatar
Mark Olesen committed
417
418
    partInfoPointSets_ = partSelection->GetNumberOfArrays();
    partInfoPointSets_ += addToSelection<pointSet>
419
    (
Mark Olesen's avatar
Mark Olesen committed
420
        partSelection,
421
422
423
        objects,
        " - pointSet"
    );
424
425
426

    if (debug)
    {
427
        // just for debug info
Mark Olesen's avatar
Mark Olesen committed
428
        getSelectedArrayEntries(partSelection);
429

Mark Olesen's avatar
Mark Olesen committed
430
        Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl;
431
    }
432
433
434
}


Mark Olesen's avatar
Mark Olesen committed
435
void Foam::vtkPV3Foam::updateInfoLagrangianFields()
436
437
438
{
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
439
        Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangianFields"
440
441
442
            << endl;
    }

Mark Olesen's avatar
Mark Olesen committed
443
    vtkDataArraySelection *fieldSelection =
444
445
        reader_->GetLagrangianFieldSelection();

446
    // preserve the enabled selections
Mark Olesen's avatar
Mark Olesen committed
447
    stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
Mark Olesen's avatar
Mark Olesen committed
448
449
450
    fieldSelection->RemoveAllArrays();

    //
Mark Olesen's avatar
Mark Olesen committed
451
452
453
    // TODO - currently only get fields from ONE cloud
    // have to decide if the second set of fields get mixed in
    // or dealt with separately
Mark Olesen's avatar
Mark Olesen committed
454

Mark Olesen's avatar
Mark Olesen committed
455
456
    const partInfo& selector = partInfoLagrangian_;
    int partId = selector.start();
Mark Olesen's avatar
Mark Olesen committed
457

Mark Olesen's avatar
Mark Olesen committed
458
    if (!selector.size() || partId < 0)
Mark Olesen's avatar
Mark Olesen committed
459
460
461
462
    {
        return;
    }

Mark Olesen's avatar
Mark Olesen committed
463
    word cloudName = getPartName(partId);
464

465
466
    // use the db directly since this might be called without a mesh,
    // but the region must get added back in
467
    fileName lagrangianPrefix(cloud::prefix);
468
469
    if (meshRegion_ != polyMesh::defaultRegion)
    {
470
        lagrangianPrefix = meshRegion_/cloud::prefix;
471
472
    }

473
474
475
476
    IOobjectList objects
    (
        dbPtr_(),
        dbPtr_().timeName(),
477
        lagrangianPrefix/cloudName
478
479
    );

480
    addToSelection<IOField<label> >
481
    (
Mark Olesen's avatar
Mark Olesen committed
482
        fieldSelection,
483
484
        objects
    );
485
    addToSelection<IOField<scalar> >
486
    (
Mark Olesen's avatar
Mark Olesen committed
487
        fieldSelection,
488
489
        objects
    );
490
    addToSelection<IOField<vector> >
491
    (
Mark Olesen's avatar
Mark Olesen committed
492
        fieldSelection,
493
494
        objects
    );
495
    addToSelection<IOField<sphericalTensor> >
496
    (
Mark Olesen's avatar
Mark Olesen committed
497
        fieldSelection,
Mark Olesen's avatar
Mark Olesen committed
498

499
500
        objects
    );
501
    addToSelection<IOField<symmTensor> >
502
    (
Mark Olesen's avatar
Mark Olesen committed
503
        fieldSelection,
504
505
        objects
    );
506
    addToSelection<IOField<tensor> >
507
    (
Mark Olesen's avatar
Mark Olesen committed
508
        fieldSelection,
509
510
511
        objects
    );

512
    // restore the enabled selections
Mark Olesen's avatar
Mark Olesen committed
513
    setSelectedArrayEntries(fieldSelection, enabledEntries);
514
515
516

    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
517
        Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangianFields - "
518
            << "lagrangian objects.size() = " << objects.size() << endl;
519
520
521
    }
}

Mark Olesen's avatar
Mark Olesen committed
522

523
// ************************************************************************* //