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

vtkFoamConvertPatchFaceField.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 vtkFoamConvertPatchFaceField_H
00031 #define vtkFoamConvertPatchFaceField_H
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 template<class Type>
00036 void Foam::vtkFoam::convertPatchFaceField
00037 (
00038     const word& name,
00039     const Field<Type>& ptf,
00040     const label regioni
00041 )
00042 {
00043     vtkUnstructuredGrid *vtkMesh =
00044         vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
00045 
00046     vtkFloatArray *cellTypes = vtkFloatArray::New();
00047     cellTypes->SetNumberOfTuples(ptf.size());
00048     cellTypes->SetNumberOfComponents(Type::nComponents);
00049     cellTypes->Allocate(Type::nComponents*ptf.size());
00050     cellTypes->SetName(name.c_str());
00051 
00052     float vec[Type::nComponents];
00053 
00054     forAll(ptf, i)
00055     {
00056         const Type& t = ptf[i];
00057         for (direction d=0; d<Type::nComponents; d++)
00058         {
00059             vec[d] = t[d];
00060         }
00061 
00062         cellTypes->InsertTuple(i, vec);
00063     }
00064 
00065     vtkMesh->GetCellData()->AddArray(cellTypes);
00066     cellTypes->Delete();
00067 }
00068 
00069 
00070 template<>
00071 void Foam::vtkFoam::convertPatchFaceField
00072 (
00073     const word& name,
00074     const Field<scalar>& psf,
00075     const label regioni
00076 )
00077 {
00078     vtkUnstructuredGrid *vtkMesh =
00079         vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
00080 
00081     vtkFloatArray *cellScalars = vtkFloatArray::New();
00082     cellScalars->SetNumberOfTuples(psf.size());
00083     cellScalars->SetNumberOfComponents(1);
00084     cellScalars->Allocate(psf.size());
00085     cellScalars->SetName(name.c_str());
00086 
00087     forAll(psf, i)
00088     {
00089         cellScalars->InsertComponent(i, 0, psf[i]);
00090     }
00091 
00092     vtkMesh->GetCellData()->AddArray(cellScalars);
00093     if (!vtkMesh->GetCellData()->GetScalars())
00094     {
00095         vtkMesh->GetCellData()->SetScalars(cellScalars);
00096     }
00097 
00098     cellScalars->Delete();
00099 }
00100 
00101 
00102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00103 
00104 #endif
00105 
00106 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd