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 -------------------------------------------------------------------------------
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 "InputValueMapper.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 template<class Type>
33 const Foam::Enum
34 <
36 >
38 ({
39  { mappingMode::NONE, "none" },
40  { mappingMode::FUNCTION1, "function" },
41  { mappingMode::MINMAX, "minMax" },
42 });
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
47 template<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 
90 template<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 
109 template<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 
126 template<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 
166 template<class Type>
168 {
170  os.endEntry();
171 
172  os.beginBlock(word(this->name() + "Coeffs"));
173  writeEntries(os);
174  os.endBlock();
175 }
176 
177 
178 // ************************************************************************* //
Foam::Function1Types::InputValueMapper
Function1 wrapper that maps the input value prior to it being used by another Function1.
Definition: InputValueMapper.H:148
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::Function1Types::InputValueMapper::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: InputValueMapper.C:128
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
InputValueMapper.H
writeData
const bool writeData(pdfDictionary.get< bool >("writeData"))
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::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::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::Function1Types::InputValueMapper::mappingModeNames_
static const Enum< mappingMode > mappingModeNames_
Names for the input value mapping modes.
Definition: InputValueMapper.H:165
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
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::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56