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

MeshedSurfaceProxy.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 "MeshedSurfaceProxy.H"
00027 
00028 #include <OpenFOAM/Time.H>
00029 #include <surfMesh/surfMesh.H>
00030 #include <OpenFOAM/OFstream.H>
00031 #include <OpenFOAM/ListOps.H>
00032 
00033 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
00034 
00035 template<class Face>
00036 Foam::wordHashSet Foam::MeshedSurfaceProxy<Face>::writeTypes()
00037 {
00038     return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
00039 }
00040 
00041 
00042 template<class Face>
00043 bool Foam::MeshedSurfaceProxy<Face>::canWriteType
00044 (
00045     const word& ext,
00046     const bool verbose
00047 )
00048 {
00049     return checkSupport(writeTypes(), ext, verbose, "writing");
00050 }
00051 
00052 
00053 template<class Face>
00054 void Foam::MeshedSurfaceProxy<Face>::write
00055 (
00056     const fileName& name,
00057     const MeshedSurfaceProxy& surf
00058 )
00059 {
00060     if (debug)
00061     {
00062         Info<< "MeshedSurfaceProxy::write"
00063             "(const fileName&, const MeshedSurfaceProxy&) : "
00064             "writing to " << name
00065             << endl;
00066     }
00067 
00068     word ext = name.ext();
00069 
00070     typename writefileExtensionMemberFunctionTable::iterator mfIter =
00071         writefileExtensionMemberFunctionTablePtr_->find(ext);
00072 
00073     if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
00074     {
00075         FatalErrorIn
00076         (
00077             "MeshedSurfaceProxy::write(const fileName&)"
00078         )   << "Unknown file extension " << ext << nl << nl
00079             << "Valid types are :" << endl
00080             << writeTypes()
00081             << exit(FatalError);
00082     }
00083 
00084     mfIter()(name, surf);
00085 }
00086 
00087 
00088 template<class Face>
00089 void Foam::MeshedSurfaceProxy<Face>::write
00090 (
00091     const Time& t,
00092     const word& surfName
00093 ) const
00094 {
00095     // the surface name to be used
00096     word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
00097 
00098     if (debug)
00099     {
00100         Info<< "MeshedSurfaceProxy::write"
00101             "(const Time&, const word&) : "
00102             "writing to " << name
00103             << endl;
00104     }
00105 
00106 
00107     // the local location
00108     const fileName objectDir
00109     (
00110         t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
00111     );
00112 
00113     if (!isDir(objectDir))
00114     {
00115         mkDir(objectDir);
00116     }
00117 
00118 
00119     // write surfMesh/points
00120     {
00121         pointIOField io
00122         (
00123             IOobject
00124             (
00125                 "points",
00126                 t.timeName(),
00127                 surfMesh::meshSubDir,
00128                 t,
00129                 IOobject::NO_READ,
00130                 IOobject::NO_WRITE,
00131                 false
00132             )
00133         );
00134 
00135         OFstream os
00136         (
00137             objectDir/io.name(),
00138             t.writeFormat(),
00139             IOstream::currentVersion,
00140             t.writeCompression()
00141         );
00142 
00143         io.writeHeader(os);
00144 
00145         os  << this->points();
00146 
00147         io.writeEndDivider(os);
00148     }
00149 
00150 
00151     // write surfMesh/faces
00152     {
00153         faceIOList io
00154         (
00155             IOobject
00156             (
00157                 "faces",
00158                 t.timeName(),
00159                 surfMesh::meshSubDir,
00160                 t,
00161                 IOobject::NO_READ,
00162                 IOobject::NO_WRITE,
00163                 false
00164             )
00165         );
00166 
00167         OFstream os
00168         (
00169             objectDir/io.name(),
00170             t.writeFormat(),
00171             IOstream::currentVersion,
00172             t.writeCompression()
00173         );
00174         io.writeHeader(os);
00175 
00176         if (this->useFaceMap())
00177         {
00178             // this is really a bit annoying (and wasteful) but no other way
00179             os  << reorder(this->faceMap(), this->faces());
00180         }
00181         else
00182         {
00183             os  << this->faces();
00184         }
00185 
00186         io.writeEndDivider(os);
00187     }
00188 
00189 
00190     // write surfMesh/surfZones
00191     {
00192         surfZoneIOList io
00193         (
00194             IOobject
00195             (
00196                 "surfZones",
00197                 t.timeName(),
00198                 surfMesh::meshSubDir,
00199                 t,
00200                 IOobject::NO_READ,
00201                 IOobject::NO_WRITE,
00202                 false
00203             )
00204         );
00205 
00206         // write as ascii
00207         OFstream os(objectDir/io.name());
00208         io.writeHeader(os);
00209 
00210         os  << this->surfZones();
00211 
00212         io.writeEndDivider(os);
00213     }
00214 
00215 }
00216 
00217 
00218 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00219 
00220 template<class Face>
00221 Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy
00222 (
00223     const pointField& pointLst,
00224     const List<Face>& faceLst,
00225     const List<surfZone>& zoneLst,
00226     const List<label>& faceMap
00227 )
00228 :
00229     points_(pointLst),
00230     faces_(faceLst),
00231     zones_(zoneLst),
00232     faceMap_(faceMap)
00233 {}
00234 
00235 
00236 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00237 
00238 template<class Face>
00239 Foam::MeshedSurfaceProxy<Face>::~MeshedSurfaceProxy()
00240 {}
00241 
00242 
00243 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines