Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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 * * * * * * * * * * * * * //
33const Foam::word Foam::functionObjects::properties::resultsName_ =
34 SHA1("results").str();
35
36
37// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38
40(
41 const IOobject& io
42)
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
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 }
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
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;
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;
167 }
168
169 return false;
170}
171
172
174(
175 const word& objectName
176) const
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 }
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 }
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;
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// ************************************************************************* //
bool found
propsDict readIfPresent("fields", acceptFields)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void append(const T &val)
Copy append an element to the end of this list.
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition SHA1.H:57
std::string str(const bool prefixed=false) const
The digest (40-byte) text representation, optionally with '_' prefix.
Definition SHA1I.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition dictionary.C:441
dictionary()
Default construct, a top-level empty dictionary.
Definition dictionary.C:68
bool remove(const word &keyword)
Remove an entry specified by keyword.
friend class entry
Declare friendship with the entry class for IO.
Definition dictionary.H:338
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
wordList sortedToc() const
Return the sorted table of contents.
Definition dictionary.C:601
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition dictionary.C:765
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
properties(const properties &)=delete
No copy construct.
wordList objectNames() const
Return list of object names.
dictionary & getObjectDict(const word &objectName)
Get dictionary for named object. Creates one if required.
bool setTrigger(const label triggeri)
Set new trigger index.
bool foundObjectProperty(const word &objectName, const word &entryName) const
Return true if the property exists.
bool hasResultObjectEntry(const word &objectName, const word &entryName) const
Return true if the object with objectName exists and has entryName in its results.
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
bool hasResultObject(const word &objectName) const
Return true if the object with objectName exists in results.
bool getObjectResultDict(const word &objectName, dictionary &dict) const
Get dictionary of object results, return true if set.
bool hasObjectDict(const word &objectName) const
Return true if the object with objectName exists.
void clearTrigger()
Remove the trigger index from the properties.
wordList objectResultEntries(const word &objectName) const
Return result entries for named object.
label getTrigger() const
Get the current trigger index.
wordList objectResultNames() const
Return list of objects with results.
A class for handling words, derived from Foam::string.
Definition word.H:66
static const word null
An empty word.
Definition word.H:84
OBJstream os(runTime.globalPath()/outputName)
const auto & io
List< word > wordList
List of word.
Definition fileName.H:60
constexpr label labelMin
Definition label.H:54
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict