Constant2.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2020-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "Constant2.H"
27 #include "Constant.H"
28 #include "unitSet.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const word& name,
36  const Type& val
37 )
38 :
39  FieldFunction2<Type, Constant<Type>>(name),
40  value_(val)
41 {}
42 
43 
44 template<class Type>
46 (
47  const word& name,
48  const unitSets& units,
49  const dictionary& dict
50 )
51 :
52  FieldFunction2<Type, Constant<Type>>(name),
53  value_(dict.lookup<Type>("value", typeUnits<Type>(units.value)))
54 {}
55 
56 
57 template<class Type>
59 (
60  const word& name,
61  const unitSets& units,
62  Istream& is
63 )
64 :
65  FieldFunction2<Type, Constant<Type>>(name),
66  value_(readAndConvert<Type>(is, typeUnits<Type>(units.value)))
67 {}
68 
69 
70 template<class Type>
72 :
73  FieldFunction2<Type, Constant<Type>>(cnst),
74  value_(cnst.value_)
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
79 
80 template<class Type>
82 {}
83 
84 
85 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 
87 template<class Type>
89 (
90  Ostream& os,
91  const unitSets& units
92 ) const
93 {
94  writeEntry(os, "value", typeUnits<Type>(units.value), value_);
95 }
96 
97 
98 // ************************************************************************* i/
Templated function of two variables that returns a constant value.
Definition: Constant2.H:66
Constant(const word &name, const Type &val)
Construct from name and value.
Definition: Constant2.C:34
virtual void write(Ostream &os, const unitSets &units) const
Write in dictionary format.
Definition: Constant2.C:89
virtual ~Constant()
Destructor.
Definition: Constant2.C:81
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:63
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Type readAndConvert(Istream &, const unitSet &)
Read a type which supports unit conversion.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
const typeUnitsType< Type >::type & typeUnits(const unitSet &)
dictionary dict
unitSet value
Unit conversion for result values.