OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

vtkPV3FoamFields.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "vtkPV3Foam.H"
00030 
00031 // Foam includes
00032 #include "IOobjectList.H"
00033 #include "vtkPV3FoamReader.h"
00034 
00035 // VTK includes
00036 #include "vtkDataArraySelection.h"
00037 #include "vtkPolyData.h"
00038 #include "vtkUnstructuredGrid.h"
00039 
00040 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00041 
00042 #include "vtkPV3FoamVolFields.H"
00043 #include "vtkPV3FoamPointFields.H"
00044 #include "vtkPV3FoamLagrangianFields.H"
00045 
00046 
00047 void Foam::vtkPV3Foam::pruneObjectList
00048 (
00049     IOobjectList& objects,
00050     const wordHashSet& selected
00051 )
00052 {
00053     // hash all the selected field names
00054     if (!selected.size())
00055     {
00056         objects.clear();
00057     }
00058 
00059     // only keep selected fields
00060     forAllIter(IOobjectList, objects, iter)
00061     {
00062         if (!selected.found(iter()->name()))
00063         {
00064             objects.erase(iter);
00065         }
00066     }
00067 }
00068 
00069 
00070 void Foam::vtkPV3Foam::convertVolFields
00071 (
00072     vtkMultiBlockDataSet* output
00073 )
00074 {
00075     const fvMesh& mesh = *meshPtr_;
00076 
00077     wordHashSet selectedFields = getSelected
00078     (
00079         reader_->GetVolFieldSelection()
00080     );
00081 
00082     if (!selectedFields.size())
00083     {
00084         return;
00085     }
00086 
00087     // Get objects (fields) for this time - only keep selected fields
00088     // the region name is already in the mesh db
00089     IOobjectList objects(mesh, dbPtr_().timeName());
00090     pruneObjectList(objects, selectedFields);
00091 
00092     if (!objects.size())
00093     {
00094         return;
00095     }
00096 
00097     if (debug)
00098     {
00099         Info<< "<beg> Foam::vtkPV3Foam::convertVolFields" << nl
00100             << "converting Foam volume fields" << endl;
00101         forAllConstIter(IOobjectList, objects, iter)
00102         {
00103             Info<< "  " << iter()->name()
00104                 << " == " << iter()->objectPath() << nl;
00105         }
00106         printMemory();
00107     }
00108 
00109 
00110     PtrList<PrimitivePatchInterpolation<primitivePatch> >
00111         ppInterpList(mesh.boundaryMesh().size());
00112 
00113     forAll(ppInterpList, i)
00114     {
00115         ppInterpList.set
00116         (
00117             i,
00118             new PrimitivePatchInterpolation<primitivePatch>
00119             (
00120                 mesh.boundaryMesh()[i]
00121             )
00122         );
00123     }
00124 
00125 
00126     convertVolFields<scalar>
00127     (
00128         mesh, ppInterpList, objects, output
00129     );
00130     convertVolFields<vector>
00131     (
00132         mesh, ppInterpList, objects, output
00133     );
00134     convertVolFields<sphericalTensor>
00135     (
00136         mesh, ppInterpList, objects, output
00137     );
00138     convertVolFields<symmTensor>
00139     (
00140         mesh, ppInterpList, objects, output
00141     );
00142     convertVolFields<tensor>
00143     (
00144         mesh, ppInterpList, objects, output
00145     );
00146 
00147     if (debug)
00148     {
00149         Info<< "<end> Foam::vtkPV3Foam::convertVolFields" << endl;
00150         printMemory();
00151     }
00152 }
00153 
00154 
00155 void Foam::vtkPV3Foam::convertPointFields
00156 (
00157     vtkMultiBlockDataSet* output
00158 )
00159 {
00160     const fvMesh& mesh = *meshPtr_;
00161 
00162     wordHashSet selectedFields = getSelected
00163     (
00164         reader_->GetPointFieldSelection()
00165     );
00166 
00167     if (!selectedFields.size())
00168     {
00169         return;
00170     }
00171 
00172     // Get objects (fields) for this time - only keep selected fields
00173     // the region name is already in the mesh db
00174     IOobjectList objects(mesh, dbPtr_().timeName());
00175     pruneObjectList(objects, selectedFields);
00176 
00177     if (!objects.size())
00178     {
00179         return;
00180     }
00181 
00182     if (debug)
00183     {
00184         Info<< "<beg> Foam::vtkPV3Foam::convertPointFields" << nl
00185             << "converting Foam volume fields" << endl;
00186         forAllConstIter(IOobjectList, objects, iter)
00187         {
00188             Info<< "  " << iter()->name()
00189                 << " == " << iter()->objectPath() << nl;
00190         }
00191         printMemory();
00192     }
00193 
00194     // Construct interpolation on the raw mesh
00195     pointMesh pMesh(mesh);
00196 
00197 
00198     convertPointFields<scalar>
00199     (
00200         mesh, pMesh, objects, output
00201     );
00202     convertPointFields<vector>
00203     (
00204         mesh, pMesh, objects, output
00205     );
00206     convertPointFields<sphericalTensor>
00207     (
00208         mesh, pMesh, objects, output
00209     );
00210     convertPointFields<symmTensor>
00211     (
00212         mesh, pMesh, objects, output
00213     );
00214     convertPointFields<tensor>
00215     (
00216         mesh, pMesh, objects, output
00217     );
00218 
00219     if (debug)
00220     {
00221         Info<< "<end> Foam::vtkPV3Foam::convertPointFields" << endl;
00222         printMemory();
00223     }
00224 }
00225 
00226 
00227 void Foam::vtkPV3Foam::convertLagrangianFields
00228 (
00229     vtkMultiBlockDataSet* output
00230 )
00231 {
00232     partInfo& selector = partInfoLagrangian_;
00233     const fvMesh& mesh = *meshPtr_;
00234 
00235     wordHashSet selectedFields = getSelected
00236     (
00237         reader_->GetLagrangianFieldSelection()
00238     );
00239 
00240     if (!selectedFields.size())
00241     {
00242         return;
00243     }
00244 
00245     if (debug)
00246     {
00247         Info<< "<beg> Foam::vtkPV3Foam::convertLagrangianFields" << endl;
00248         printMemory();
00249     }
00250 
00251     for (int partId = selector.start(); partId < selector.end(); ++partId)
00252     {
00253         const word  cloudName = getPartName(partId);
00254         const label datasetNo = partDataset_[partId];
00255 
00256         if (!partStatus_[partId] || datasetNo < 0)
00257         {
00258             continue;
00259         }
00260 
00261 
00262         // Get the Lagrangian fields for this time and this cloud
00263         // but only keep selected fields
00264         // the region name is already in the mesh db
00265         IOobjectList objects
00266         (
00267             mesh,
00268             dbPtr_().timeName(),
00269             cloud::prefix/cloudName
00270         );
00271         pruneObjectList(objects, selectedFields);
00272 
00273         if (!objects.size())
00274         {
00275             continue;
00276         }
00277 
00278         if (debug)
00279         {
00280             Info<< "converting Foam lagrangian fields" << nl;
00281             forAllConstIter(IOobjectList, objects, iter)
00282             {
00283                 Info<< "  " << iter()->name()
00284                     << " == " << iter()->objectPath() << nl;
00285             }
00286         }
00287 
00288         convertLagrangianFields<label>
00289         (
00290             objects, output, datasetNo
00291         );
00292         convertLagrangianFields<scalar>
00293         (
00294             objects, output, datasetNo
00295         );
00296         convertLagrangianFields<vector>
00297         (
00298             objects, output, datasetNo
00299         );
00300         convertLagrangianFields<sphericalTensor>
00301         (
00302             objects, output, datasetNo
00303         );
00304         convertLagrangianFields<symmTensor>
00305         (
00306             objects, output, datasetNo
00307         );
00308         convertLagrangianFields<tensor>
00309         (
00310             objects, output, datasetNo
00311         );
00312     }
00313 
00314     if (debug)
00315     {
00316         Info<< "<end> Foam::vtkPV3Foam::convertLagrangianFields" << endl;
00317         printMemory();
00318     }
00319 }
00320 
00321 
00322 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd