InputValueMapper.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) 2020-2021 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 "InputValueMapper.H"
29
30// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31
32template<class Type>
33const Foam::Enum
34<
36>
38({
39 { mappingMode::NONE, "none" },
40 { mappingMode::FUNCTION1, "function" },
41 { mappingMode::MINMAX, "minMax" },
42});
43
44
45// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46
47template<class Type>
49(
50 const dictionary& coeffs
51)
52{
53 mappingMode_ = mappingModeNames_.get("mode", coeffs);
54
55 switch (mappingMode_)
56 {
57 case mappingMode::NONE:
58 {
59 break;
60 }
61 case mappingMode::FUNCTION1:
62 {
63 mappingValuePtr_.reset
64 (
65 Function1<scalar>::New("function", coeffs, this->obrPtr_)
66 );
67
68 break;
69 }
70 case mappingMode::MINMAX:
71 {
72 min_ = coeffs.get<scalar>("min");
73 max_ = coeffs.get<scalar>("max");
74
75 break;
76 }
77 default:
78 {
80 << "Unhandled enumeration " << mappingModeNames_[mappingMode_]
81 << ". Available options are: " << mappingModeNames_.sortedToc()
82 << abort(FatalError);
83 }
84 }
85
86 value_ = Function1<Type>::New("value", coeffs, this->obrPtr_);
87}
88
89
90template<class Type>
92(
93 const word& entryName,
94 const dictionary& dict,
95 const objectRegistry* obrPtr
96)
97:
98 Function1<Type>(entryName, obrPtr),
99 mappingMode_(mappingMode::NONE),
100 mappingValuePtr_(nullptr),
101 min_(0),
102 max_(0),
103 value_(nullptr)
104{
105 read(dict);
106}
107
108
109template<class Type>
111(
112 const InputValueMapper<Type>& rhs
113)
114:
115 Function1<Type>(rhs),
116 mappingMode_(rhs.mappingMode_),
117 mappingValuePtr_(rhs.mappingValuePtr_.clone()),
118 min_(rhs.min_),
119 max_(rhs.max_),
120 value_(rhs.value_.clone())
121{}
122
123
124// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125
126template<class Type>
128(
129 Ostream& os
130) const
131{
132 os.writeEntry("mode", mappingModeNames_[mappingMode_]);
133
134 switch (mappingMode_)
135 {
136 case mappingMode::NONE:
137 {
138 break;
139 }
140 case mappingMode::FUNCTION1:
141 {
142 mappingValuePtr_->writeData(os);
143
144 break;
145 }
146 case mappingMode::MINMAX:
147 {
148 os.writeEntry("min", min_);
149 os.writeEntry("max", max_);
150
151 break;
152 }
153 default:
154 {
156 << "Unhandled enumeration " << mappingModeNames_[mappingMode_]
157 << ". Available options are: " << mappingModeNames_.sortedToc()
158 << abort(FatalError);
159 }
160 }
161
162 value_->writeData(os);
163}
164
165
166template<class Type>
168{
170 os.endEntry();
171
172 os.beginBlock(word(this->name() + "Coeffs"));
173 writeEntries(os);
174 os.endBlock();
175}
176
177
178// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
Function1 wrapper that maps the input value prior to it being used by another Function1.
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
static const Enum< mappingMode > mappingModeNames_
Names for the input value mapping modes.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:96
const word const dictionary & dict
Definition: Function1.H:134
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
dictionary dict