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

vtkPV3FoamPointFields.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 vtkPV3FoamPointFields_H
00031 #define vtkPV3FoamPointFields_H
00032 
00033 // Foam includes
00034 #include "interpolatePointToCell.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 template<class Type>
00039 void Foam::vtkPV3Foam::convertPointFields
00040 (
00041     const fvMesh& mesh,
00042     const pointMesh& pMesh,
00043     const IOobjectList& objects,
00044     vtkMultiBlockDataSet* output
00045 )
00046 {
00047     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00048 
00049     forAllConstIter(IOobjectList, objects, iter)
00050     {
00051         const word& fieldName = iter()->name();
00052         // restrict to this GeometricField<Type, ...>
00053         if
00054         (
00055             iter()->headerClassName()
00056          != GeometricField<Type, pointPatchField, pointMesh>::typeName
00057         )
00058         {
00059             continue;
00060         }
00061 
00062         if (debug)
00063         {
00064             Info<< "Foam::vtkPV3Foam::convertPointFields : "
00065                 << fieldName << endl;
00066         }
00067 
00068         GeometricField<Type, pointPatchField, pointMesh> ptf
00069         (
00070             *iter(),
00071             pMesh
00072         );
00073 
00074 
00075         // Convert activated internalMesh regions
00076         convertPointFieldBlock
00077         (
00078             ptf,
00079             output,
00080             partInfoVolume_,
00081             regionPolyDecomp_
00082         );
00083 
00084         // Convert activated cellZones
00085         convertPointFieldBlock
00086         (
00087             ptf,
00088             output,
00089             partInfoCellZones_,
00090             zonePolyDecomp_
00091         );
00092 
00093         // Convert activated cellSets
00094         convertPointFieldBlock
00095         (
00096             ptf,
00097             output,
00098             partInfoCellSets_,
00099             csetPolyDecomp_
00100         );
00101 
00102 
00103         //
00104         // Convert patches - if activated
00105         //
00106         for
00107         (
00108             int partId = partInfoPatches_.start();
00109             partId < partInfoPatches_.end();
00110             ++partId
00111         )
00112         {
00113             const word  patchName = getPartName(partId);
00114             const label datasetNo = partDataset_[partId];
00115             const label   patchId = patches.findPatchID(patchName);
00116 
00117             if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
00118             {
00119                 continue;
00120             }
00121 
00122             convertPatchPointField
00123             (
00124                 fieldName,
00125                 ptf.boundaryField()[patchId].patchInternalField()(),
00126                 output,
00127                 partInfoPatches_,
00128                 datasetNo
00129             );
00130         }
00131     }
00132 }
00133 
00134 
00135 template<class Type>
00136 void Foam::vtkPV3Foam::convertPointFieldBlock
00137 (
00138     const GeometricField<Type, pointPatchField, pointMesh>& ptf,
00139     vtkMultiBlockDataSet* output,
00140     const partInfo& selector,
00141     const List<polyDecomp>& decompLst
00142 )
00143 {
00144    for (int partId = selector.start(); partId < selector.end(); ++partId)
00145    {
00146        const label datasetNo = partDataset_[partId];
00147 
00148        if (datasetNo >= 0 && partStatus_[partId])
00149        {
00150            convertPointField
00151            (
00152                ptf,
00153                GeometricField<Type, fvPatchField, volMesh>::null(),
00154                output,
00155                selector,
00156                datasetNo,
00157                decompLst[datasetNo]
00158            );
00159        }
00160    }
00161 }
00162 
00163 
00164 template<class Type>
00165 void Foam::vtkPV3Foam::convertPointField
00166 (
00167     const GeometricField<Type, pointPatchField, pointMesh>& ptf,
00168     const GeometricField<Type, fvPatchField, volMesh>& tf,
00169     vtkMultiBlockDataSet* output,
00170     const partInfo& selector,
00171     const label datasetNo,
00172     const polyDecomp& decomp
00173 )
00174 {
00175     const label nComp = pTraits<Type>::nComponents;
00176     const labelList& addPointCellLabels = decomp.addPointCellLabels();
00177     const labelList& pointMap = decomp.pointMap();
00178 
00179     // use a pointMap or address directly into mesh
00180     label nPoints;
00181     if (pointMap.size())
00182     {
00183         nPoints = pointMap.size();
00184     }
00185     else
00186     {
00187         nPoints = ptf.size();
00188     }
00189 
00190     vtkFloatArray *pointData = vtkFloatArray::New();
00191     pointData->SetNumberOfTuples(nPoints + addPointCellLabels.size());
00192     pointData->SetNumberOfComponents(nComp);
00193     pointData->Allocate(nComp*(nPoints + addPointCellLabels.size()));
00194     pointData->SetName(tf.name().c_str());
00195 
00196     if (debug)
00197     {
00198         Info<< "convert convertPointField: "
00199             << ptf.name()
00200             << " size = " << nPoints
00201             << " nComp=" << nComp
00202             << " nTuples = " << (nPoints + addPointCellLabels.size())
00203             <<  endl;
00204     }
00205 
00206     float vec[nComp];
00207 
00208     if (pointMap.size())
00209     {
00210         forAll(pointMap, i)
00211         {
00212             const Type& t = ptf[pointMap[i]];
00213             for (direction d=0; d<nComp; d++)
00214             {
00215                 vec[d] = component(t, d);
00216             }
00217             pointData->InsertTuple(i, vec);
00218         }
00219     }
00220     else
00221     {
00222         forAll(ptf, i)
00223         {
00224             const Type& t = ptf[i];
00225             for (direction d=0; d<nComp; d++)
00226             {
00227                 vec[d] = component(t, d);
00228             }
00229             pointData->InsertTuple(i, vec);
00230         }
00231     }
00232 
00233     // continue insertion from here
00234     label i = nPoints;
00235 
00236     if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
00237     {
00238         forAll(addPointCellLabels, apI)
00239         {
00240             const Type& t = tf[addPointCellLabels[apI]];
00241             for (direction d=0; d<nComp; d++)
00242             {
00243                 vec[d] = component(t, d);
00244             }
00245             pointData->InsertTuple(i++, vec);
00246         }
00247     }
00248     else
00249     {
00250         forAll(addPointCellLabels, apI)
00251         {
00252             Type t = interpolatePointToCell(ptf, addPointCellLabels[apI]);
00253             for (direction d=0; d<nComp; d++)
00254             {
00255                 vec[d] = component(t, d);
00256             }
00257             pointData->InsertTuple(i++, vec);
00258         }
00259     }
00260 
00261     vtkUnstructuredGrid::SafeDownCast
00262     (
00263         GetDataSetFromBlock(output, selector, datasetNo)
00264     )   ->GetPointData()
00265         ->AddArray(pointData);
00266 
00267     pointData->Delete();
00268 }
00269 
00270 
00271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00272 
00273 #endif
00274 
00275 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd