initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / triSurface / triSurface / interfaces / GTS / writeGTS.C
blob93b286f6173256f517c8c36d91cdb4bf1e37e456
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 \*---------------------------------------------------------------------------*/
27 #include "triSurface.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 void triSurface::writeGTS(const bool writeSorted, Ostream& os) const
38     // Write header
39     os  << "# GTS file" << endl
40         << "# Regions:" << endl;
42     labelList faceMap;
44     surfacePatchList myPatches(calcPatches(faceMap));
46     // Print patch names as comment
47     forAll(myPatches, patchI)
48     {
49         os  << "#     " << patchI << "    "
50             << myPatches[patchI].name() << endl;
51     }
52     os  << "#" << endl;
55     const pointField& ps = points();
57     os  << "# nPoints  nEdges  nTriangles" << endl
58         << ps.size() << ' ' << nEdges() << ' ' << size() << endl;
60     // Write vertex coords
62     forAll(ps, pointi)
63     {
64         os  << ps[pointi].x() << ' '
65             << ps[pointi].y() << ' '
66             << ps[pointi].z() << endl;
67     }
69     // Write edges.
70     // Note: edges are in local point labels so convert
71     const edgeList& es = edges();
72     const labelList& meshPts = meshPoints();
74     forAll(es, edgei)
75     {
76         os  << meshPts[es[edgei].start()] + 1 << ' '
77             << meshPts[es[edgei].end()] + 1 << endl;
78     }
80     // Write faces in terms of edges.
81     const labelListList& faceEs = faceEdges();
83     if (writeSorted)
84     {
85         label faceIndex = 0;
86         forAll(myPatches, patchI)
87         {
88             for
89             (
90                 label patchFaceI = 0;
91                 patchFaceI < myPatches[patchI].size();
92                 patchFaceI++
93             )
94             {
95                 const label faceI = faceMap[faceIndex++];
97                 const labelList& fEdges = faceEdges()[faceI];
99                 os  << fEdges[0] + 1 << ' '
100                     << fEdges[1] + 1 << ' '
101                     << fEdges[2] + 1 << ' '
102                     << (*this)[faceI].region() << endl;
103             }
104         }
105     }
106     else
107     {
108         forAll(faceEs, faceI)
109         {
110             const labelList& fEdges = faceEdges()[faceI];
112             os  << fEdges[0] + 1 << ' '
113                 << fEdges[1] + 1 << ' '
114                 << fEdges[2] + 1 << ' '
115                 << (*this)[faceI].region() << endl;
116         }
117     }
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 } // End namespace Foam
125 // ************************************************************************* //