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

vtkFoamConvertPointField.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     Foam::vtkFoam
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #ifndef vtkFoamConvertPointField_H
00031 #define vtkFoamConvertPointField_H
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 #include "interpolatePointToCell.H"
00036 
00037 template<class Type>
00038 void Foam::vtkFoam::convertPointField
00039 (
00040     const GeometricField<Type, pointPatchField, pointMesh>& ptf,
00041     const GeometricField<Type, fvPatchField, volMesh>& tf
00042 )
00043 {
00044     vtkUnstructuredGrid *vtkMesh =
00045         vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
00046 
00047     vtkFloatArray *pointTypes = vtkFloatArray::New();
00048     pointTypes->SetNumberOfTuples(ptf.size() + addPointCellLabels_.size());
00049     pointTypes->SetNumberOfComponents(Type::nComponents);
00050     pointTypes->Allocate(Type::nComponents*ptf.size());
00051     pointTypes->SetName(ptf.name().c_str());
00052 
00053     float vec[Type::nComponents];
00054 
00055     forAll(ptf, i)
00056     {
00057         for (direction d=0; d<Type::nComponents; d++)
00058         {
00059             vec[d] = ptf[i][d];
00060         }
00061 
00062         pointTypes->InsertTuple(i, vec);
00063     }
00064 
00065     label i = ptf.size();
00066 
00067     if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
00068     {
00069         forAll(addPointCellLabels_, api)
00070         {
00071             Type t = tf[addPointCellLabels_[api]];
00072 
00073             for (direction d=0; d<Type::nComponents; d++)
00074             {
00075                 vec[d] = t[d];
00076             }
00077 
00078             pointTypes->InsertTuple(i++, vec);
00079         }
00080     }
00081     else
00082     {
00083         forAll(addPointCellLabels_, api)
00084         {
00085             Type t = interpolatePointToCell(ptf, addPointCellLabels_[api]);
00086 
00087             for (direction d=0; d<Type::nComponents; d++)
00088             {
00089                 vec[d] = t[d];
00090             }
00091 
00092             pointTypes->InsertTuple(i++, vec);
00093         }
00094     }
00095 
00096     vtkMesh->GetPointData()->AddArray(pointTypes);
00097     pointTypes->Delete();
00098 }
00099 
00100 
00101 template<>
00102 void Foam::vtkFoam::convertPointField
00103 (
00104     const GeometricField<scalar, pointPatchField, pointMesh>& psf,
00105     const GeometricField<scalar, fvPatchField, volMesh>& sf
00106 )
00107 {
00108     vtkUnstructuredGrid *vtkMesh =
00109         vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
00110 
00111     vtkFloatArray *pointScalars = vtkFloatArray::New();
00112     pointScalars->SetNumberOfTuples(psf.size() + addPointCellLabels_.size());
00113     pointScalars->SetNumberOfComponents(1);
00114     pointScalars->Allocate(psf.size());
00115     pointScalars->SetName(psf.name().c_str());
00116 
00117     for (int i=0; i<psf.size(); i++)
00118     {
00119         pointScalars->InsertComponent(i, 0, psf[i]);
00120     }
00121 
00122     label i = psf.size();
00123 
00124     if (&sf != &GeometricField<scalar, fvPatchField, volMesh>::null())
00125     {
00126         forAll(addPointCellLabels_, api)
00127         {
00128             pointScalars->InsertComponent
00129             (
00130                 i++,
00131                 0,
00132                 sf[addPointCellLabels_[api]]
00133             );
00134         }
00135     }
00136     else
00137     {
00138         forAll(addPointCellLabels_, api)
00139         {
00140             pointScalars->InsertComponent
00141             (
00142                 i++,
00143                 0,
00144                 interpolatePointToCell(psf, addPointCellLabels_[api])
00145             );
00146         }
00147     }
00148 
00149     vtkMesh->GetPointData()->AddArray(pointScalars);
00150     if (!vtkMesh->GetPointData()->GetScalars())
00151     {
00152         vtkMesh->GetPointData()->SetScalars(pointScalars);
00153     }
00154 
00155     pointScalars->Delete();
00156 }
00157 
00158 
00159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00160 
00161 #endif
00162 
00163 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd