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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2013-2017 OpenFOAM Foundation
9 Copyright (C) 2016-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "writeDictionary.H"
30#include "Time.H"
31#include "polyMesh.H"
33#include "IOdictionary.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
39namespace functionObjects
40{
42
44 (
48 );
49}
50}
51
52
53// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54
55void Foam::functionObjects::writeDictionary::writeHeader()
56{
57 if (firstChange_)
58 {
59 firstChange_ = false;
60
61 Info<< type() << ' ' << name() << " write:" << nl << nl;
63 }
64}
65
66
67void Foam::functionObjects::writeDictionary::checkDictionary
68(
69 const dictionary& dict,
70 const label dicti
71)
72{
73 const auto digest(dict.digest());
74
75 if (digests_[dicti] != digest)
76 {
77 digests_[dicti] = digest;
78
80 dict.writeEntry(Info);
81 Info<< nl;
83 }
84}
85
86
87bool Foam::functionObjects::writeDictionary::tryDirectory
88(
89 const word& location,
90 const label dicti
91)
92{
93 IOobject dictIO
94 (
95 dictNames_[dicti],
96 location,
97 obr_,
100 false
101 );
102
103 if (dictIO.typeHeaderOk<IOdictionary>(true))
104 {
105 checkDictionary(IOdictionary(dictIO), dicti);
106
107 return true;
108 }
109
110 return false;
111}
112
113
114// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
115
117(
118 const word& name,
119 const Time& runTime,
120 const dictionary& dict
121)
122:
123 functionObjects::regionFunctionObject(name, runTime, dict),
124 dictNames_(),
125 digests_(),
126 firstChange_(true)
127{
128 read(dict);
129}
130
131
132// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133
135{
137
138 // Make unique
139 dictNames_ = wordHashSet(dict.get<wordList>("dictNames")).sortedToc();
140
141 digests_.resize(dictNames_.size());
142 digests_ = SHA1Digest();
143
144 Info<< type() << ' ' << name() << ": monitoring dictionaries:" << nl;
145 for (const word& dictName : dictNames_)
146 {
147 Info<< " " << dictName << nl;
148 }
149 if (dictNames_.empty())
150 {
151 Info<< " none" << nl;
152 }
153 Info<< endl;
154
155 return true;
156}
157
158
159bool Foam::functionObjects::writeDictionary::performCheck()
160{
161 // Restart reporting cycle
162 firstChange_ = true;
163
164 forAll(dictNames_, dicti)
165 {
166 // Also search parent (eg, Time) as too
167 const auto* dictptr =
168 obr_.cfindObject<IOdictionary>(dictNames_[dicti], true);
169
170 if (dictptr)
171 {
172 checkDictionary(*dictptr, dicti);
173 }
174 else if (dictNames_[dicti] == Time::controlDictName)
175 {
176 // Slight hack. controlDict an unwatchedIOdictionary
177 // (not IOdictionary) and not registered on Time either
178 // - grab directly from Time
179 checkDictionary(obr_.time().controlDict(), dicti);
180 }
181 else
182 {
183 const bool ok
184 (
185 tryDirectory(obr_.time().timeName(), dicti)
186 || tryDirectory(obr_.time().constant(), dicti)
187 || tryDirectory(obr_.time().system(), dicti)
188 );
189
190 if (!ok)
191 {
192 writeHeader();
193
194 Info<< " Unable to locate dictionary "
195 << dictNames_[dicti] << nl << nl;
196
198 }
199 }
200 }
201
202 return true;
203}
204
205
207{
208 return true;
209}
210
211
213{
214 performCheck();
215 return true;
216}
217
218
219// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:137
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
virtual bool read()
Re-read model coefficients if they have changed.
The SHA1 message digest.
Definition: SHA1Digest.H:61
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
static word controlDictName
The default control dictionary name (normally "controlDict")
Definition: Time.H:226
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
virtual const word & type() const =0
Runtime type information.
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
Reports dictionary contents on change.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the selected dictionaries.
virtual bool read(const dictionary &)
Read the writeDictionary data.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
static void writeHeader(Ostream &os, const word &fieldName)
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:82
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
IOobject dictIO
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333