writeDictionary.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 |
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 "writeDictionary.H"
27 #include "dictionary.H"
28 #include "Time.H"
29 #include "HashSet.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 defineTypeNameAndDebug(writeDictionary, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
42 (
43  const label dictI,
44  const word& location,
45  bool& firstDict
46 )
47 {
49  (
50  dictNames_[dictI],
51  location,
52  obr_,
55  false
56  );
57 
58  if (dictIO.headerOk())
59  {
60  IOdictionary dict(dictIO);
61 
62  if (dict.digest() != digests_[dictI])
63  {
64  if (firstDict)
65  {
66  Info<< type() << " " << name_ << " output:" << nl << endl;
67 
69  Info<< endl;
70  firstDict = false;
71  }
72 
73  Info<< dict.dictName() << dict << nl;
74 
76 
77  digests_[dictI] = dict.digest();
78  }
79 
80  return true;
81  }
82 
83  return false;
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 (
91  const word& name,
92  const objectRegistry& obr,
93  const dictionary& dict,
94  const bool loadFromFiles
95 )
96 :
97  name_(name),
98  obr_(obr),
99  dictNames_(),
100  digests_()
101 {
102  read(dict);
103 
104  execute();
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
109 
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
117 {
118  wordList dictNames(dict.lookup("dictNames"));
119  HashSet<word> uniqueNames(dictNames);
120  dictNames_ = uniqueNames.toc();
121 
122  digests_.setSize(dictNames_.size(), SHA1Digest());
123 
124  Info<< type() << " " << name_ << ": monitoring dictionaries:" << nl;
125  if (dictNames_.size())
126  {
127  forAll(dictNames_, i)
128  {
129  Info<< " " << dictNames_[i] << endl;
130  }
131  }
132  else
133  {
134  Info<< " none" << nl;
135  }
136  Info<< endl;
137 }
138 
139 
141 {
142  bool firstDict = true;
143  forAll(dictNames_, i)
144  {
145  if (obr_.foundObject<dictionary>(dictNames_[i]))
146  {
147  const dictionary& dict =
148  obr_.lookupObject<dictionary>(dictNames_[i]);
149 
150  if (dict.digest() != digests_[i])
151  {
152  if (firstDict)
153  {
154  Info<< type() << " " << name_ << " output:" << nl << endl;
155 
157  Info<< endl;
158  firstDict = false;
159  }
160 
161  digests_[i] = dict.digest();
162 
163  Info<< dict.dictName() << dict << nl;
165  Info<< endl;
166  }
167  }
168  else
169  {
170  bool processed = tryDirectory(i, obr_.time().timeName(), firstDict);
171 
172  if (!processed)
173  {
174  processed = tryDirectory(i, obr_.time().constant(), firstDict);
175  }
176 
177  if (!processed)
178  {
179  processed = tryDirectory(i, obr_.time().system(), firstDict);
180  }
181 
182  if (!processed)
183  {
184  Info<< " Unable to locate dictionary " << dictNames_[i]
185  << nl << endl;
186  }
187  else
188  {
189  Info<< endl;
190  }
191  }
192  }
193 }
194 
195 
197 {
198  execute();
199 }
200 
201 
203 {
204  // do nothing
205 }
206 
207 
209 {
210  // do nothing
211 }
212 
213 
214 // ************************************************************************* //
writeDictionary(const writeDictionary &)
Disallow default bitwise copy construct.
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:272
IOobject dictIO(dictName, runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE)
virtual void execute()
Execute, currently does nothing.
virtual void write()
Write the writeDictionary.
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
messageStream Info
virtual void end()
Execute at the final time-loop, currently does nothing.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void read(const dictionary &)
Read the writeDictionary data.
Namespace for OpenFOAM.
dictionary dict
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
Definition: IOobjectI.H:98
#define forAll(list, i)
Definition: UList.H:421
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
Registry of regIOobjects.
A HashTable with keys but without contents.
Definition: HashSet.H:59
bool read(const char *, int32_t &)
Definition: int32IO.C:87
bool headerOk()
Read and check header info.
Definition: IOobject.C:424
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
The SHA1 message digest.
Definition: SHA1Digest.H:62
virtual ~writeDictionary()
Destructor.
defineTypeNameAndDebug(combustionModel, 0)
bool tryDirectory(const label dictI, const word &location, bool &firstDict)
Helper function to write the dictionary if found at location.