vtkPV3FoamVolFields.H 9.41 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
     \\/     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

InClass
    vtkPV3Foam

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

Mark Olesen's avatar
Mark Olesen committed
30
31
#ifndef vtkPV3FoamVolFields_H
#define vtkPV3FoamVolFields_H
32
33
34
35
36

// Foam includes
#include "emptyFvPatchField.H"
#include "wallPolyPatch.H"
#include "faceSet.H"
mattijs's avatar
mattijs committed
37
38
#include "volPointInterpolation.H"

Mark Olesen's avatar
Mark Olesen committed
39
40
#include "vtkPV3FoamFaceField.H"
#include "vtkPV3FoamPatchField.H"
41
42
43
44
45
46
47

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

template<class Type>
void Foam::vtkPV3Foam::convertVolFields
(
    const fvMesh& mesh,
48
    const PtrList<PrimitivePatchInterpolation<primitivePatch> >& ppInterpList,
49
50
51
52
53
54
    const IOobjectList& objects,
    vtkMultiBlockDataSet* output
)
{
    const polyBoundaryMesh& patches = mesh.boundaryMesh();

Mark Olesen's avatar
Mark Olesen committed
55
    forAllConstIter(IOobjectList, objects, iter)
56
    {
Mark Olesen's avatar
Mark Olesen committed
57
58
59
60
61
62
63
64
65
        // restrict to GeometricField<Type, ...>
        if
        (
            iter()->headerClassName()
         != GeometricField<Type, fvPatchField, volMesh>::typeName
        )
        {
            continue;
        }
66

mattijs's avatar
mattijs committed
67
        // Load field
68
69
        GeometricField<Type, fvPatchField, volMesh> tf
        (
Mark Olesen's avatar
Mark Olesen committed
70
            *iter(),
71
72
73
            mesh
        );

mattijs's avatar
mattijs committed
74
75
        // Interpolated field (demand driven)
        autoPtr<GeometricField<Type, pointPatchField, pointMesh> > ptfPtr;
76

77

Mark Olesen's avatar
Mark Olesen committed
78
79
        // Convert activated internalMesh regions
        convertVolFieldBlock
80
        (
Mark Olesen's avatar
Mark Olesen committed
81
            tf,
mattijs's avatar
mattijs committed
82
            ptfPtr,
Mark Olesen's avatar
Mark Olesen committed
83
84
85
86
            output,
            partInfoVolume_,
            regionPolyDecomp_
        );
87

Mark Olesen's avatar
Mark Olesen committed
88
89
90
91
        // Convert activated cellZones
        convertVolFieldBlock
        (
            tf,
mattijs's avatar
mattijs committed
92
            ptfPtr,
Mark Olesen's avatar
Mark Olesen committed
93
94
95
96
97
98
99
100
101
            output,
            partInfoCellZones_,
            zonePolyDecomp_
        );

        // Convert activated cellSets
        convertVolFieldBlock
        (
            tf,
mattijs's avatar
mattijs committed
102
            ptfPtr,
Mark Olesen's avatar
Mark Olesen committed
103
104
105
106
            output,
            partInfoCellSets_,
            csetPolyDecomp_
        );
107
108


109
110
111
        //
        // Convert patches - if activated
        //
112
113
        for
        (
Mark Olesen's avatar
Mark Olesen committed
114
115
116
            int partId = partInfoPatches_.start();
            partId < partInfoPatches_.end();
            ++partId
117
118
        )
        {
Mark Olesen's avatar
Mark Olesen committed
119
120
            const word patchName = getPartName(partId);
            const label datasetNo = partDataset_[partId];
Mark Olesen's avatar
Mark Olesen committed
121
122
            const label patchId = patches.findPatchID(patchName);

Mark Olesen's avatar
Mark Olesen committed
123
            if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
124
125
126
127
            {
                continue;
            }

Mark Olesen's avatar
Mark Olesen committed
128
            const fvPatchField<Type>& ptf = tf.boundaryField()[patchId];
129
130
131
132
133
134

            if
            (
                isType<emptyFvPatchField<Type> >(ptf)
             ||
                (
135
136
                    reader_->GetExtrapolatePatches()
                && !polyPatch::constraintType(patches[patchId].type())
137
138
139
                )
            )
            {
Mark Olesen's avatar
Mark Olesen committed
140
141
142
                fvPatch p(ptf.patch().patch(), tf.mesh().boundary());

                tmp<Field<Type> > tpptf
143
                (
Mark Olesen's avatar
Mark Olesen committed
144
                    fvPatchField<Type>(p, tf).patchInternalField()
145
146
                );

Mark Olesen's avatar
Mark Olesen committed
147
                convertPatchField
148
149
                (
                    tf.name(),
Mark Olesen's avatar
Mark Olesen committed
150
                    tpptf(),
151
                    output,
Mark Olesen's avatar
Mark Olesen committed
152
153
154
155
156
157
158
159
160
161
                    partInfoPatches_,
                    datasetNo
                );

                convertPatchPointField
                (
                    tf.name(),
                    ppInterpList[patchId].faceToPointInterpolate(tpptf)(),
                    output,
                    partInfoPatches_,
Mark Olesen's avatar
Mark Olesen committed
162
                    datasetNo
163
164
165
166
                );
            }
            else
            {
Mark Olesen's avatar
Mark Olesen committed
167
                convertPatchField
168
169
170
171
                (
                    tf.name(),
                    ptf,
                    output,
Mark Olesen's avatar
Mark Olesen committed
172
                    partInfoPatches_,
Mark Olesen's avatar
Mark Olesen committed
173
                    datasetNo
174
175
                );

Mark Olesen's avatar
Mark Olesen committed
176
177
178
179
180
181
182
183
                convertPatchPointField
                (
                    tf.name(),
                    ppInterpList[patchId].faceToPointInterpolate(ptf)(),
                    output,
                    partInfoPatches_,
                    datasetNo
                );
184
185
186
            }
        }

187
188
189
        //
        // Convert face zones - if activated
        //
190
191
        for
        (
Mark Olesen's avatar
Mark Olesen committed
192
193
194
            int partId = partInfoFaceZones_.start();
            partId < partInfoFaceZones_.end();
            ++partId
195
196
        )
        {
Mark Olesen's avatar
Mark Olesen committed
197
198
            const word zoneName = getPartName(partId);
            const label datasetNo = partDataset_[partId];
199

Mark Olesen's avatar
Mark Olesen committed
200
            if (!partStatus_[partId] || datasetNo < 0)
Mark Olesen's avatar
Mark Olesen committed
201
202
203
204
205
206
207
208
            {
                continue;
            }

            const faceZoneMesh& zMesh = mesh.faceZones();
            const label zoneId = zMesh.findZoneID(zoneName);

            if (zoneId < 0)
209
210
211
212
213
214
215
            {
                continue;
            }

            convertFaceField
            (
                tf,
216
                output,
Mark Olesen's avatar
Mark Olesen committed
217
                partInfoFaceZones_,
Mark Olesen's avatar
Mark Olesen committed
218
                datasetNo,
219
                mesh,
Mark Olesen's avatar
Mark Olesen committed
220
                zMesh[zoneId]
221
            );
Mark Olesen's avatar
Mark Olesen committed
222
223

            // TODO: points
224
225
        }

226
227
228
        //
        // Convert face sets - if activated
        //
229
230
        for
        (
Mark Olesen's avatar
Mark Olesen committed
231
232
233
            int partId = partInfoFaceSets_.start();
            partId < partInfoFaceSets_.end();
            ++partId
234
235
        )
        {
Mark Olesen's avatar
Mark Olesen committed
236
237
            const word selectName = getPartName(partId);
            const label datasetNo = partDataset_[partId];
238

Mark Olesen's avatar
Mark Olesen committed
239
            if (!partStatus_[partId] || datasetNo < 0)
240
            {
Mark Olesen's avatar
Mark Olesen committed
241
                continue;
242
243
244
245
246
247
248
            }

            const faceSet fSet(mesh, selectName);

            convertFaceField
            (
                tf,
249
                output,
Mark Olesen's avatar
Mark Olesen committed
250
                partInfoFaceSets_,
Mark Olesen's avatar
Mark Olesen committed
251
                datasetNo,
252
253
254
                mesh,
                fSet
            );
Mark Olesen's avatar
Mark Olesen committed
255
256

            // TODO: points
257
258
259
260
        }
    }
}

mattijs's avatar
mattijs committed
261

Mark Olesen's avatar
Mark Olesen committed
262
263
264
265
template<class Type>
void Foam::vtkPV3Foam::convertVolFieldBlock
(
    const GeometricField<Type, fvPatchField, volMesh>& tf,
mattijs's avatar
mattijs committed
266
    autoPtr<GeometricField<Type, pointPatchField, pointMesh> >& ptfPtr,
Mark Olesen's avatar
Mark Olesen committed
267
268
269
270
271
    vtkMultiBlockDataSet* output,
    const partInfo& selector,
    const List<polyDecomp>& decompLst
)
{
mattijs's avatar
mattijs committed
272
273
274
275
276
277
278
279
280
281
282
283
284
285
    for (int partId = selector.start(); partId < selector.end(); ++partId)
    {
        const label datasetNo = partDataset_[partId];

        if (datasetNo >= 0 && partStatus_[partId])
        {
            convertVolField
            (
                tf,
                output,
                selector,
                datasetNo,
                decompLst[datasetNo]
            );
Mark Olesen's avatar
Mark Olesen committed
286

mattijs's avatar
mattijs committed
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
            if (!ptfPtr.valid())
            {
                if (debug)
                {
                    Info<< "convertVolFieldBlock interpolating:" << tf.name()
                        << endl;
                }

                ptfPtr.reset
                (
                    volPointInterpolation::New(tf.mesh()).interpolate(tf).ptr()
                );
            }

            convertPointField
            (
                ptfPtr(),
                tf,
                output,
                selector,
                datasetNo,
                decompLst[datasetNo]
            );
        }
    }
}
Mark Olesen's avatar
Mark Olesen committed
313

314
315
316
317
318
319

template<class Type>
void Foam::vtkPV3Foam::convertVolField
(
    const GeometricField<Type, fvPatchField, volMesh>& tf,
    vtkMultiBlockDataSet* output,
Mark Olesen's avatar
Mark Olesen committed
320
    const partInfo& selector,
321
    const label datasetNo,
Mark Olesen's avatar
Mark Olesen committed
322
    const polyDecomp& decompInfo
323
324
)
{
325
    const label nComp = pTraits<Type>::nComponents;
Mark Olesen's avatar
Mark Olesen committed
326
    const labelList& superCells = decompInfo.superCells();
327
328

    vtkFloatArray* celldata = vtkFloatArray::New();
Andrew Heather's avatar
Andrew Heather committed
329
330
331
332
    celldata->SetNumberOfTuples(superCells.size());
    celldata->SetNumberOfComponents(nComp);
    celldata->Allocate(nComp*superCells.size());
    celldata->SetName(tf.name().c_str());
333
334
335

    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
336
337
338
339
340
        Info<< "convert volField: "
            << tf.name()
            << " size = " << tf.size()
            << " nComp=" << nComp
            << " nTuples = " << superCells.size() <<  endl;
341
342
    }

343
    float vec[nComp];
Mark Olesen's avatar
Mark Olesen committed
344
    forAll(superCells, i)
345
    {
Mark Olesen's avatar
Mark Olesen committed
346
        const Type& t = tf[superCells[i]];
347
        for (direction d=0; d<nComp; d++)
348
        {
349
            vec[d] = component(t, d);
350
        }
Mark Olesen's avatar
Mark Olesen committed
351
        celldata->InsertTuple(i, vec);
352
353
    }

Mark Olesen's avatar
Mark Olesen committed
354
355
356
357
358
359
    vtkUnstructuredGrid::SafeDownCast
    (
        GetDataSetFromBlock(output, selector, datasetNo)
    )   ->GetCellData()
        ->AddArray(celldata);

360
361
362
363
364
365
366
367
368
    celldata->Delete();
}


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

#endif

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