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

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