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

vtkPV3FoamVolFields.H

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 InClass
00026     vtkPV3Foam
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #ifndef vtkPV3FoamVolFields_H
00031 #define vtkPV3FoamVolFields_H
00032 
00033 // Foam includes
00034 #include "emptyFvPatchField.H"
00035 #include "wallPolyPatch.H"
00036 #include "faceSet.H"
00037 #include "volPointInterpolation.H"
00038 
00039 #include "vtkPV3FoamFaceField.H"
00040 #include "vtkPV3FoamPatchField.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 template<class Type>
00045 void Foam::vtkPV3Foam::convertVolFields
00046 (
00047     const fvMesh& mesh,
00048     const PtrList<PrimitivePatchInterpolation<primitivePatch> >& ppInterpList,
00049     const IOobjectList& objects,
00050     vtkMultiBlockDataSet* output
00051 )
00052 {
00053     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00054 
00055     forAllConstIter(IOobjectList, objects, iter)
00056     {
00057         // restrict to GeometricField<Type, ...>
00058         if
00059         (
00060             iter()->headerClassName()
00061          != GeometricField<Type, fvPatchField, volMesh>::typeName
00062         )
00063         {
00064             continue;
00065         }
00066 
00067         // Load field
00068         GeometricField<Type, fvPatchField, volMesh> tf
00069         (
00070             *iter(),
00071             mesh
00072         );
00073 
00074         // Interpolated field (demand driven)
00075         autoPtr<GeometricField<Type, pointPatchField, pointMesh> > ptfPtr;
00076 
00077 
00078         // Convert activated internalMesh regions
00079         convertVolFieldBlock
00080         (
00081             tf,
00082             ptfPtr,
00083             output,
00084             partInfoVolume_,
00085             regionPolyDecomp_
00086         );
00087 
00088         // Convert activated cellZones
00089         convertVolFieldBlock
00090         (
00091             tf,
00092             ptfPtr,
00093             output,
00094             partInfoCellZones_,
00095             zonePolyDecomp_
00096         );
00097 
00098         // Convert activated cellSets
00099         convertVolFieldBlock
00100         (
00101             tf,
00102             ptfPtr,
00103             output,
00104             partInfoCellSets_,
00105             csetPolyDecomp_
00106         );
00107 
00108 
00109         //
00110         // Convert patches - if activated
00111         //
00112         for
00113         (
00114             int partId = partInfoPatches_.start();
00115             partId < partInfoPatches_.end();
00116             ++partId
00117         )
00118         {
00119             const word patchName = getPartName(partId);
00120             const label datasetNo = partDataset_[partId];
00121             const label patchId = patches.findPatchID(patchName);
00122 
00123             if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
00124             {
00125                 continue;
00126             }
00127 
00128             const fvPatchField<Type>& ptf = tf.boundaryField()[patchId];
00129 
00130             if
00131             (
00132                 isType<emptyFvPatchField<Type> >(ptf)
00133              ||
00134                 (
00135                     reader_->GetExtrapolatePatches()
00136                 && !polyPatch::constraintType(patches[patchId].type())
00137                 )
00138             )
00139             {
00140                 fvPatch p(ptf.patch().patch(), tf.mesh().boundary());
00141 
00142                 tmp<Field<Type> > tpptf
00143                 (
00144                     fvPatchField<Type>(p, tf).patchInternalField()
00145                 );
00146 
00147                 convertPatchField
00148                 (
00149                     tf.name(),
00150                     tpptf(),
00151                     output,
00152                     partInfoPatches_,
00153                     datasetNo
00154                 );
00155 
00156                 convertPatchPointField
00157                 (
00158                     tf.name(),
00159                     ppInterpList[patchId].faceToPointInterpolate(tpptf)(),
00160                     output,
00161                     partInfoPatches_,
00162                     datasetNo
00163                 );
00164             }
00165             else
00166             {
00167                 convertPatchField
00168                 (
00169                     tf.name(),
00170                     ptf,
00171                     output,
00172                     partInfoPatches_,
00173                     datasetNo
00174                 );
00175 
00176                 convertPatchPointField
00177                 (
00178                     tf.name(),
00179                     ppInterpList[patchId].faceToPointInterpolate(ptf)(),
00180                     output,
00181                     partInfoPatches_,
00182                     datasetNo
00183                 );
00184             }
00185         }
00186 
00187         //
00188         // Convert face zones - if activated
00189         //
00190         for
00191         (
00192             int partId = partInfoFaceZones_.start();
00193             partId < partInfoFaceZones_.end();
00194             ++partId
00195         )
00196         {
00197             const word zoneName = getPartName(partId);
00198             const label datasetNo = partDataset_[partId];
00199 
00200             if (!partStatus_[partId] || datasetNo < 0)
00201             {
00202                 continue;
00203             }
00204 
00205             const faceZoneMesh& zMesh = mesh.faceZones();
00206             const label zoneId = zMesh.findZoneID(zoneName);
00207 
00208             if (zoneId < 0)
00209             {
00210                 continue;
00211             }
00212 
00213             convertFaceField
00214             (
00215                 tf,
00216                 output,
00217                 partInfoFaceZones_,
00218                 datasetNo,
00219                 mesh,
00220                 zMesh[zoneId]
00221             );
00222 
00223             // TODO: points
00224         }
00225 
00226         //
00227         // Convert face sets - if activated
00228         //
00229         for
00230         (
00231             int partId = partInfoFaceSets_.start();
00232             partId < partInfoFaceSets_.end();
00233             ++partId
00234         )
00235         {
00236             const word selectName = getPartName(partId);
00237             const label datasetNo = partDataset_[partId];
00238 
00239             if (!partStatus_[partId] || datasetNo < 0)
00240             {
00241                 continue;
00242             }
00243 
00244             const faceSet fSet(mesh, selectName);
00245 
00246             convertFaceField
00247             (
00248                 tf,
00249                 output,
00250                 partInfoFaceSets_,
00251                 datasetNo,
00252                 mesh,
00253                 fSet
00254             );
00255 
00256             // TODO: points
00257         }
00258     }
00259 }
00260 
00261 
00262 template<class Type>
00263 void Foam::vtkPV3Foam::convertVolFieldBlock
00264 (
00265     const GeometricField<Type, fvPatchField, volMesh>& tf,
00266     autoPtr<GeometricField<Type, pointPatchField, pointMesh> >& ptfPtr,
00267     vtkMultiBlockDataSet* output,
00268     const partInfo& selector,
00269     const List<polyDecomp>& decompLst
00270 )
00271 {
00272     for (int partId = selector.start(); partId < selector.end(); ++partId)
00273     {
00274         const label datasetNo = partDataset_[partId];
00275 
00276         if (datasetNo >= 0 && partStatus_[partId])
00277         {
00278             convertVolField
00279             (
00280                 tf,
00281                 output,
00282                 selector,
00283                 datasetNo,
00284                 decompLst[datasetNo]
00285             );
00286 
00287             if (!ptfPtr.valid())
00288             {
00289                 if (debug)
00290                 {
00291                     Info<< "convertVolFieldBlock interpolating:" << tf.name()
00292                         << endl;
00293                 }
00294 
00295                 ptfPtr.reset
00296                 (
00297                     volPointInterpolation::New(tf.mesh()).interpolate(tf).ptr()
00298                 );
00299             }
00300 
00301             convertPointField
00302             (
00303                 ptfPtr(),
00304                 tf,
00305                 output,
00306                 selector,
00307                 datasetNo,
00308                 decompLst[datasetNo]
00309             );
00310         }
00311     }
00312 }
00313 
00314 
00315 template<class Type>
00316 void Foam::vtkPV3Foam::convertVolField
00317 (
00318     const GeometricField<Type, fvPatchField, volMesh>& tf,
00319     vtkMultiBlockDataSet* output,
00320     const partInfo& selector,
00321     const label datasetNo,
00322     const polyDecomp& decompInfo
00323 )
00324 {
00325     const label nComp = pTraits<Type>::nComponents;
00326     const labelList& superCells = decompInfo.superCells();
00327 
00328     vtkFloatArray* celldata = vtkFloatArray::New();
00329     celldata->SetNumberOfTuples(superCells.size());
00330     celldata->SetNumberOfComponents(nComp);
00331     celldata->Allocate(nComp*superCells.size());
00332     celldata->SetName(tf.name().c_str());
00333 
00334     if (debug)
00335     {
00336         Info<< "convert volField: "
00337             << tf.name()
00338             << " size = " << tf.size()
00339             << " nComp=" << nComp
00340             << " nTuples = " << superCells.size() <<  endl;
00341     }
00342 
00343     float vec[nComp];
00344     forAll(superCells, i)
00345     {
00346         const Type& t = tf[superCells[i]];
00347         for (direction d=0; d<nComp; d++)
00348         {
00349             vec[d] = component(t, d);
00350         }
00351         celldata->InsertTuple(i, vec);
00352     }
00353 
00354     vtkUnstructuredGrid::SafeDownCast
00355     (
00356         GetDataSetFromBlock(output, selector, datasetNo)
00357     )   ->GetCellData()
00358         ->AddArray(celldata);
00359 
00360     celldata->Delete();
00361 }
00362 
00363 
00364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00365 
00366 #endif
00367 
00368 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd