initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / graphics / PV3FoamReader / vtkPV3Foam / vtkPV3FoamFields.C
blob38cc52f68047303136cd08d02e15c3ded723bcc7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "vtkPV3Foam.H"
31 // Foam includes
32 #include "IOobjectList.H"
33 #include "vtkPV3FoamReader.h"
35 // VTK includes
36 #include "vtkDataArraySelection.h"
37 #include "vtkPolyData.h"
38 #include "vtkUnstructuredGrid.h"
40 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
42 #include "vtkPV3FoamVolFields.H"
43 #include "vtkPV3FoamPointFields.H"
44 #include "vtkPV3FoamLagrangianFields.H"
47 void Foam::vtkPV3Foam::pruneObjectList
49     IOobjectList& objects,
50     const wordHashSet& selected
53     // hash all the selected field names
54     if (!selected.size())
55     {
56         objects.clear();
57     }
59     // only keep selected fields
60     forAllIter(IOobjectList, objects, iter)
61     {
62         if (!selected.found(iter()->name()))
63         {
64             objects.erase(iter);
65         }
66     }
70 void Foam::vtkPV3Foam::convertVolFields
72     vtkMultiBlockDataSet* output
75     const fvMesh& mesh = *meshPtr_;
77     wordHashSet selectedFields = getSelected
78     (
79         reader_->GetVolFieldSelection()
80     );
82     if (!selectedFields.size())
83     {
84         return;
85     }
87     // Get objects (fields) for this time - only keep selected fields
88     // the region name is already in the mesh db
89     IOobjectList objects(mesh, dbPtr_().timeName());
90     pruneObjectList(objects, selectedFields);
92     if (!objects.size())
93     {
94         return;
95     }
97     if (debug)
98     {
99         Info<< "<beg> Foam::vtkPV3Foam::convertVolFields" << nl
100             << "converting Foam volume fields" << endl;
101         forAllConstIter(IOobjectList, objects, iter)
102         {
103             Info<< "  " << iter()->name()
104                 << " == " << iter()->objectPath() << nl;
105         }
106         printMemory();
107     }
110     PtrList<PrimitivePatchInterpolation<primitivePatch> >
111         ppInterpList(mesh.boundaryMesh().size());
113     forAll(ppInterpList, i)
114     {
115         ppInterpList.set
116         (
117             i,
118             new PrimitivePatchInterpolation<primitivePatch>
119             (
120                 mesh.boundaryMesh()[i]
121             )
122         );
123     }
126     convertVolFields<scalar>
127     (
128         mesh, ppInterpList, objects, output
129     );
130     convertVolFields<vector>
131     (
132         mesh, ppInterpList, objects, output
133     );
134     convertVolFields<sphericalTensor>
135     (
136         mesh, ppInterpList, objects, output
137     );
138     convertVolFields<symmTensor>
139     (
140         mesh, ppInterpList, objects, output
141     );
142     convertVolFields<tensor>
143     (
144         mesh, ppInterpList, objects, output
145     );
147     if (debug)
148     {
149         Info<< "<end> Foam::vtkPV3Foam::convertVolFields" << endl;
150         printMemory();
151     }
155 void Foam::vtkPV3Foam::convertPointFields
157     vtkMultiBlockDataSet* output
160     const fvMesh& mesh = *meshPtr_;
162     wordHashSet selectedFields = getSelected
163     (
164         reader_->GetPointFieldSelection()
165     );
167     if (!selectedFields.size())
168     {
169         return;
170     }
172     // Get objects (fields) for this time - only keep selected fields
173     // the region name is already in the mesh db
174     IOobjectList objects(mesh, dbPtr_().timeName());
175     pruneObjectList(objects, selectedFields);
177     if (!objects.size())
178     {
179         return;
180     }
182     if (debug)
183     {
184         Info<< "<beg> Foam::vtkPV3Foam::convertPointFields" << nl
185             << "converting Foam volume fields" << endl;
186         forAllConstIter(IOobjectList, objects, iter)
187         {
188             Info<< "  " << iter()->name()
189                 << " == " << iter()->objectPath() << nl;
190         }
191         printMemory();
192     }
194     // Construct interpolation on the raw mesh
195     pointMesh pMesh(mesh);
198     convertPointFields<scalar>
199     (
200         mesh, pMesh, objects, output
201     );
202     convertPointFields<vector>
203     (
204         mesh, pMesh, objects, output
205     );
206     convertPointFields<sphericalTensor>
207     (
208         mesh, pMesh, objects, output
209     );
210     convertPointFields<symmTensor>
211     (
212         mesh, pMesh, objects, output
213     );
214     convertPointFields<tensor>
215     (
216         mesh, pMesh, objects, output
217     );
219     if (debug)
220     {
221         Info<< "<end> Foam::vtkPV3Foam::convertPointFields" << endl;
222         printMemory();
223     }
227 void Foam::vtkPV3Foam::convertLagrangianFields
229     vtkMultiBlockDataSet* output
232     partInfo& selector = partInfoLagrangian_;
233     const fvMesh& mesh = *meshPtr_;
235     wordHashSet selectedFields = getSelected
236     (
237         reader_->GetLagrangianFieldSelection()
238     );
240     if (!selectedFields.size())
241     {
242         return;
243     }
245     if (debug)
246     {
247         Info<< "<beg> Foam::vtkPV3Foam::convertLagrangianFields" << endl;
248         printMemory();
249     }
251     for (int partId = selector.start(); partId < selector.end(); ++partId)
252     {
253         const word  cloudName = getPartName(partId);
254         const label datasetNo = partDataset_[partId];
256         if (!partStatus_[partId] || datasetNo < 0)
257         {
258             continue;
259         }
262         // Get the Lagrangian fields for this time and this cloud
263         // but only keep selected fields
264         // the region name is already in the mesh db
265         IOobjectList objects
266         (
267             mesh,
268             dbPtr_().timeName(),
269             cloud::prefix/cloudName
270         );
271         pruneObjectList(objects, selectedFields);
273         if (!objects.size())
274         {
275             continue;
276         }
278         if (debug)
279         {
280             Info<< "converting Foam lagrangian fields" << nl;
281             forAllConstIter(IOobjectList, objects, iter)
282             {
283                 Info<< "  " << iter()->name()
284                     << " == " << iter()->objectPath() << nl;
285             }
286         }
288         convertLagrangianFields<label>
289         (
290             objects, output, datasetNo
291         );
292         convertLagrangianFields<scalar>
293         (
294             objects, output, datasetNo
295         );
296         convertLagrangianFields<vector>
297         (
298             objects, output, datasetNo
299         );
300         convertLagrangianFields<sphericalTensor>
301         (
302             objects, output, datasetNo
303         );
304         convertLagrangianFields<symmTensor>
305         (
306             objects, output, datasetNo
307         );
308         convertLagrangianFields<tensor>
309         (
310             objects, output, datasetNo
311         );
312     }
314     if (debug)
315     {
316         Info<< "<end> Foam::vtkPV3Foam::convertLagrangianFields" << endl;
317         printMemory();
318     }
322 // ************************************************************************* //