1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 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 "dxSurfaceWriter.H"
29 #include "OSspecific.H"
31 #include "makeSurfaceWriterMethods.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 makeSurfaceWriterType(dxSurfaceWriter);
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 void Foam::dxSurfaceWriter::writeGeometry
46 const pointField& points,
50 // Write vertex coordinates
52 os << "# The irregular positions" << nl
53 << "object 1 class array type float rank 1 shape 3 items "
54 << points.size() << " data follows" << nl;
56 forAll(points, pointI)
58 const point& pt = points[pointI];
60 os << float(pt.x()) << ' ' << float(pt.y()) << ' ' << float(pt.z())
66 os << "# The irregular connections (triangles)" << nl
67 << "object 2 class array type int rank 1 shape 3 items "
68 << faces.size() << " data follows" << nl;
72 const face& f = faces[faceI];
78 "writeGeometry(Ostream&, const pointField&, const faceList&)"
79 ) << "Face " << faceI << " vertices " << f
80 << " is not a triangle."
84 os << f[0] << ' ' << f[1] << ' ' << f[2] << nl;
86 os << "attribute \"element type\" string \"triangles\"" << nl
87 << "attribute \"ref\" string \"positions\"" << nl << nl;
91 void Foam::dxSurfaceWriter::writeTrailer(Ostream& os, const bool isNodeValues)
95 os << nl << "attribute \"dep\" string \"positions\""
100 os << nl << "attribute \"dep\" string \"connections\""
104 os << "# the field, with three components: \"positions\","
105 << " \"connections\", and \"data\"" << nl
106 << "object \"irregular positions irregular "
107 << "connections\" class field"
109 << "component \"positions\" value 1" << nl
110 << "component \"connections\" value 2" << nl
111 << "component \"data\" value 3" << nl;
120 void Foam::dxSurfaceWriter::writeData
123 const Field<scalar>& values
126 os << "object 3 class array type float rank 0 items "
127 << values.size() << " data follows" << nl;
129 forAll(values, elemI)
131 os << float(values[elemI]) << nl;
137 void Foam::dxSurfaceWriter::writeData
140 const Field<vector>& values
143 os << "object 3 class array type float rank 1 shape 3 items "
144 << values.size() << " data follows" << nl;
146 forAll(values, elemI)
148 os << float(values[elemI].x()) << ' '
149 << float(values[elemI].y()) << ' '
150 << float(values[elemI].z()) << nl;
156 void Foam::dxSurfaceWriter::writeData
159 const Field<sphericalTensor>& values
162 os << "object 3 class array type float rank 0 items "
163 << values.size() << " data follows" << nl;
165 forAll(values, elemI)
167 os << float(values[elemI][0]) << nl;
173 void Foam::dxSurfaceWriter::writeData
176 const Field<symmTensor>& values
179 os << "object 3 class array type float rank 2 shape 3 items "
180 << values.size() << " data follows" << nl;
182 forAll(values, elemI)
184 const symmTensor& t = values[elemI];
186 os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
187 << float(t.xy()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
188 << float(t.xz()) << ' ' << float(t.yz()) << ' ' << float(t.zz())
194 // Write Field<tensor> in DX format
196 inline void Foam::dxSurfaceWriter::writeData
199 const Field<tensor>& values
202 os << "object 3 class array type float rank 2 shape 3 items "
203 << values.size() << " data follows" << nl;
205 forAll(values, elemI)
207 const tensor& t = values[elemI];
209 os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
210 << float(t.yx()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
211 << float(t.zx()) << ' ' << float(t.zy()) << ' ' << float(t.zz())
220 inline void Foam::dxSurfaceWriter::writeData
223 const Field<Type>& values
226 os << "object 3 class array type float rank 0 items "
227 << values.size() << " data follows" << nl;
229 forAll(values, elemI)
231 os << float(0.0) << nl;
237 void Foam::dxSurfaceWriter::writeTemplate
239 const fileName& outputDir,
240 const fileName& surfaceName,
241 const pointField& points,
242 const faceList& faces,
243 const word& fieldName,
244 const Field<Type>& values,
245 const bool isNodeValues,
249 if (!isDir(outputDir))
256 outputDir/fieldName + '_' + surfaceName + ".dx"
261 Info<< "Writing field " << fieldName << " to " << os.name() << endl;
264 writeGeometry(os, points, faces);
265 writeData(os, values);
266 writeTrailer(os, isNodeValues);
270 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
272 Foam::dxSurfaceWriter::dxSurfaceWriter()
278 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
280 Foam::dxSurfaceWriter::~dxSurfaceWriter()
284 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
286 // create write methods
287 defineSurfaceWriterWriteFields(Foam::dxSurfaceWriter);
290 // ************************************************************************* //