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 | 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 "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_,
53  IOobject::MUST_READ,
54  IOobject::NO_WRITE,
55  false
56  );
57 
58  if (dictIO.headerOk())
59  {
61 
62  if (dict.digest() != digests_[dictI])
63  {
64  if (firstDict)
65  {
66  Info<< type() << " " << name_ << " output:" << nl << endl;
67 
68  IOobject::writeDivider(Info);
69  Info<< endl;
70  firstDict = false;
71  }
72 
73  Info<< dict.dictName() << dict << nl;
74 
75  IOobject::writeDivider(Info);
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  // do nothing
199 }
200 
201 
203 {
204  // do nothing
205 }
206 
207 
209 {
210  // do nothing
211 }
212 
213 
214 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::dictionaryName::dictName
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::writeDictionary::read
virtual void read(const dictionary &)
Read the writeDictionary data.
Definition: writeDictionary.C:116
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::HashTable< nil, word, string::hash >::toc
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
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
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
writeDictionary.H
Foam::writeDictionary::writeDictionary
writeDictionary(const writeDictionary &)
Disallow default bitwise copy construct.
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::label
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
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::writeDictionary::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: writeDictionary.C:196
Foam::writeDictionary::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: writeDictionary.C:202
Foam::writeDictionary::execute
virtual void execute()
Execute, currently does nothing.
Definition: writeDictionary.C:140
HashSet.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::writeDictionary::write
virtual void write()
Write the writeDictionary.
Definition: writeDictionary.C:208
Foam::SHA1Digest
The SHA1 message digest.
Definition: SHA1Digest.H:62
Foam::IOobject::writeDivider
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
Definition: IOobjectI.H:108
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::writeDictionary::tryDirectory
bool tryDirectory(const label dictI, const word &location, bool &firstDict)
Helper function to write the dictionary if found at location.
Definition: writeDictionary.C:42
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::writeDictionary::~writeDictionary
virtual ~writeDictionary()
Destructor.
Definition: writeDictionary.C:110
dictionary.H
Foam::dictionary::digest
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:270
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
dictIO
IOobject dictIO(dictName, runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47