functionObjectProperties.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) 2021-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "SHA1.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 const Foam::word Foam::functionObjects::properties::resultsName_ =
34  SHA1("results").str();
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 (
41  const IOobject& io
42 )
43 :
45 {}
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
51 {
52  // TODO
53  // - remove resultsName_ dict from results?
54  // - or put objects into their own subdictionary?
55  return sortedToc();
56 }
57 
58 
60 (
61  const word& objectName
62 ) const
63 {
64  return found(objectName);
65 }
66 
67 
69 (
70  const word& objectName
71 )
72 {
73  if (!found(objectName))
74  {
75  add(objectName, dictionary());
76  }
77 
78  return subDict(objectName);
79 }
80 
81 
83 {
84  remove("triggerIndex");
85 }
86 
87 
89 {
90  // Like getOrDefault, but without reporting missing entry (noisy)
91  label idx = labelMin;
92  readIfPresent("triggerIndex", idx);
93  return idx;
94 }
95 
96 
98 (
99  const label triggeri
100 )
101 {
102  if (triggeri != getTrigger())
103  {
104  set("triggerIndex", triggeri);
105  return true;
106  }
107 
108  // TBD: any special handling for triggeri == labelMin - eg, clearTrigger()
109 
110  return false;
111 }
112 
113 
115 (
116  const word& objectName,
117  const word& entryName
118 ) const
119 {
120  const dictionary* dictptr = findDict(objectName);
121 
122  return (dictptr && dictptr->found(entryName));
123 }
124 
125 
127 (
128  const word& objectName,
129  const word& entryName,
131 ) const
132 {
133  const dictionary* dictptr = findDict(objectName);
134 
135  if (dictptr)
136  {
137  dictptr = dictptr->findDict(entryName);
138 
139  if (dictptr)
140  {
141  dict = *dictptr;
142  return true;
143  }
144  }
145 
146  return false;
147 }
148 
149 
151 (
152  const word& objectName,
154 ) const
155 {
156  const dictionary* dictptr = findDict(resultsName_);
157 
158  if (dictptr)
159  {
160  const dictionary* objptr = dictptr->findDict(objectName);
161 
162  if (objptr)
163  {
164  dict = *objptr;
165  return true;
166  }
167  }
168 
169  return false;
170 }
171 
172 
174 (
175  const word& objectName
176 ) const
177 {
178  const dictionary* dictptr = findDict(resultsName_);
179 
180  return (dictptr && dictptr->found(objectName));
181 }
182 
183 
185 {
186  if (found(resultsName_))
187  {
188  return subDict(resultsName_).sortedToc();
189  }
190 
191  return wordList();
192 }
193 
194 
196 (
197  const word& objectName,
198  const word& entryName
199 ) const
200 {
201  if (found(resultsName_))
202  {
203  const dictionary& resultsDict = subDict(resultsName_);
204 
205  if (resultsDict.found(objectName))
206  {
207  const dictionary& objectDict = resultsDict.subDict(objectName);
208 
209  for (const entry& dEntry : objectDict)
210  {
211  const dictionary& dict = dEntry.dict();
212 
213  if (dict.found(entryName))
214  {
215  return true;
216  }
217  }
218  }
219  }
220 
221  return false;
222 }
223 
224 
226 (
227  const word& objectName,
228  const word& entryName
229 ) const
230 {
231  if (found(resultsName_))
232  {
233  const dictionary& resultsDict = subDict(resultsName_);
234 
235  if (resultsDict.found(objectName))
236  {
237  const dictionary& objectDict = resultsDict.subDict(objectName);
238 
239  for (const entry& dEntry : objectDict)
240  {
241  const dictionary& dict = dEntry.dict();
242 
243  if (dict.found(entryName))
244  {
245  return dict.dictName();
246  }
247  }
248  }
249  }
250 
251  return word::null;
252 }
253 
254 
256 (
257  const word& objectName
258 ) const
259 {
260  DynamicList<word> result;
261 
262  if (found(resultsName_))
263  {
264  const dictionary& resultsDict = subDict(resultsName_);
265 
266  if (resultsDict.found(objectName))
267  {
268  const dictionary& objectDict = resultsDict.subDict(objectName);
269 
270  for (const entry& dEntry : objectDict)
271  {
272  const dictionary& dict = dEntry.dict();
273 
274  result.append(dict.toc());
275  }
276  }
277  }
278 
279  wordList entries;
280  entries.transfer(result);
281 
282  return entries;
283 }
284 
285 
287 (
288  const word& objectName,
289  Ostream& os
290 ) const
291 {
292  if (found(resultsName_))
293  {
294  const dictionary& resultsDict = subDict(resultsName_);
295 
296  if (resultsDict.found(objectName))
297  {
298  const dictionary& objectDict = resultsDict.subDict(objectName);
299 
300  for (const word& dataFormat : objectDict.sortedToc())
301  {
302  os << " Type: " << dataFormat << nl;
303 
304  const dictionary& resultDict = objectDict.subDict(dataFormat);
305 
306  for (const word& result : resultDict.sortedToc())
307  {
308  os << " " << result << nl;
309  }
310  }
311  }
312  }
313 }
314 
315 
317 (
318  Ostream& os
319 ) const
320 {
321  if (found(resultsName_))
322  {
323  const dictionary& resultsDict = subDict(resultsName_);
324 
325  for (const word& objectName : resultsDict.sortedToc())
326  {
327  os << "Object: " << objectName << endl;
328 
329  writeResultEntries(objectName, os);
330  }
331  }
332 }
333 
334 
335 // ************************************************************************* //
dictionary dict
std::string str(const bool prefixed=false) const
The digest (40-byte) text representation, optionally with &#39;_&#39; prefix.
Definition: SHA1I.H:114
properties(const properties &)=delete
No copy construct.
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:326
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
dictionary & getObjectDict(const word &objectName)
Get dictionary for named object. Creates one if required.
wordList objectNames() const
Return list of object names.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
label getTrigger() const
Get the current trigger index.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
wordList objectResultEntries(const word &objectName) const
Return result entries for named object.
constexpr label labelMin
Definition: label.H:54
bool foundObjectProperty(const word &objectName, const word &entryName) const
Return true if the property exists.
bool setTrigger(const label triggeri)
Set new trigger index.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
wordList objectResultNames() const
Return list of objects with results.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
bool hasResultObjectEntry(const word &objectName, const word &entryName) const
Return true if the object with objectName exists and has entryName in its results.
void clearTrigger()
Remove the trigger index from the properties.
A class for handling words, derived from Foam::string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:84
bool hasObjectDict(const word &objectName) const
Return true if the object with objectName exists.
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicList.H:584
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
bool hasResultObject(const word &objectName) const
Return true if the object with objectName exists in results.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
OBJstream os(runTime.globalPath()/outputName)
List< word > wordList
List of word.
Definition: fileName.H:59
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
meshDefDict readIfPresent("polyMeshPatches", polyPatchNames)
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:56
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
bool getObjectResultDict(const word &objectName, dictionary &dict) const
Get dictionary of object results, return true if set.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
bool found
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:601
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
Definition: dictionaryI.H:124