Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
28#include "functionObjectValue.H"
30#include "IFstream.H"
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace substitutionModels
37{
40 (
44 );
45}
46}
47
48// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
49
50template<class Type>
51bool 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 }
66 return false;
67}
68
69
70// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71
72Foam::substitutionModels::functionObjectValue::functionObjectValue
73(
74 const dictionary& dict,
75 const Time& time
76)
77:
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Foam::string str() const
Get the string. As Foam::string instead of std::string (may change in future).
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
const functionObjectList & functionObjects() const noexcept
Return the list of function objects.
Definition Time.H:714
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
functionObjects::properties & propsDict()
Write access to the properties dictionary ("functionObjectProperties") registered on Time.
Lookup type of boundary radiation properties.
Definition lookup.H:60
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
Base class for substitution models.
const Time & time_
Reference to the time database.
static word cleanKey(const string &str)
Clean the key text.
static string keyify(const word &w)
Return a key representation from a word.
functionObjectValue substitution model.
virtual bool apply(const word &key, string &buffer) const
Apply substitutions to this string buffer.
virtual bool valid(const word &keyName) const
Return true of model applies to this keyName.
virtual bool update()
Update model local data.
virtual wordList keys() const
Return a word list of the keys.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
messageStream Info
Information stream (stdout output on master, null elsewhere).
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
volScalarField & e