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) 2013-2014 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 "dictionary.H"
28 #include "Time.H"
29 #include "IOobjectList.H"
30 #include "polyMesh.H"
31 #include "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  log_(true)
54 {
55  read(dict);
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 
62 {}
63 
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
68 {
69  log_.readIfPresent("log", dict);
70  dict.lookup("objectNames") >> objectNames_;
71  dict.lookup("writeInterval") >> writeInterval_;
72  writeInstance_ = 0;
73 
74  if (log_)
75  {
76  Info<< type() << " " << name() << ":" << nl
77  << " dumping every outputTime :";
78 
79  forAllConstIter(HashSet<word>, objectNames_, iter)
80  {
81  Info<< ' ' << iter.key();
82  }
83 
84  word postStr = "";
85  if (writeInterval_ == 2)
86  {
87  postStr = "nd ";
88  }
89  else if (writeInterval_ == 3)
90  {
91  postStr = "rd ";
92  }
93  else
94  {
95  postStr = "th ";
96  }
97 
98  Info<< nl
99  << " dumping all other fields every "
100  << writeInterval_ << postStr << " outputTime" << nl
101  << endl;
102  }
103 
104  if (writeInterval_ < 1)
105  {
107  << "Illegal value for writeInterval " << writeInterval_
108  << ". It should be >= 1."
109  << exit(FatalIOError);
110  }
111 
112  // Clear out any previously loaded fields
113  vsf_.clear();
114  vvf_.clear();
115  vSpheretf_.clear();
116  vSymmtf_.clear();
117  vtf_.clear();
118 
119  ssf_.clear();
120  svf_.clear();
121  sSpheretf_.clear();
122  sSymmtf_.clear();
123  stf_.clear();
124 
125  forAllConstIter(HashSet<word>, objectNames_, iter)
126  {
127  loadField<scalar>(iter.key(), vsf_, ssf_);
128  loadField<vector>(iter.key(), vvf_, svf_);
129  loadField<sphericalTensor>(iter.key(), vSpheretf_, sSpheretf_);
130  loadField<symmTensor>(iter.key(), vSymmtf_, sSymmtf_);
131  loadField<tensor>(iter.key(), vtf_, stf_);
132  }
133 }
134 
135 
137 {
138  // Do nothing - only valid on write
139 }
140 
141 
143 {
144  // Do nothing - only valid on write
145 }
146 
147 
149 {
150  if (obr_.time().outputTime())
151  {
152  writeInstance_++;
153 
154  if (writeInstance_ == writeInterval_)
155  {
156  // Next overall dump corresponds to partial write. Change
157  // write options to AUTO_WRITE
158  writeInstance_ = 0;
159 
160  changeWriteOptions<scalar>(vsf_, ssf_, IOobject::AUTO_WRITE);
161  changeWriteOptions<vector>(vvf_, svf_, IOobject::AUTO_WRITE);
162  changeWriteOptions<sphericalTensor>
163  (
164  vSpheretf_,
165  sSpheretf_,
167  );
168  changeWriteOptions<symmTensor>
169  (
170  vSymmtf_,
171  sSymmtf_,
173  );
174  changeWriteOptions<tensor>(vtf_, stf_, IOobject::AUTO_WRITE);
175  }
176  else
177  {
178  changeWriteOptions<scalar>(vsf_, ssf_, IOobject::NO_WRITE);
179  changeWriteOptions<vector>(vvf_, svf_, IOobject::NO_WRITE);
180  changeWriteOptions<sphericalTensor>
181  (
182  vSpheretf_,
183  sSpheretf_,
185  );
186  changeWriteOptions<symmTensor>
187  (
188  vSymmtf_,
189  sSymmtf_,
191  );
192  changeWriteOptions<tensor>(vtf_, stf_, IOobject::NO_WRITE);
193  }
194  }
195 }
196 
197 
199 {
200  // Do nothing. The fields get written through the
201  // standard dump
202 }
203 
204 
205 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
Foam::partialWrite::write
virtual void write()
Write the partialWrite.
Definition: partialWrite.C:198
Foam::partialWrite::execute
virtual void execute()
Execute.
Definition: partialWrite.C:136
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
cloud.H
Foam::FatalIOError
IOerror FatalIOError
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::partialWrite::partialWrite
partialWrite(const partialWrite &)
Disallow default bitwise copy construct.
polyMesh.H
Foam::partialWrite::~partialWrite
virtual ~partialWrite()
Destructor.
Definition: partialWrite.C:61
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
partialWrite.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::partialWrite::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: partialWrite.C:142
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::partialWrite::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: partialWrite.C:148
dictionary.H
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::partialWrite::read
virtual void read(const dictionary &)
Read the partialWrite data.
Definition: partialWrite.C:67
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47