1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 \*---------------------------------------------------------------------------*/
30 #ifndef vtkFoamConvertPointField_H
31 #define vtkFoamConvertPointField_H
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 #include "interpolatePointToCell.H"
38 void Foam::vtkFoam::convertPointField
40 const GeometricField<Type, pointPatchField, pointMesh>& ptf,
41 const GeometricField<Type, fvPatchField, volMesh>& tf
44 vtkUnstructuredGrid *vtkMesh =
45 vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
47 vtkFloatArray *pointTypes = vtkFloatArray::New();
48 pointTypes->SetNumberOfTuples(ptf.size() + addPointCellLabels_.size());
49 pointTypes->SetNumberOfComponents(Type::nComponents);
50 pointTypes->Allocate(Type::nComponents*ptf.size());
51 pointTypes->SetName(ptf.name().c_str());
53 float vec[Type::nComponents];
57 for (direction d=0; d<Type::nComponents; d++)
62 pointTypes->InsertTuple(i, vec);
67 if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
69 forAll(addPointCellLabels_, api)
71 Type t = tf[addPointCellLabels_[api]];
73 for (direction d=0; d<Type::nComponents; d++)
78 pointTypes->InsertTuple(i++, vec);
83 forAll(addPointCellLabels_, api)
85 Type t = interpolatePointToCell(ptf, addPointCellLabels_[api]);
87 for (direction d=0; d<Type::nComponents; d++)
92 pointTypes->InsertTuple(i++, vec);
96 vtkMesh->GetPointData()->AddArray(pointTypes);
102 void Foam::vtkFoam::convertPointField
104 const GeometricField<scalar, pointPatchField, pointMesh>& psf,
105 const GeometricField<scalar, fvPatchField, volMesh>& sf
108 vtkUnstructuredGrid *vtkMesh =
109 vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
111 vtkFloatArray *pointScalars = vtkFloatArray::New();
112 pointScalars->SetNumberOfTuples(psf.size() + addPointCellLabels_.size());
113 pointScalars->SetNumberOfComponents(1);
114 pointScalars->Allocate(psf.size());
115 pointScalars->SetName(psf.name().c_str());
117 for (int i=0; i<psf.size(); i++)
119 pointScalars->InsertComponent(i, 0, psf[i]);
122 label i = psf.size();
124 if (&sf != &GeometricField<scalar, fvPatchField, volMesh>::null())
126 forAll(addPointCellLabels_, api)
128 pointScalars->InsertComponent
132 sf[addPointCellLabels_[api]]
138 forAll(addPointCellLabels_, api)
140 pointScalars->InsertComponent
144 interpolatePointToCell(psf, addPointCellLabels_[api])
149 vtkMesh->GetPointData()->AddArray(pointScalars);
150 if (!vtkMesh->GetPointData()->GetScalars())
152 vtkMesh->GetPointData()->SetScalars(pointScalars);
155 pointScalars->Delete();
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 // ************************************************************************* //