vtkPV3FoamPointFields.H 7.09 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 vtkPV3FoamPointFields_H
#define vtkPV3FoamPointFields_H
32
33
34
35
36
37
38
39
40
41

// Foam includes
#include "interpolatePointToCell.H"

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

template<class Type>
void Foam::vtkPV3Foam::convertPointFields
(
    const fvMesh& mesh,
Mark Olesen's avatar
Mark Olesen committed
42
    const pointMesh& pMesh,
43
44
45
46
47
48
    const IOobjectList& objects,
    vtkMultiBlockDataSet* output
)
{
    const polyBoundaryMesh& patches = mesh.boundaryMesh();

Mark Olesen's avatar
Mark Olesen committed
49
    forAllConstIter(IOobjectList, objects, iter)
50
    {
Mark Olesen's avatar
Mark Olesen committed
51
52
53
54
55
56
57
58
59
60
        const word& fieldName = iter()->name();
        // restrict to this GeometricField<Type, ...>
        if
        (
            iter()->headerClassName()
         != GeometricField<Type, pointPatchField, pointMesh>::typeName
        )
        {
            continue;
        }
61

62
63
64
65
66
        if (debug)
        {
            Info<< "Foam::vtkPV3Foam::convertPointFields : "
                << fieldName << endl;
        }
67

68
69
        GeometricField<Type, pointPatchField, pointMesh> ptf
        (
Mark Olesen's avatar
Mark Olesen committed
70
            *iter(),
71
72
73
74
            pMesh
        );


Mark Olesen's avatar
Mark Olesen committed
75
76
        // Convert activated internalMesh regions
        convertPointFieldBlock
77
        (
Mark Olesen's avatar
Mark Olesen committed
78
79
80
81
82
            ptf,
            output,
            partInfoVolume_,
            regionPolyDecomp_
        );
83

Mark Olesen's avatar
Mark Olesen committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
        // Convert activated cellZones
        convertPointFieldBlock
        (
            ptf,
            output,
            partInfoCellZones_,
            zonePolyDecomp_
        );

        // Convert activated cellSets
        convertPointFieldBlock
        (
            ptf,
            output,
            partInfoCellSets_,
            csetPolyDecomp_
        );
101

102

103
104
105
        //
        // Convert patches - if activated
        //
Mark Olesen's avatar
Mark Olesen committed
106
107
        for
        (
Mark Olesen's avatar
Mark Olesen committed
108
109
110
            int partId = partInfoPatches_.start();
            partId < partInfoPatches_.end();
            ++partId
Mark Olesen's avatar
Mark Olesen committed
111
        )
112
        {
Mark Olesen's avatar
Mark Olesen committed
113
114
115
            const word  patchName = getPartName(partId);
            const label datasetNo = partDataset_[partId];
            const label   patchId = patches.findPatchID(patchName);
Mark Olesen's avatar
Mark Olesen committed
116

Mark Olesen's avatar
Mark Olesen committed
117
            if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
118
            {
Mark Olesen's avatar
Mark Olesen committed
119
                continue;
120
            }
Mark Olesen's avatar
Mark Olesen committed
121
122
123
124
125
126

            convertPatchPointField
            (
                fieldName,
                ptf.boundaryField()[patchId].patchInternalField()(),
                output,
Mark Olesen's avatar
Mark Olesen committed
127
                partInfoPatches_,
Mark Olesen's avatar
Mark Olesen committed
128
129
                datasetNo
            );
130
131
132
133
134
        }
    }
}


Mark Olesen's avatar
Mark Olesen committed
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
template<class Type>
void Foam::vtkPV3Foam::convertPointFieldBlock
(
    const GeometricField<Type, pointPatchField, pointMesh>& ptf,
    vtkMultiBlockDataSet* output,
    const partInfo& selector,
    const List<polyDecomp>& decompLst
)
{
   for (int partId = selector.start(); partId < selector.end(); ++partId)
   {
       const label datasetNo = partDataset_[partId];

       if (datasetNo >= 0 && partStatus_[partId])
       {
           convertPointField
           (
               ptf,
               GeometricField<Type, fvPatchField, volMesh>::null(),
               output,
               selector,
               datasetNo,
               decompLst[datasetNo]
           );
       }
   }
}


164
165
166
167
168
169
template<class Type>
void Foam::vtkPV3Foam::convertPointField
(
    const GeometricField<Type, pointPatchField, pointMesh>& ptf,
    const GeometricField<Type, fvPatchField, volMesh>& tf,
    vtkMultiBlockDataSet* output,
Mark Olesen's avatar
Mark Olesen committed
170
171
172
    const partInfo& selector,
    const label datasetNo,
    const polyDecomp& decomp
173
174
)
{
175
    const label nComp = pTraits<Type>::nComponents;
Mark Olesen's avatar
Mark Olesen committed
176
177
    const labelList& addPointCellLabels = decomp.addPointCellLabels();
    const labelList& pointMap = decomp.pointMap();
178

Mark Olesen's avatar
Mark Olesen committed
179
180
181
182
183
184
185
186
187
188
    // use a pointMap or address directly into mesh
    label nPoints;
    if (pointMap.size())
    {
        nPoints = pointMap.size();
    }
    else
    {
        nPoints = ptf.size();
    }
189
190

    vtkFloatArray *pointData = vtkFloatArray::New();
Andrew Heather's avatar
bugfix:    
Andrew Heather committed
191
192
193
    pointData->SetNumberOfTuples(nPoints + addPointCellLabels.size());
    pointData->SetNumberOfComponents(nComp);
    pointData->Allocate(nComp*(nPoints + addPointCellLabels.size()));
194
    pointData->SetName(ptf.name().c_str());
195

Mark Olesen's avatar
Mark Olesen committed
196
197
198
    if (debug)
    {
        Info<< "convert convertPointField: "
Andrew Heather's avatar
bugfix:    
Andrew Heather committed
199
            << ptf.name()
Mark Olesen's avatar
Mark Olesen committed
200
            << " size = " << nPoints
Mark Olesen's avatar
Mark Olesen committed
201
            << " nComp=" << nComp
Mark Olesen's avatar
Mark Olesen committed
202
            << " nTuples = " << (nPoints + addPointCellLabels.size())
Mark Olesen's avatar
Mark Olesen committed
203
204
205
206
            <<  endl;
    }

    float vec[nComp];
Mark Olesen's avatar
Mark Olesen committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220

    if (pointMap.size())
    {
        forAll(pointMap, i)
        {
            const Type& t = ptf[pointMap[i]];
            for (direction d=0; d<nComp; d++)
            {
                vec[d] = component(t, d);
            }
            pointData->InsertTuple(i, vec);
        }
    }
    else
221
    {
Mark Olesen's avatar
Mark Olesen committed
222
        forAll(ptf, i)
223
        {
Mark Olesen's avatar
Mark Olesen committed
224
225
226
227
228
229
            const Type& t = ptf[i];
            for (direction d=0; d<nComp; d++)
            {
                vec[d] = component(t, d);
            }
            pointData->InsertTuple(i, vec);
230
231
232
        }
    }

Mark Olesen's avatar
Mark Olesen committed
233
    // continue insertion from here
Mark Olesen's avatar
Mark Olesen committed
234
    label i = nPoints;
235
236
237

    if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
    {
Mark Olesen's avatar
Mark Olesen committed
238
        forAll(addPointCellLabels, apI)
239
        {
Mark Olesen's avatar
Mark Olesen committed
240
            const Type& t = tf[addPointCellLabels[apI]];
241
            for (direction d=0; d<nComp; d++)
242
            {
243
                vec[d] = component(t, d);
244
245
246
247
248
249
            }
            pointData->InsertTuple(i++, vec);
        }
    }
    else
    {
Mark Olesen's avatar
Mark Olesen committed
250
        forAll(addPointCellLabels, apI)
251
        {
Mark Olesen's avatar
Mark Olesen committed
252
            Type t = interpolatePointToCell(ptf, addPointCellLabels[apI]);
253
            for (direction d=0; d<nComp; d++)
254
            {
255
                vec[d] = component(t, d);
256
257
258
259
260
            }
            pointData->InsertTuple(i++, vec);
        }
    }

Mark Olesen's avatar
Mark Olesen committed
261
262
263
264
265
266
    vtkUnstructuredGrid::SafeDownCast
    (
        GetDataSetFromBlock(output, selector, datasetNo)
    )   ->GetPointData()
        ->AddArray(pointData);

267
268
269
    pointData->Delete();
}

270

271
272
273
274
275
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

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