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

writeSMESH.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::writeSMESH(const bool writeSorted, Ostream& os) const
00037 {
00038     const pointField& ps = points();
00039 
00040     // Write header
00041     os  << "# tetgen .smesh file" << endl
00042         << ps.size() << " 3" << endl;   // 3 dimensions
00043 
00044     // Write vertex coords
00045     forAll(ps, pointi)
00046     {
00047         os  << pointi << ' '
00048             << ps[pointi].x() << ' '
00049             << ps[pointi].y() << ' '
00050             << ps[pointi].z() << endl;
00051     }
00052 
00053     if (writeSorted)
00054     {
00055         labelList faceMap;
00056 
00057         surfacePatchList myPatches(calcPatches(faceMap));
00058 
00059         os  << size() << " 1" << endl;   // 1 attribute: region number
00060 
00061         label faceIndex = 0;
00062 
00063         forAll(myPatches, patchI)
00064         {
00065             // Print all faces belonging to this patch
00066 
00067             for
00068             (
00069                 label patchFaceI = 0;
00070                 patchFaceI < myPatches[patchI].size();
00071                 patchFaceI++
00072             )
00073             {
00074                 const label faceI = faceMap[faceIndex++];
00075 
00076                 os  << "3 " // triangles
00077                     << operator[](faceI)[0] << ' '
00078                     << operator[](faceI)[1] << ' '
00079                     << operator[](faceI)[2] << ' '
00080                     << operator[](faceI).region()   // region number
00081                     << endl;
00082             }
00083         }
00084 
00085         os  << '0' << endl      // holes
00086             << '0' << endl;     // regions
00087     }
00088     else
00089     {
00090         os  << size() << " 1" << endl;   // 1 attribute: region number
00091 
00092         forAll(*this, faceI)
00093         {
00094             os  << "3 "
00095                 << operator[](faceI)[0] << ' '
00096                 << operator[](faceI)[1] << ' '
00097                 << operator[](faceI)[2] << ' '
00098                 << operator[](faceI).region()       // region number
00099                 << endl;
00100         }
00101 
00102         os  << '0' << endl      // holes
00103             << '0' << endl;     // regions
00104     }
00105 }
00106 
00107 
00108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00109 
00110 } // End namespace Foam
00111 
00112 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd