functionObjectValue.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) 2024 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 
28 #include "functionObjectValue.H"
30 #include "IFstream.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace substitutionModels
37 {
38  defineTypeNameAndDebug(functionObjectValue, 0);
40  (
41  substitutionModel,
42  functionObjectValue,
43  dictionary
44  );
45 }
46 }
47 
48 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
49 
50 template<class Type>
51 bool Foam::substitutionModels::functionObjectValue::getValue
52 (
53  OStringStream& oss,
54  const word& lookup
55 ) const
56 {
57  const auto& foProps = time_.functionObjects().propsDict();
58 
59  Type result;
60  if (foProps.getObjectResult(functionObject_, lookup, result))
61  {
62  oss << result;
63  return true;
64  }
65 
66  return false;
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
72 Foam::substitutionModels::functionObjectValue::functionObjectValue
73 (
74  const dictionary& dict,
75  const Time& time
76 )
77 :
78  substitutionModel(dict, time),
79  functionObject_(dict.get<word>("functionObject")),
80  entries_(),
81  debugValues_(dict.getOrDefault<bool>("debugValues", false))
82 {
83  // Populate entries
84  const dictionary& entriesDict = dict.subDict("entries");
85  for (const auto& e : entriesDict)
86  {
87  entries_.insert(cleanKey(e.keyword()), word(e.stream()));
88  }
89 }
90 
91 
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 
95 {
96  if (debugValues_)
97  {
98  Info<< nl << "Function object results:" << nl;
99  time_.functionObjects().propsDict().writeAllResultEntries(Info);
100  }
101 
102  return true;
103 }
104 
105 
107 (
108  const word& keyName
109 ) const
110 {
111  return entries_.found(keyName);
112 }
113 
114 
116 (
117  const word& key,
118  string& buffer
119 ) const
120 {
121  if (!valid(key)) return false;
122 
123  OStringStream oss;
124 
125  const word& lookup = entries_[key];
126 
127  bool ok =
128  getValue<label>(oss, lookup)
129  || getValue<scalar>(oss, lookup)
130  || getValue<vector>(oss, lookup)
131  || getValue<sphericalTensor>(oss, lookup)
132  || getValue<symmTensor>(oss, lookup)
133  || getValue<tensor>(oss, lookup);
134 
135  if (!ok) return false;
137  buffer.replaceAll(keyify(key), oss.str());
138 
139  return true;
140 }
141 
142 
144 {
145  return entries_.sortedToc();
146 }
147 
148 
149 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool apply(const word &key, string &buffer) const
Apply substitutions to this string buffer.
Base class for substitution models.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const Time & time_
Reference to the time database.
functionObjects::properties & propsDict()
Write access to the properties dictionary ("functionObjectProperties") registered on Time...
Lookup type of boundary radiation properties.
Definition: lookup.H:57
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
const functionObjectList & functionObjects() const noexcept
Return the list of function objects.
Definition: Time.H:714
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool valid(const word &keyName) const
Return true of model applies to this keyName.
virtual wordList keys() const
Return a word list of the keys.
addToRunTimeSelectionTable(substitutionModel, dictionaryValue, dictionary)
string & replaceAll(const std::string &s1, const std::string &s2, size_type pos=0)
Replace all occurrences of sub-string s1 with s2, beginning at pos in the string. ...
Definition: string.C:117
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
defineTypeNameAndDebug(dictionaryValue, 0)
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool update()
Update model local data.
static word cleanKey(const string &str)
Clean the key text.
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:208
Namespace for OpenFOAM.