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 * * * * * * * * * * * * * //
32
33const 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 if (found(objectName))
121 {
122 const dictionary& baseDict = subDict(objectName);
123 return baseDict.found(entryName);
124 }
125
126 return false;
127}
128
129
131(
132 const word& objectName,
133 const word& entryName,
135) const
136{
137 if (found(objectName))
138 {
139 const dictionary& baseDict = subDict(objectName);
140
141 if (baseDict.found(entryName) && baseDict.isDict(entryName))
142 {
143 dict = baseDict.subDict(entryName);
144 return true;
145 }
146 }
147
148 return false;
149}
150
151
153(
154 const word& objectName
155) const
156{
157 if (found(resultsName_))
158 {
159 return subDict(resultsName_).found(objectName);
160 }
161
162 return false;
163}
164
165
167{
168 if (found(resultsName_))
169 {
170 return subDict(resultsName_).sortedToc();
171 }
172
173 return wordList();
174}
175
176
178(
179 const word& objectName,
180 const word& entryName
181) const
182{
183 if (found(resultsName_))
184 {
185 const dictionary& resultsDict = subDict(resultsName_);
186
187 if (resultsDict.found(objectName))
188 {
189 const dictionary& objectDict = resultsDict.subDict(objectName);
190
191 for (const entry& dEntry : objectDict)
192 {
193 const dictionary& dict = dEntry.dict();
194
195 if (dict.found(entryName))
196 {
197 return true;
198 }
199 }
200 }
201 }
202
203 return false;
204}
205
206
208(
209 const word& objectName,
210 const word& entryName
211) const
212{
213 if (found(resultsName_))
214 {
215 const dictionary& resultsDict = subDict(resultsName_);
216
217 if (resultsDict.found(objectName))
218 {
219 const dictionary& objectDict = resultsDict.subDict(objectName);
220
221 for (const entry& dEntry : objectDict)
222 {
223 const dictionary& dict = dEntry.dict();
224
225 if (dict.found(entryName))
226 {
227 return dict.dictName();
228 }
229 }
230 }
231 }
232
233 return word::null;
234}
235
236
238(
239 const word& objectName
240) const
241{
242 DynamicList<word> result;
243
244 if (found(resultsName_))
245 {
246 const dictionary& resultsDict = subDict(resultsName_);
247
248 if (resultsDict.found(objectName))
249 {
250 const dictionary& objectDict = resultsDict.subDict(objectName);
251
252 for (const entry& dEntry : objectDict)
253 {
254 const dictionary& dict = dEntry.dict();
255
256 result.append(dict.toc());
257 }
258 }
259 }
260
261 wordList entries;
262 entries.transfer(result);
263
264 return entries;
265}
266
267
269(
270 const word& objectName,
271 Ostream& os
272) const
273{
274 if (found(resultsName_))
275 {
276 const dictionary& resultsDict = subDict(resultsName_);
277
278 if (resultsDict.found(objectName))
279 {
280 const dictionary& objectDict = resultsDict.subDict(objectName);
281
282 for (const word& dataFormat : objectDict.sortedToc())
283 {
284 os << " Type: " << dataFormat << nl;
285
286 const dictionary& resultDict = objectDict.subDict(dataFormat);
287
288 for (const word& result : resultDict.sortedToc())
289 {
290 os << " " << result << nl;
291 }
292 }
293 }
294 }
295}
296
297
299(
300 Ostream& os
301) const
302{
303 if (found(resultsName_))
304 {
305 const dictionary& resultsDict = subDict(resultsName_);
306
307 for (const word& objectName : resultsDict.sortedToc())
308 {
309 os << "Object: " << objectName << endl;
310
311 writeResultEntries(objectName, os);
312 }
313 }
314}
315
316
317// ************************************************************************* //
bool found
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
void transfer(List< T > &list)
Definition: List.C:447
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:616
bool isDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Check if entry is found and is a sub-dictionary.
Definition: dictionaryI.H:147
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
Definition: add.H:161
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
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
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 hasObjectDict(const word &objectName) const
Return true if the object with objectName exists.
void clearTrigger()
Remove the trigger index from the properties.
label getTrigger() const
Get the current trigger index.
wordList objectResultNames() const
Return list of objects with results.
wordList objectResultEntries() const
Retrieve the result entries.
A class for handling words, derived from Foam::string.
Definition: word.H:68
static const word null
An empty word.
Definition: word.H:80
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
List< word > wordList
A List of words.
Definition: fileName.H:63
constexpr label labelMin
Definition: label.H:60
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
propsDict readIfPresent("fields", acceptFields)