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 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 :
44  IOdictionary(io)
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  bool increaseOnly
101 )
102 {
103  const label currTriggeri = getTrigger();
104 
105  if (increaseOnly ? (triggeri > currTriggeri) : (triggeri != currTriggeri))
106  {
107  set("triggerIndex", triggeri);
108  return true;
109  }
110 
111  // TBD: any special handling for triggeri == labelMin - eg, clearTrigger()
112 
113  return false;
114 }
115 
116 
118 (
119  const word& objectName,
120  const word& entryName
121 ) const
122 {
123  if (found(objectName))
124  {
125  const dictionary& baseDict = subDict(objectName);
126  return baseDict.found(entryName);
127  }
128 
129  return false;
130 }
131 
132 
134 (
135  const word& objectName,
136  const word& entryName,
138 ) const
139 {
140  if (found(objectName))
141  {
142  const dictionary& baseDict = subDict(objectName);
143 
144  if (baseDict.found(entryName) && baseDict.isDict(entryName))
145  {
146  dict = baseDict.subDict(entryName);
147  return true;
148  }
149  }
150 
151  return false;
152 }
153 
154 
156 (
157  const word& objectName
158 ) const
159 {
160  if (found(resultsName_))
161  {
162  return subDict(resultsName_).found(objectName);
163  }
164 
165  return false;
166 }
167 
168 
170 {
171  if (found(resultsName_))
172  {
173  return subDict(resultsName_).sortedToc();
174  }
175 
176  return wordList();
177 }
178 
179 
181 (
182  const word& objectName,
183  const word& entryName
184 ) const
185 {
186  if (found(resultsName_))
187  {
188  const dictionary& resultsDict = subDict(resultsName_);
189 
190  if (resultsDict.found(objectName))
191  {
192  const dictionary& objectDict = resultsDict.subDict(objectName);
193 
194  for (const entry& dEntry : objectDict)
195  {
196  const dictionary& dict = dEntry.dict();
197 
198  if (dict.found(entryName))
199  {
200  return true;
201  }
202  }
203  }
204  }
205 
206  return false;
207 }
208 
209 
211 (
212  const word& objectName,
213  const word& entryName
214 ) const
215 {
216  if (found(resultsName_))
217  {
218  const dictionary& resultsDict = subDict(resultsName_);
219 
220  if (resultsDict.found(objectName))
221  {
222  const dictionary& objectDict = resultsDict.subDict(objectName);
223 
224  for (const entry& dEntry : objectDict)
225  {
226  const dictionary& dict = dEntry.dict();
227 
228  if (dict.found(entryName))
229  {
230  return dict.dictName();
231  }
232  }
233  }
234  }
235 
236  return word::null;
237 }
238 
239 
241 (
242  const word& objectName
243 ) const
244 {
245  DynamicList<word> result;
246 
247  if (found(resultsName_))
248  {
249  const dictionary& resultsDict = subDict(resultsName_);
250 
251  if (resultsDict.found(objectName))
252  {
253  const dictionary& objectDict = resultsDict.subDict(objectName);
254 
255  for (const entry& dEntry : objectDict)
256  {
257  const dictionary& dict = dEntry.dict();
258 
259  result.append(dict.toc());
260  }
261  }
262  }
263 
264  wordList entries;
265  entries.transfer(result);
266 
267  return entries;
268 }
269 
270 
272 (
273  const word& objectName,
274  Ostream& os
275 ) const
276 {
277  if (found(resultsName_))
278  {
279  const dictionary& resultsDict = subDict(resultsName_);
280 
281  if (resultsDict.found(objectName))
282  {
283  const dictionary& objectDict = resultsDict.subDict(objectName);
284 
285  for (const word& dataFormat : objectDict.sortedToc())
286  {
287  os << " Type: " << dataFormat << nl;
288 
289  const dictionary& resultDict = objectDict.subDict(dataFormat);
290 
291  for (const word& result : resultDict.sortedToc())
292  {
293  os << " " << result << nl;
294  }
295  }
296  }
297  }
298 }
299 
300 
302 (
303  Ostream& os
304 ) const
305 {
306  if (found(resultsName_))
307  {
308  const dictionary& resultsDict = subDict(resultsName_);
309 
310  for (const word& objectName : resultsDict.sortedToc())
311  {
312  os << "Object: " << objectName << endl;
313 
314  writeResultEntries(objectName, os);
315  }
316  }
317 }
318 
319 
320 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::functionObjects::properties::hasObjectDict
bool hasObjectDict(const word &objectName) const
Return true if the object with objectName exists.
Definition: functionObjectProperties.C:60
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::DynamicList< word >
Foam::dictionary::found
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
Foam::functionObjects::properties::getObjectDict
dictionary & getObjectDict(const word &objectName)
Get dictionary for named object. Creates one if required.
Definition: functionObjectProperties.C:69
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::properties::hasResultObject
bool hasResultObject(const word &objectName) const
Return true if the object with objectName exists in results.
Definition: functionObjectProperties.C:156
Foam::functionObjects::properties::getTrigger
label getTrigger() const
Get the current trigger index.
Definition: functionObjectProperties.C:88
Foam::functionObjects::properties::clearTrigger
void clearTrigger()
Remove the trigger index from the properties.
Definition: functionObjectProperties.C:82
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::functionObjects::properties::foundObjectProperty
bool foundObjectProperty(const word &objectName, const word &entryName) const
Return true if the property exists.
Definition: functionObjectProperties.C:118
functionObjectProperties.H
Foam::functionObjects::properties::objectResultType
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
Definition: functionObjectProperties.C:211
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::properties::properties
properties(const properties &)=delete
No copy construct.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
os
OBJstream os(runTime.globalPath()/outputName)
Foam::functionObjects::properties::setTrigger
bool setTrigger(const label triggeri, bool increaseOnly=true)
Set the trigger index. Normally only if greater than current.
Definition: functionObjectProperties.C:98
Foam::dictionary::isDict
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
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::functionObjects::properties::objectResultNames
wordList objectResultNames() const
Return list of objects with results.
Definition: functionObjectProperties.C:169
Foam::functionObjects::properties::objectNames
wordList objectNames() const
Return list of object names.
Definition: functionObjectProperties.C:50
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< word >
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::functionObjects::properties::writeAllResultEntries
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
Definition: functionObjectProperties.C:302
Foam::functionObjects::properties::hasResultObjectEntry
bool hasResultObjectEntry(const word &objectName, const word &entryName) const
Definition: functionObjectProperties.C:181
Foam::functionObjects::properties::writeResultEntries
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
Foam::labelMin
constexpr label labelMin
Definition: label.H:60
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
SHA1.H
Foam::dictionary::sortedToc
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:616
Foam::functionObjects::properties::objectResultEntries
wordList objectResultEntries(const word &objectName) const
Return result entries for named object.
Definition: functionObjectProperties.C:241