initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / triSurface / triSurface / interfaces / DX / writeDX.C
blob9572c0d527bba03bd1c77f6f8b2ac04c0dccd29e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 Description
26     OpenDX format. Both data-only and scalar/vector data.
28 \*---------------------------------------------------------------------------*/
30 #include "triSurface.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
39 // Geometry (positions + connections)
40 // writeSorted: sort acc. to patch
41 void triSurface::writeDXGeometry
43     const bool writeSorted,
44     Ostream& os
45 ) const
47     labelList faceMap;
48     surfacePatchList myPatches(calcPatches(faceMap));
50     // Print patch names as comment
51     os  << "# Patches:" << endl;
52     forAll(myPatches, patchI)
53     {
54         os  << "#     " << patchI << "    "
55             << myPatches[patchI].name() << endl;
56     }
57     os << endl << 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)
65     {
66         const point& pt = localPoints()[pointI];
67         os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
68     }
69     os  << 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;
75     if (writeSorted)
76     {
77         label faceIndex = 0;
79         forAll(myPatches, patchI)
80         {
81             // Print all faces belonging to this patch
83             for
84             (
85                 label patchFaceI = 0;
86                 patchFaceI < myPatches[patchI].size();
87                 patchFaceI++
88             )
89             {
90                 const label faceI = faceMap[faceIndex++];
92                 const labelledTri& f = localFaces()[faceI];
94                 os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
95             }
96         }
97     }
98     else
99     {
100         forAll(*this, faceI)
101         {
102             const labelledTri& f = localFaces()[faceI];
104             os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
105         }
106     }
107     os << "attribute \"element type\" string \"triangles\"" << endl
108        << "attribute \"ref\" string \"positions\"" << endl << endl;
112 // Standard trailer
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"
118         << endl
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;
132     if (writeSorted)
133     {
134         // Write patch number as data
136         labelList faceMap;
137         surfacePatchList myPatches(calcPatches(faceMap));
139         forAll(myPatches, patchI)
140         {
141             forAll(myPatches[patchI], patchFaceI)
142             {
143                 os << patchI << endl;
144             }
145         }
146     }
147     else
148     {
149         // Write face number as data
151         forAll(*this, faceI)
152         {
153             os << faceI << endl;
154         }
155     }
157     os  << endl << "attribute \"dep\" string \"connections\"" << endl << endl;
159     writeDXTrailer(os);
161     os << "end" << endl;
165 // Geometry + scalar data
166 void triSurface::writeDX(const scalarField& field, Ostream& os) const
168     writeDXGeometry(false, os);
170     if (field.size() == size())
171     {
172         // Connections dependent data
173         os  << "object 3 class array type float rank 0 items " << field.size()
174             << " data follows" << endl;
175         forAll(field, faceI)
176         {
177             os << field[faceI] << endl;
178         }
179         os  << endl
180             << "attribute \"dep\" string \"connections\"" << endl << endl;
181     }
182     else if (field.size() == nPoints())
183     {
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)
188         {
189             os << field[pointI] << endl;
190         }
191         os  << endl
192             << "attribute \"dep\" string \"positions\"" << endl << endl;
193     }
194     else
195     {
196         FatalErrorIn
197         (
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);
202     }
204     writeDXTrailer(os);
206     os << "end" << endl;
210 // Geometry + vector data
211 void triSurface::writeDX(const vectorField& field, Ostream& os) const
213     writeDXGeometry(false, os);
215     if (field.size() == size())
216     {
217         // Connections dependent data
218         os  << "object 3 class array type float rank 1 shape 3 items "
219             << field.size() << " data follows" << endl;
220         forAll(field, faceI)
221         {
222             os  << field[faceI].x() << ' '
223                 << field[faceI].y() << ' '
224                 << field[faceI].z() << endl;
225         }
226         os  << endl
227             << "attribute \"dep\" string \"connections\"" << endl << endl;
228     }
229     else if (field.size() == nPoints())
230     {
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)
235         {
236             os  << field[pointI].x() << ' '
237                 << field[pointI].y() << ' '
238                 << field[pointI].z() << endl;
239         }
240         os  << endl
241             << "attribute \"dep\" string \"positions\"" << endl << endl;
242     }
243     else
244     {
245         FatalErrorIn
246         (
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);
251     }
253     writeDXTrailer(os);
255     os << "end" << endl;
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 } // End namespace Foam
263 // ************************************************************************* //