1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "vtkSetWriter.H"
30 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 Foam::vtkSetWriter<Type>::vtkSetWriter()
41 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
44 Foam::vtkSetWriter<Type>::~vtkSetWriter()
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 Foam::fileName Foam::vtkSetWriter<Type>::getFileName
53 const coordSet& points,
54 const wordList& valueSetNames
57 return this->getBaseName(points, valueSetNames) + ".vtk";
62 void Foam::vtkSetWriter<Type>::write
64 const coordSet& points,
65 const wordList& valueSetNames,
66 const List<const Field<Type>*>& valueSets,
70 os << "# vtk DataFile Version 2.0" << nl
71 << points.name() << nl
73 << "DATASET POLYDATA" << nl
74 << "POINTS " << points.size() << " float" << nl;
78 const vector& pt = points[i];
79 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
83 os << "POINT_DATA " << points.size() << nl
84 << " FIELD attributes " << valueSetNames.size() << nl;
86 forAll(valueSetNames, setI)
88 os << valueSetNames[setI] << ' ' << pTraits<Type>::nComponents << ' '
89 << points.size() << " float" << nl;
91 const Field<Type>& fld = *valueSets[setI];
99 writer<Type>::write(fld[pointI], os);
107 void Foam::vtkSetWriter<Type>::write
109 const bool writeTracks,
110 const PtrList<coordSet>& tracks,
111 const wordList& valueSetNames,
112 const List<List<Field<Type> > >& valueSets,
116 if (valueSets.size() != valueSetNames.size())
118 FatalErrorIn("vtkSetWriter<Type>::write(..)")
119 << "Number of variables:" << valueSetNames.size() << endl
120 << "Number of valueSets:" << valueSets.size()
124 label nTracks = tracks.size();
128 nPoints += tracks[i].size();
131 os << "# vtk DataFile Version 2.0" << nl
132 << tracks[0].name() << nl
134 << "DATASET POLYDATA" << nl
135 << "POINTS " << nPoints << " float" << nl;
137 forAll(tracks, trackI)
139 const coordSet& points = tracks[trackI];
142 const vector& pt = points[i];
143 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
149 os << "LINES " << nTracks << ' ' << nPoints+nTracks << nl;
151 // Write ids of track points to file
153 forAll(tracks, trackI)
155 const coordSet& points = tracks[trackI];
160 os << ' ' << globalPtI;
167 os << "POINT_DATA " << nPoints << nl
168 << " FIELD attributes " << valueSetNames.size() << nl;
170 forAll(valueSetNames, setI)
172 os << valueSetNames[setI] << ' ' << pTraits<Type>::nComponents << ' '
173 << nPoints << " float" << nl;
175 const List<Field<Type> >& fieldVals = valueSets[setI];
179 const Field<Type>& vals = fieldVals[i];
187 writer<Type>::write(vals[j], os);
195 // ************************************************************************* //