OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "triSurface.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00035 
00036 void triSurface::writeGTS(const bool writeSorted, Ostream& os) const
00037 {
00038     // Write header
00039     os  << "# GTS file" << endl
00040         << "# Regions:" << endl;
00041 
00042     labelList faceMap;
00043 
00044     surfacePatchList myPatches(calcPatches(faceMap));
00045 
00046     // Print patch names as comment
00047     forAll(myPatches, patchI)
00048     {
00049         os  << "#     " << patchI << "    "
00050             << myPatches[patchI].name() << endl;
00051     }
00052     os  << "#" << endl;
00053 
00054 
00055     const pointField& ps = points();
00056 
00057     os  << "# nPoints  nEdges  nTriangles" << endl
00058         << ps.size() << ' ' << nEdges() << ' ' << size() << endl;
00059 
00060     // Write vertex coords
00061 
00062     forAll(ps, pointi)
00063     {
00064         os  << ps[pointi].x() << ' '
00065             << ps[pointi].y() << ' '
00066             << ps[pointi].z() << endl;
00067     }
00068 
00069     // Write edges.
00070     // Note: edges are in local point labels so convert
00071     const edgeList& es = edges();
00072     const labelList& meshPts = meshPoints();
00073 
00074     forAll(es, edgei)
00075     {
00076         os  << meshPts[es[edgei].start()] + 1 << ' '
00077             << meshPts[es[edgei].end()] + 1 << endl;
00078     }
00079 
00080     // Write faces in terms of edges.
00081     const labelListList& faceEs = faceEdges();
00082 
00083     if (writeSorted)
00084     {
00085         label faceIndex = 0;
00086         forAll(myPatches, patchI)
00087         {
00088             for
00089             (
00090                 label patchFaceI = 0;
00091                 patchFaceI < myPatches[patchI].size();
00092                 patchFaceI++
00093             )
00094             {
00095                 const label faceI = faceMap[faceIndex++];
00096 
00097                 const labelList& fEdges = faceEdges()[faceI];
00098 
00099                 os  << fEdges[0] + 1 << ' '
00100                     << fEdges[1] + 1 << ' '
00101                     << fEdges[2] + 1 << ' '
00102                     << (*this)[faceI].region() << endl;
00103             }
00104         }
00105     }
00106     else
00107     {
00108         forAll(faceEs, faceI)
00109         {
00110             const labelList& fEdges = faceEdges()[faceI];
00111 
00112             os  << fEdges[0] + 1 << ' '
00113                 << fEdges[1] + 1 << ' '
00114                 << fEdges[2] + 1 << ' '
00115                 << (*this)[faceI].region() << endl;
00116         }
00117     }
00118 }
00119 
00120 
00121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00122 
00123 } // End namespace Foam
00124 
00125 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd