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

partialWrite.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) 2011-2011 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 "partialWrite.H"
00027 #include <OpenFOAM/dictionary.H>
00028 #include <OpenFOAM/Time.H>
00029 #include <OpenFOAM/IOobjectList.H>
00030 #include <OpenFOAM/polyMesh.H>
00031 #include <OpenFOAM/cloud.H>
00032 
00033 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037     defineTypeNameAndDebug(partialWrite, 0);
00038 }
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 Foam::partialWrite::partialWrite
00044 (
00045     const word& name,
00046     const objectRegistry& obr,
00047     const dictionary& dict,
00048     const bool loadFromFiles
00049 )
00050 :
00051     name_(name),
00052     obr_(obr)
00053 {
00054     read(dict);
00055 }
00056 
00057 
00058 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00059 
00060 Foam::partialWrite::~partialWrite()
00061 {}
00062 
00063 
00064 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00065 
00066 void Foam::partialWrite::read(const dictionary& dict)
00067 {
00068     dict.lookup("objectNames") >> objectNames_;
00069     dict.lookup("writeInterval") >> writeInterval_;
00070     writeInstance_ = 0;
00071 
00072     Info<< type() << " " << name() << ":" << nl
00073         << "    dumping every outputTime :";
00074     forAllConstIter(HashSet<word>, objectNames_, iter)
00075     {
00076         Info<< ' ' << iter.key();
00077     }
00078     Info<< nl
00079         << "    dumping all other fields every "
00080         << writeInterval_ << "th outputTime" << nl
00081         << endl;
00082 
00083     if (writeInterval_ < 1)
00084     {
00085         FatalIOErrorIn("partialWrite::read(const dictionary&)", dict)
00086             << "Illegal value for writeInterval " << writeInterval_
00087             << ". It should be >= 1."
00088             << exit(FatalIOError);
00089     }
00090 }
00091 
00092 
00093 void Foam::partialWrite::execute()
00094 {
00095     //Pout<< "execute at time " << obr_.time().timeName()
00096     //    << " index:" << obr_.time().timeIndex() << endl;
00097 }
00098 
00099 
00100 void Foam::partialWrite::end()
00101 {
00102     //Pout<< "end at time " << obr_.time().timeName() << endl;
00103     // Do nothing - only valid on write
00104 }
00105 
00106 
00107 void Foam::partialWrite::write()
00108 {
00109     //Pout<< "write at time " << obr_.time().timeName() << endl;
00110     if (obr_.time().outputTime())
00111     {
00112         // Above check so it can be used both with
00113         //  outputControl   timeStep;
00114         //  outputInterval  1;
00115         // or with
00116         //  outputControl   outputTime;
00117 
00118         writeInstance_++;
00119 
00120         if (writeInstance_ == writeInterval_)
00121         {
00122             // Normal dump
00123             writeInstance_ = 0;
00124         }
00125         else
00126         {
00127             // Delete all but marked objects
00128             fileName dbDir;
00129             if (isA<polyMesh>(obr_))
00130             {
00131                 dbDir = dynamic_cast<const polyMesh&>(obr_).dbDir();
00132             }
00133 
00134             IOobjectList objects(obr_, obr_.time().timeName());
00135 
00136             if (debug)
00137             {
00138                 Pout<< "For region:" << obr_.name() << endl;
00139             }
00140 
00141             forAllConstIter(IOobjectList, objects, iter)
00142             {
00143                 if (!objectNames_.found(iter()->name()))
00144                 {
00145                     const fileName f =
00146                         obr_.time().timePath()
00147                        /dbDir
00148                        /iter()->name();
00149                     if (debug)
00150                     {
00151                         Pout<< "   rm " << f << endl;
00152                     }
00153                     rm(f);
00154                 }
00155             }
00156 
00157             // Do the lagrangian files as well.
00158             fileNameList cloudDirs
00159             (
00160                 readDir
00161                 (
00162                     obr_.time().timePath()/dbDir/cloud::prefix,
00163                     fileName::DIRECTORY
00164                 )
00165             );
00166             forAll(cloudDirs, i)
00167             {
00168                 if (debug)
00169                 {
00170                     Pout<< "For cloud:" << cloudDirs[i] << endl;
00171                 }
00172 
00173                 IOobjectList sprayObjs
00174                 (
00175                     obr_,
00176                     obr_.time().timeName(),
00177                     cloud::prefix/cloudDirs[i]
00178                 );
00179                 forAllConstIter(IOobjectList, sprayObjs, iter)
00180                 {
00181                     if (!objectNames_.found(iter()->name()))
00182                     {
00183                         const fileName f =
00184                             obr_.time().timePath()
00185                            /dbDir
00186                            /cloud::prefix
00187                            /cloudDirs[i]
00188                            /iter()->name();
00189                         if (debug)
00190                         {
00191                             Pout<< "   rm " << f << endl;
00192                         }
00193                         rm(f);
00194                     }
00195                 }
00196             }
00197         }
00198     }
00199 }
00200 
00201 
00202 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines