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

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