FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

writeGTS.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <triSurface/triSurface.H>
00027 
00028 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00029 
00030 namespace Foam
00031 {
00032 
00033 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00034 
00035 void triSurface::writeGTS(const bool writeSorted, Ostream& os) const
00036 {
00037     // Write header
00038     os  << "# GTS file" << endl
00039         << "# Regions:" << endl;
00040 
00041     labelList faceMap;
00042 
00043     surfacePatchList myPatches(calcPatches(faceMap));
00044 
00045     // Print patch names as comment
00046     forAll(myPatches, patchI)
00047     {
00048         os  << "#     " << patchI << "    "
00049             << myPatches[patchI].name() << endl;
00050     }
00051     os  << "#" << endl;
00052 
00053 
00054     const pointField& ps = points();
00055 
00056     os  << "# nPoints  nEdges  nTriangles" << endl
00057         << ps.size() << ' ' << nEdges() << ' ' << size() << endl;
00058 
00059     // Write vertex coords
00060 
00061     forAll(ps, pointi)
00062     {
00063         os  << ps[pointi].x() << ' '
00064             << ps[pointi].y() << ' '
00065             << ps[pointi].z() << endl;
00066     }
00067 
00068     // Write edges.
00069     // Note: edges are in local point labels so convert
00070     const edgeList& es = edges();
00071     const labelList& meshPts = meshPoints();
00072 
00073     forAll(es, edgei)
00074     {
00075         os  << meshPts[es[edgei].start()] + 1 << ' '
00076             << meshPts[es[edgei].end()] + 1 << endl;
00077     }
00078 
00079     // Write faces in terms of edges.
00080     const labelListList& faceEs = faceEdges();
00081 
00082     if (writeSorted)
00083     {
00084         label faceIndex = 0;
00085         forAll(myPatches, patchI)
00086         {
00087             for
00088             (
00089                 label patchFaceI = 0;
00090                 patchFaceI < myPatches[patchI].size();
00091                 patchFaceI++
00092             )
00093             {
00094                 const label faceI = faceMap[faceIndex++];
00095 
00096                 const labelList& fEdges = faceEdges()[faceI];
00097 
00098                 os  << fEdges[0] + 1 << ' '
00099                     << fEdges[1] + 1 << ' '
00100                     << fEdges[2] + 1 << ' '
00101                     << (*this)[faceI].region() << endl;
00102             }
00103         }
00104     }
00105     else
00106     {
00107         forAll(faceEs, faceI)
00108         {
00109             const labelList& fEdges = faceEdges()[faceI];
00110 
00111             os  << fEdges[0] + 1 << ' '
00112                 << fEdges[1] + 1 << ' '
00113                 << fEdges[2] + 1 << ' '
00114                 << (*this)[faceI].region() << endl;
00115         }
00116     }
00117 }
00118 
00119 
00120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00121 
00122 } // End namespace Foam
00123 
00124 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines