1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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
25 \*---------------------------------------------------------------------------*/
27 #include "rawSurfaceWriter.H"
30 #include "OSspecific.H"
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 void Foam::rawSurfaceWriter<Type>::writeGeometry
38 const pointField& points,
43 const point& pt = points[pointI];
45 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' ';
50 void Foam::rawSurfaceWriter<Type>::writeGeometry
52 const pointField& points,
53 const faceList& faces,
58 const point& ct = faces[faceI].centre(points);
60 os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' ';
64 // Write scalarField in raw format
66 void Foam::rawSurfaceWriter<Type>::writeData
68 const fileName& fieldName,
69 const pointField& points,
70 const faceList& faces,
71 const scalarField& values,
76 os << "# x y z " << fieldName << endl;
79 if (values.size() == points.size())
83 writeGeometry(points, elemI, os);
84 os << values[elemI] << nl;
91 writeGeometry(points, faces, elemI, os);
92 os << values[elemI] << nl;
100 // Write vectorField in raw format
102 void Foam::rawSurfaceWriter<Type>::writeData
104 const fileName& fieldName,
105 const pointField& points,
106 const faceList& faces,
107 const vectorField& values,
113 << fieldName << "_x "
114 << fieldName << "_y "
115 << fieldName << "_z "
119 if (values.size() == points.size())
121 forAll(values, elemI)
123 writeGeometry(points, elemI, os);
125 const vector& v = values[elemI];
126 os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
131 forAll(values, elemI)
133 writeGeometry(points, faces, elemI, os);
135 const vector& v = values[elemI];
136 os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
143 // Write sphericalTensorField in raw format
145 void Foam::rawSurfaceWriter<Type>::writeData
147 const fileName& fieldName,
148 const pointField& points,
149 const faceList& faces,
150 const sphericalTensorField& values,
156 os << fieldName << "_ii" << endl;
159 if (values.size() == points.size())
161 forAll(values, elemI)
163 writeGeometry(points, elemI, os);
165 const sphericalTensor& v = values[elemI];
171 forAll(values, elemI)
173 writeGeometry(points, faces, elemI, os);
175 const sphericalTensor& v = values[elemI];
182 // Write symmTensorField in raw format
184 void Foam::rawSurfaceWriter<Type>::writeData
186 const fileName& fieldName,
187 const pointField& points,
188 const faceList& faces,
189 const symmTensorField& values,
194 os << "# xx xy xz yy yz ";
195 for(int i=0; i<6; i++)
197 os << fieldName << "_" << i << " ";
202 if (values.size() == points.size())
204 forAll(values, elemI)
206 writeGeometry(points, elemI, os);
208 const symmTensor& v = values[elemI];
210 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
211 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
217 forAll(values, elemI)
219 writeGeometry(points, faces, elemI, os);
221 const symmTensor& v = values[elemI];
223 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
224 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
231 // Write tensorField in raw format
233 void Foam::rawSurfaceWriter<Type>::writeData
235 const fileName& fieldName,
236 const pointField& points,
237 const faceList& faces,
238 const tensorField& values,
243 os << "# xx xy xz yx yy yz zx zy zz";
244 for (int i=0; i<9; ++i)
246 os << fieldName << "_" << i << " ";
251 if (values.size() == points.size())
253 forAll(values, elemI)
255 writeGeometry(points, elemI, os);
257 const tensor& v = values[elemI];
258 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
259 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
260 << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
265 forAll(values, elemI)
267 writeGeometry(points, faces, elemI, os);
269 const tensor& v = values[elemI];
270 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
271 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
272 << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
278 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
281 Foam::rawSurfaceWriter<Type>::rawSurfaceWriter()
283 surfaceWriter<Type>()
287 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
290 Foam::rawSurfaceWriter<Type>::~rawSurfaceWriter()
294 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
297 void Foam::rawSurfaceWriter<Type>::write
299 const fileName& outputDir,
300 const fileName& surfaceName,
301 const pointField& points,
302 const faceList& faces,
306 if (!isDir(outputDir))
313 outputDir/surfaceName + ".raw"
318 Info<< "Writing geometry to " << os.name() << endl;
323 os << "# geometry NO_DATA " << faces.size() << nl
324 << "# x y z" << endl;
329 writeGeometry(points, faces, elemI, os);
339 // bool fields aren't supported
341 void Foam::rawSurfaceWriter<bool>::write
343 const fileName& outputDir,
344 const fileName& surfaceName,
345 const pointField& points,
346 const faceList& faces,
347 const fileName& fieldName,
348 const Field<bool>& values,
356 void Foam::rawSurfaceWriter<Type>::write
358 const fileName& outputDir,
359 const fileName& surfaceName,
360 const pointField& points,
361 const faceList& faces,
362 const fileName& fieldName,
363 const Field<Type>& values,
367 if (!isDir(outputDir))
374 outputDir/fieldName + '_' + surfaceName + ".raw"
379 Info<< "Writing field " << fieldName << " to " << os.name() << endl;
384 os << "# " << fieldName;
385 if (values.size() == points.size())
387 os << " POINT_DATA ";
394 os << values.size() << nl;
396 writeData(fieldName, points, faces, values, os);
400 // ************************************************************************* //