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-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 Class
27  Foam::Function1Types::InputValueMapper
28 
29 Description
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 
98 Note
99  Replaces the LimitRange Function1 (v2106 and earlier)
100 
101 SourceFiles
102  InputValueMapper.C
103  InputValueMapperI.H
104 
105 \*---------------------------------------------------------------------------*/
106 
107 #ifndef Function1Types_InputValueMapper_H
108 #define Function1Types_InputValueMapper_H
109 
110 #include "Function1.H"
111 #include "Enum.H"
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 namespace Foam
116 {
117 namespace Function1Types
118 {
119 
120 /*---------------------------------------------------------------------------*\
121  Class InputValueMapper Declaration
122 \*---------------------------------------------------------------------------*/
123 
124 template<class Type>
125 class InputValueMapper
126 :
127  public Function1<Type>
128 {
129 public:
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 
144 
145 private:
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 
157 
158  // Min/max mapping
159 
160  //- Minimum input value
161  scalar min_;
162 
163  //- Maximum input value
164  scalar max_;
165 
166 
167  // Function being wrapped
168 
169  //- Value function
170  autoPtr<Function1<Type>> value_;
171 
172 
173  // Private Member Functions
174 
175  //- Read the coefficients from the given dictionary
176  void read(const dictionary& coeffs);
177 
178 
179 public:
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
202  explicit InputValueMapper(const InputValueMapper<Type>& rhs);
203 
204 
205  //- Destructor
206  virtual ~InputValueMapper() = default;
207 
208 
209  // Member Functions
210 
211  //- Return value for time t
212  virtual inline Type value(const scalar t) const;
213 
214  //- Integrate between two (scalar) values
215  virtual inline Type integrate(const scalar x1, const scalar x2) const;
216 
217  //- Write in dictionary format
218  virtual void writeData(Ostream& os) const;
219 
220  //- Write coefficient entries in dictionary format
221  void writeEntries(Ostream& os) const;
222 };
223 
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace Function1Types
228 } // End namespace Foam
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 #include "InputValueMapperI.H"
233 
234 #ifdef NoRepository
235  #include "InputValueMapper.C"
236 #endif
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 #endif
241 
242 // ************************************************************************* //
Foam::Function1Types::InputValueMapper
Function1 wrapper that maps the input value prior to it being used by another Function1.
Definition: InputValueMapper.H:148
Foam::Enum< mappingMode >
Foam::Function1Types::InputValueMapper::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: InputValueMapper.C:128
InputValueMapper.C
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Function1Types::InputValueMapper::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: InputValueMapper.C:167
Foam::Function1::entryName
const word & entryName
Definition: Function1.H:133
Function1.H
Foam::Function1Types::InputValueMapper::~InputValueMapper
virtual ~InputValueMapper()=default
Destructor.
Foam::Function1::dict
const word const dictionary & dict
Definition: Function1.H:134
Foam::Function1Types::InputValueMapper::InputValueMapper
InputValueMapper(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: InputValueMapper.C:92
Foam::Function1Types::InputValueMapper::value
virtual Type value(const scalar t) const
Return value for time t.
Definition: InputValueMapperI.H:34
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Function1::obrPtr
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
Foam::Function1Types::InputValueMapper::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: InputValueMapperI.H:69
Foam::Function1Types::InputValueMapper::mappingModeNames_
static const Enum< mappingMode > mappingModeNames_
Names for the input value mapping modes.
Definition: InputValueMapper.H:165
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Function1Types::InputValueMapper::mappingMode
mappingMode
Input value mapping mode.
Definition: InputValueMapper.H:157
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::Function1Types::InputValueMapper::mappingMode::FUNCTION1
Foam::Function1Types::InputValueMapper::mappingMode::MINMAX
InputValueMapperI.H
Foam::Function1Types::InputValueMapper::mappingMode::NONE
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Function1Types::InputValueMapper::TypeName
TypeName("inputValueMapper")
Runtime type information.
Foam::Function1Types::InputValueMapper::operator=
void operator=(const InputValueMapper< Type > &)=delete
No copy assignment.
Enum.H