1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
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 "rawSurfaceWriter.H"
29 #include "OSspecific.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 void Foam::rawSurfaceWriter<Type>::writeGeometry
37 const pointField& points,
42 const point& pt = points[pointI];
44 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' ';
49 void Foam::rawSurfaceWriter<Type>::writeGeometry
51 const pointField& points,
52 const faceList& faces,
57 const point& ct = faces[faceI].centre(points);
59 os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' ';
63 // Write scalarField in raw format
65 void Foam::rawSurfaceWriter<Type>::writeData
67 const fileName& fieldName,
68 const pointField& points,
69 const faceList& faces,
70 const scalarField& values,
75 os << "# x y z " << fieldName << endl;
78 if (values.size() == points.size())
82 writeGeometry(points, elemI, os);
83 os << values[elemI] << nl;
90 writeGeometry(points, faces, elemI, os);
91 os << values[elemI] << nl;
99 // Write vectorField in raw format
101 void Foam::rawSurfaceWriter<Type>::writeData
103 const fileName& fieldName,
104 const pointField& points,
105 const faceList& faces,
106 const vectorField& values,
112 << fieldName << "_x "
113 << fieldName << "_y "
114 << fieldName << "_z "
118 if (values.size() == points.size())
120 forAll(values, elemI)
122 writeGeometry(points, elemI, os);
124 const vector& v = values[elemI];
125 os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
130 forAll(values, elemI)
132 writeGeometry(points, faces, elemI, os);
134 const vector& v = values[elemI];
135 os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
142 // Write sphericalTensorField in raw format
144 void Foam::rawSurfaceWriter<Type>::writeData
146 const fileName& fieldName,
147 const pointField& points,
148 const faceList& faces,
149 const sphericalTensorField& values,
155 os << fieldName << "_ii" << endl;
158 if (values.size() == points.size())
160 forAll(values, elemI)
162 writeGeometry(points, elemI, os);
164 const sphericalTensor& v = values[elemI];
170 forAll(values, elemI)
172 writeGeometry(points, faces, elemI, os);
174 const sphericalTensor& v = values[elemI];
181 // Write symmTensorField in raw format
183 void Foam::rawSurfaceWriter<Type>::writeData
185 const fileName& fieldName,
186 const pointField& points,
187 const faceList& faces,
188 const symmTensorField& values,
193 os << "# xx xy xz yy yz ";
194 for(int i=0; i<6; i++)
196 os << fieldName << "_" << i << " ";
201 if (values.size() == points.size())
203 forAll(values, elemI)
205 writeGeometry(points, elemI, os);
207 const symmTensor& v = values[elemI];
209 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
210 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
216 forAll(values, elemI)
218 writeGeometry(points, faces, elemI, os);
220 const symmTensor& v = values[elemI];
222 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
223 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
230 // Write tensorField in raw format
232 void Foam::rawSurfaceWriter<Type>::writeData
234 const fileName& fieldName,
235 const pointField& points,
236 const faceList& faces,
237 const tensorField& values,
242 os << "# xx xy xz yx yy yz zx zy zz";
243 for (int i=0; i<9; ++i)
245 os << fieldName << "_" << i << " ";
250 if (values.size() == points.size())
252 forAll(values, elemI)
254 writeGeometry(points, elemI, os);
256 const tensor& v = values[elemI];
257 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
258 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
259 << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
264 forAll(values, elemI)
266 writeGeometry(points, faces, elemI, os);
268 const tensor& v = values[elemI];
269 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
270 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
271 << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
277 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
280 Foam::rawSurfaceWriter<Type>::rawSurfaceWriter()
282 surfaceWriter<Type>()
286 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
289 Foam::rawSurfaceWriter<Type>::~rawSurfaceWriter()
293 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
296 void Foam::rawSurfaceWriter<Type>::write
298 const fileName& outputDir,
299 const fileName& surfaceName,
300 const pointField& points,
301 const faceList& faces,
305 if (!isDir(outputDir))
312 outputDir/surfaceName + ".raw"
317 Info<< "Writing geometry to " << os.name() << endl;
322 os << "# geometry NO_DATA " << faces.size() << nl
323 << "# x y z" << endl;
328 writeGeometry(points, faces, elemI, os);
338 // bool fields aren't supported
340 void Foam::rawSurfaceWriter<bool>::write
342 const fileName& outputDir,
343 const fileName& surfaceName,
344 const pointField& points,
345 const faceList& faces,
346 const fileName& fieldName,
347 const Field<bool>& values,
355 void Foam::rawSurfaceWriter<Type>::write
357 const fileName& outputDir,
358 const fileName& surfaceName,
359 const pointField& points,
360 const faceList& faces,
361 const fileName& fieldName,
362 const Field<Type>& values,
366 if (!isDir(outputDir))
373 outputDir/fieldName + '_' + surfaceName + ".raw"
378 Info<< "Writing field " << fieldName << " to " << os.name() << endl;
383 os << "# " << fieldName;
384 if (values.size() == points.size())
386 os << " POINT_DATA ";
393 os << values.size() << nl;
395 writeData(fieldName, points, faces, values, os);
399 // ************************************************************************* //