FreeFOAM The Cross-Platform CFD Toolkit
partialWrite.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "partialWrite.H"
27 #include <OpenFOAM/dictionary.H>
28 #include <OpenFOAM/Time.H>
29 #include <OpenFOAM/IOobjectList.H>
30 #include <OpenFOAM/polyMesh.H>
31 #include <OpenFOAM/cloud.H>
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(partialWrite, 0);
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 (
45  const word& name,
46  const objectRegistry& obr,
47  const dictionary& dict,
48  const bool loadFromFiles
49 )
50 :
51  name_(name),
52  obr_(obr)
53 {
54  read(dict);
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
59 
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
67 {
68  dict.lookup("objectNames") >> objectNames_;
69  dict.lookup("writeInterval") >> writeInterval_;
70  writeInstance_ = 0;
71 
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;
82 
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  }
90 }
91 
92 
94 {
95  //Pout<< "execute at time " << obr_.time().timeName()
96  // << " index:" << obr_.time().timeIndex() << endl;
97 }
98 
99 
101 {
102  //Pout<< "end at time " << obr_.time().timeName() << endl;
103  // Do nothing - only valid on write
104 }
105 
106 
108 {
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;
117 
118  writeInstance_++;
119 
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  }
133 
134  IOobjectList objects(obr_, obr_.time().timeName());
135 
136  if (debug)
137  {
138  Pout<< "For region:" << obr_.name() << endl;
139  }
140 
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  }
156 
157  // Do the lagrangian files as well.
158  fileNameList cloudDirs
159  (
160  readDir
161  (
162  obr_.time().timePath()/dbDir/cloud::prefix,
164  )
165  );
166  forAll(cloudDirs, i)
167  {
168  if (debug)
169  {
170  Pout<< "For cloud:" << cloudDirs[i] << endl;
171  }
172 
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
187  /cloudDirs[i]
188  /iter()->name();
189  if (debug)
190  {
191  Pout<< " rm " << f << endl;
192  }
193  rm(f);
194  }
195  }
196  }
197  }
198  }
199 }
200 
201 
202 // ************************ vim: set sw=4 sts=4 et: ************************ //