Loading...
Searching...
No Matches
InputValueMapper.H
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-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
26Class
27 Foam::Function1Types::InputValueMapper
28
29Description
30 Function1 wrapper that maps the input value prior to it being used by
31 another Function1.
32
33 Example usage for limiting a polynomial:
34 \verbatim
35 <entryName>
36 {
37 type inputValueMapper;
38 mode minMax;
39
40 min 0.4;
41 max 1.4;
42
43 value polynomial
44 (
45 (5 1)
46 (-2 2)
47 (-2 3)
48 (1 4)
49 );
50 }
51 \endverbatim
52
53 Here the return value will be:
54 - poly(0.4) for x <= 0.4;
55 - poly(1.4) for x >= 1.4; and
56 - poly(x) for 0.4 < x < 1.4.
57
58
59 Example usage for supplying a patch mass flux for a table lookup:
60 \verbatim
61 <entryName>
62 {
63 type inputValueMapper;
64 mode function;
65
66 function
67 {
68 type functionObjectValue;
69 functionObject surfaceFieldValue1;
70 functionObjectResult sum(outlet,phi);
71 }
72
73 value
74 {
75 type table;
76 file "<system>/fanCurve.txt";
77 }
78 }
79 \endverbatim
80
81 Where:
82 \table
83 Property | Description | Required
84 mode | Mapping mode (see below) | yes
85 function | Mapping Function1 | no*
86 min | Minimum input value | no*
87 max | Maximum input value | no*
88 value | Function of type Function1<Type> | yes
89 \endtable
90
91 Mapping modes include
92 - none : the input value is simply passed to the 'value' Function1
93 - function : the input value is passed through the 'function' Function1
94 before being passed to the 'value' Function1
95 - minMax : limits the input value to 'min' and 'max' values before being
96 passed to the 'value' Function1
97
98Note
99 Replaces the LimitRange Function1 (v2106 and earlier)
100
101SourceFiles
102 InputValueMapper.C
103 InputValueMapperI.H
104
105\*---------------------------------------------------------------------------*/
106
107#ifndef Foam_Function1Types_InputValueMapper_H
108#define Foam_Function1Types_InputValueMapper_H
109
110#include "Function1.H"
111#include "Enum.H"
112
113// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114
115namespace Foam
116{
117namespace Function1Types
118{
119
120/*---------------------------------------------------------------------------*\
121 Class InputValueMapper Declaration
122\*---------------------------------------------------------------------------*/
123
124template<class Type>
126:
127 public Function1<Type>
128{
129public:
130
131 // Public Enumerations
132
133 //- Input value mapping mode
134 enum class mappingMode
135 {
136 NONE,
137 FUNCTION1,
138 MINMAX
139 };
140
141 //- Names for the input value mapping modes
142 static const Enum<mappingMode> mappingModeNames_;
143
145private:
146
147 // Private Data
148
149 //- Mapping mode
150 mappingMode mappingMode_;
151
152 // Function1 mapping
153
154 //- Input value Function1
155 autoPtr<Function1<scalar>> mappingValuePtr_;
156
158 // Min/max mapping
160 //- Minimum input value
161 scalar min_;
162
163 //- Maximum input value
164 scalar max_;
166
167 // Function being wrapped
168
169 //- Value function
171
172
173 // Private Member Functions
174
175 //- Read the coefficients from the given dictionary
176 void read(const dictionary& coeffs);
177
178
179public:
180
181 //- Runtime type information
182 TypeName("inputValueMapper");
183
184
185 // Generated Methods
186
187 //- No copy assignment
188 void operator=(const InputValueMapper<Type>&) = delete;
189
190
191 // Constructors
192
193 //- Construct from entry name, dictionary and optional registry
195 (
196 const word& entryName,
197 const dictionary& dict,
198 const objectRegistry* obrPtr = nullptr
199 );
200
201 //- Copy construct
203
204 //- Return a clone
205 virtual tmp<Function1<Type>> clone() const
206 {
207 return Function1<Type>::Clone(*this);
208 }
209
210
211 //- Destructor
212 virtual ~InputValueMapper() = default;
213
214
215 // Member Functions
216
217 //- Return value for time t
218 virtual inline Type value(const scalar t) const;
220 //- Integrate between two (scalar) values
221 virtual inline Type integrate(const scalar x1, const scalar x2) const;
222
223 //- Write in dictionary format
224 virtual void writeData(Ostream& os) const;
225
226 //- Write coefficient entries in dictionary format
227 virtual void writeEntries(Ostream& os) const;
228};
229
230
231// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232
233} // End namespace Function1Types
234} // End namespace Foam
235
236// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237
238#include "InputValueMapperI.H"
239
240#ifdef NoRepository
241 #include "InputValueMapper.C"
242#endif
243
244// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245
246#endif
247
248// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
Function1 wrapper that maps the input value prior to it being used by another Function1.
virtual tmp< Function1< Type > > clone() const
Return a clone.
virtual void writeData(Ostream &os) const
Write in dictionary format.
void operator=(const InputValueMapper< Type > &)=delete
No copy assignment.
TypeName("inputValueMapper")
Runtime type information.
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
static const Enum< mappingMode > mappingModeNames_
Names for the input value mapping modes.
virtual Type value(const scalar t) const
Return value for time t.
InputValueMapper(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
virtual ~InputValueMapper()=default
Destructor.
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Function1(const word &entryName, const objectRegistry *obrPtr=nullptr)
Construct from entry name.
Definition Function1.C:31
static tmp< Function1< Type > > Clone(const Derived &fun)
Clone a Function1.
Definition Function1.H:190
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Registry of regIOobjects.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68