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

SMESHsurfaceFormat.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 "SMESHsurfaceFormat.H"
00028 #include "clock.H"
00029 #include "IFstream.H"
00030 #include "OFstream.H"
00031 #include "Ostream.H"
00032 
00033 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00034 
00035 template<class Face>
00036 Foam::fileFormats::SMESHsurfaceFormat<Face>::SMESHsurfaceFormat()
00037 {}
00038 
00039 
00040 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00041 
00042 template<class Face>
00043 void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
00044 (
00045     const fileName& filename,
00046     const MeshedSurfaceProxy<Face>& surf
00047 )
00048 {
00049     const pointField& pointLst = surf.points();
00050     const List<Face>&  faceLst = surf.faces();
00051     const List<label>& faceMap = surf.faceMap();
00052 
00053     const List<surfZone>& zones =
00054     (
00055         surf.surfZones().size() > 1
00056       ? surf.surfZones()
00057       : oneZone(faceLst)
00058     );
00059 
00060     const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
00061 
00062 
00063     OFstream os(filename);
00064     if (!os.good())
00065     {
00066         FatalErrorIn
00067         (
00068             "fileFormats::SMESHsurfaceFormat::write"
00069             "(const fileName&, const MeshedSurfaceProxy<Face>&)"
00070         )
00071             << "Cannot open file for writing " << filename
00072             << exit(FatalError);
00073     }
00074 
00075 
00076     // Write header
00077     os  << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl
00078         << "# <points count=\"" << pointLst.size() << "\">" << nl
00079         << pointLst.size() << " 3" << nl;    // 3: dimensions
00080 
00081     // Write vertex coords
00082     forAll(pointLst, ptI)
00083     {
00084         const point& pt = pointLst[ptI];
00085 
00086         os  << ptI << ' ' << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
00087     }
00088     os  << "# </points>" << nl
00089         << nl
00090         << "# <faces count=\"" << faceLst.size() << "\">" << endl;
00091 
00092     os  << faceLst.size() << " 1" << endl;   // one attribute: zone number
00093 
00094 
00095     label faceIndex = 0;
00096     forAll(zones, zoneI)
00097     {
00098         const surfZone& zone = zones[zoneI];
00099 
00100         if (useFaceMap)
00101         {
00102             forAll(zone, localFaceI)
00103             {
00104                 const Face& f = faceLst[faceMap[faceIndex++]];
00105 
00106                 os << f.size();
00107                 forAll(f, fp)
00108                 {
00109                     os << ' ' << f[fp];
00110                 }
00111                 os << ' ' << zoneI << endl;
00112             }
00113         }
00114         else
00115         {
00116             forAll(zones[zoneI], localFaceI)
00117             {
00118                 const Face& f = faceLst[faceIndex++];
00119 
00120                 os << f.size();
00121                 forAll(f, fp)
00122                 {
00123                     os << ' ' << f[fp];
00124                 }
00125                 os << ' ' << zoneI << endl;
00126             }
00127         }
00128     }
00129 
00130     // write tail
00131 
00132     os  << "# </faces>" << nl
00133         << nl
00134         << "# no holes or regions:" << nl
00135         << '0' << nl        // holes
00136         << '0' << endl;     // regions
00137 }
00138 
00139 
00140 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd