BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / postProcessing / functionObjects / IO / partialWrite / partialWrite.C
blob674996e5aaa8abae617e89a8839eeac09b5a04f1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "partialWrite.H"
27 #include "dictionary.H"
28 #include "Time.H"
29 #include "IOobjectList.H"
30 #include "polyMesh.H"
31 #include "cloud.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(partialWrite, 0);
41 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 Foam::partialWrite::partialWrite
45     const word& name,
46     const objectRegistry& obr,
47     const dictionary& dict,
48     const bool loadFromFiles
51     name_(name),
52     obr_(obr)
54     read(dict);
58 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
60 Foam::partialWrite::~partialWrite()
64 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
66 void Foam::partialWrite::read(const dictionary& dict)
68     dict.lookup("objectNames") >> objectNames_;
69     dict.lookup("writeInterval") >> writeInterval_;
70     writeInstance_ = 0;
72     Info<< type() << " " << name() << ":" << nl
73         << "    dumping every outputTime :";
74     forAllConstIter(HashSet<word>, objectNames_, iter)
75     {
76         Info<< ' ' << iter.key();
77     }
78     Info<< nl
79         << "    dumping all other fields every "
80         << writeInterval_ << "th outputTime" << nl
81         << endl;
83     if (writeInterval_ < 1)
84     {
85         FatalIOErrorIn("partialWrite::read(const dictionary&)", dict)
86             << "Illegal value for writeInterval " << writeInterval_
87             << ". It should be >= 1."
88             << exit(FatalIOError);
89     }
93 void Foam::partialWrite::execute()
95     //Pout<< "execute at time " << obr_.time().timeName()
96     //    << " index:" << obr_.time().timeIndex() << endl;
100 void Foam::partialWrite::end()
102     //Pout<< "end at time " << obr_.time().timeName() << endl;
103     // Do nothing - only valid on write
107 void Foam::partialWrite::write()
109     //Pout<< "write at time " << obr_.time().timeName() << endl;
110     if (obr_.time().outputTime())
111     {
112         // Above check so it can be used both with
113         //  outputControl   timeStep;
114         //  outputInterval  1;
115         // or with
116         //  outputControl   outputTime;
118         writeInstance_++;
120         if (writeInstance_ == writeInterval_)
121         {
122             // Normal dump
123             writeInstance_ = 0;
124         }
125         else
126         {
127             // Delete all but marked objects
128             fileName dbDir;
129             if (isA<polyMesh>(obr_))
130             {
131                 dbDir = dynamic_cast<const polyMesh&>(obr_).dbDir();
132             }
134             IOobjectList objects(obr_, obr_.time().timeName());
136             if (debug)
137             {
138                 Pout<< "For region:" << obr_.name() << endl;
139             }
141             forAllConstIter(IOobjectList, objects, iter)
142             {
143                 if (!objectNames_.found(iter()->name()))
144                 {
145                     const fileName f =
146                         obr_.time().timePath()
147                        /dbDir
148                        /iter()->name();
149                     if (debug)
150                     {
151                         Pout<< "   rm " << f << endl;
152                     }
153                     rm(f);
154                 }
155             }
157             // Do the lagrangian files as well.
158             fileNameList cloudDirs
159             (
160                 readDir
161                 (
162                     obr_.time().timePath()/dbDir/cloud::prefix,
163                     fileName::DIRECTORY
164                 )
165             );
166             forAll(cloudDirs, i)
167             {
168                 if (debug)
169                 {
170                     Pout<< "For cloud:" << cloudDirs[i] << endl;
171                 }
173                 IOobjectList sprayObjs
174                 (
175                     obr_,
176                     obr_.time().timeName(),
177                     cloud::prefix/cloudDirs[i]
178                 );
179                 forAllConstIter(IOobjectList, sprayObjs, iter)
180                 {
181                     if (!objectNames_.found(iter()->name()))
182                     {
183                         const fileName f =
184                             obr_.time().timePath()
185                            /dbDir
186                            /cloud::prefix
187                            /cloudDirs[i]
188                            /iter()->name();
189                         if (debug)
190                         {
191                             Pout<< "   rm " << f << endl;
192                         }
193                         rm(f);
194                     }
195                 }
196             }
197         }
198     }
202 // ************************************************************************* //