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
26 OpenDX format. Both data-only and scalar/vector data.
28 \*---------------------------------------------------------------------------*/
30 #include "triSurface.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
39 // Geometry (positions + connections)
40 // writeSorted: sort acc. to patch
41 void triSurface::writeDXGeometry
43 const bool writeSorted,
48 surfacePatchList myPatches(calcPatches(faceMap));
50 // Print patch names as comment
51 os << "# Patches:" << endl;
52 forAll(myPatches, patchI)
54 os << "# " << patchI << " "
55 << myPatches[patchI].name() << endl;
59 // Write vertex coordinates
61 os << "# The irregular positions" << endl
62 << "object 1 class array type float rank 1 shape 3 items "
63 << nPoints() << " data follows" << endl;
64 forAll(localPoints(), pointI)
66 const point& pt = localPoints()[pointI];
67 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
71 os << "# The irregular connections (triangles)" << endl
72 << "object 2 class array type int rank 1 shape 3 items "
73 << size() << " data follows" << endl;
79 forAll(myPatches, patchI)
81 // Print all faces belonging to this patch
86 patchFaceI < myPatches[patchI].size();
90 const label faceI = faceMap[faceIndex++];
92 const labelledTri& f = localFaces()[faceI];
94 os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
102 const labelledTri& f = localFaces()[faceI];
104 os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
107 os << "attribute \"element type\" string \"triangles\"" << endl
108 << "attribute \"ref\" string \"positions\"" << endl << endl;
113 void triSurface::writeDXTrailer(Ostream& os) const
115 os << "# the field, with three components: \"positions\", \"connections\""
116 << ", and \"data\"" << endl
117 << "object \"irregular positions irregular connections\" class field"
119 << "component \"positions\" value 1" << endl
120 << "component \"connections\" value 2" << endl
121 << "component \"data\" value 3" << endl;
125 // Geometry only (data field is either faceIndex or patchIndex)
126 void triSurface::writeDX(const bool writeSorted, Ostream& os) const
128 writeDXGeometry(writeSorted, os);
130 os << "object 3 class array type float rank 0 items " << size()
131 << " data follows" << endl;
134 // Write patch number as data
137 surfacePatchList myPatches(calcPatches(faceMap));
139 forAll(myPatches, patchI)
141 forAll(myPatches[patchI], patchFaceI)
143 os << patchI << endl;
149 // Write face number as data
157 os << endl << "attribute \"dep\" string \"connections\"" << endl << endl;
165 // Geometry + scalar data
166 void triSurface::writeDX(const scalarField& field, Ostream& os) const
168 writeDXGeometry(false, os);
170 if (field.size() == size())
172 // Connections dependent data
173 os << "object 3 class array type float rank 0 items " << field.size()
174 << " data follows" << endl;
177 os << field[faceI] << endl;
180 << "attribute \"dep\" string \"connections\"" << endl << endl;
182 else if (field.size() == nPoints())
184 // Positions dependent data
185 os << "object 3 class array type float rank 0 items " << field.size()
186 << " data follows" << endl;
187 forAll(field, pointI)
189 os << field[pointI] << endl;
192 << "attribute \"dep\" string \"positions\"" << endl << endl;
198 "writeDX(const scalarField&, Ostream&)"
199 ) << "Illegal field size " << field.size() << " is not equal "
200 << " to number of faces " << size() << " or to number "
201 << " of points " << nPoints() << exit(FatalError);
210 // Geometry + vector data
211 void triSurface::writeDX(const vectorField& field, Ostream& os) const
213 writeDXGeometry(false, os);
215 if (field.size() == size())
217 // Connections dependent data
218 os << "object 3 class array type float rank 1 shape 3 items "
219 << field.size() << " data follows" << endl;
222 os << field[faceI].x() << ' '
223 << field[faceI].y() << ' '
224 << field[faceI].z() << endl;
227 << "attribute \"dep\" string \"connections\"" << endl << endl;
229 else if (field.size() == nPoints())
231 // Positions dependent data
232 os << "object 3 class array type float rank 1 shape 3 items "
233 << field.size() << " data follows" << endl;
234 forAll(field, pointI)
236 os << field[pointI].x() << ' '
237 << field[pointI].y() << ' '
238 << field[pointI].z() << endl;
241 << "attribute \"dep\" string \"positions\"" << endl << endl;
247 "writeDX(const vectorField&, Ostream&)"
248 ) << "Illegal field size " << field.size() << " is not equal "
249 << " to number of faces " << size() << " or to number "
250 << " of points " << nPoints() << exit(FatalError);
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 } // End namespace Foam
263 // ************************************************************************* //