Constant.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) 2011-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 "Constant.H"
27 #include "unitSet.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const word& name,
35  const Type& val
36 )
37 :
38  FieldFunction1<Type, Constant<Type>>(name),
39  value_(val)
40 {}
41 
42 
43 template<class Type>
45 (
46  const word& name,
47  const unitSets& units,
48  const dictionary& dict
49 )
50 :
51  FieldFunction1<Type, Constant<Type>>(name),
52  value_(dict.lookup<Type>("value", typeUnits<Type>(units.value)))
53 {}
54 
55 
56 template<class Type>
58 (
59  const word& name,
60  const unitSets& units,
61  Istream& is
62 )
63 :
64  FieldFunction1<Type, Constant<Type>>(name),
65  value_(readAndConvert<Type>(is, typeUnits<Type>(units.value)))
66 {}
67 
68 
69 template<class Type>
71 :
72  FieldFunction1<Type, Constant<Type>>(cnst),
73  value_(cnst.value_)
74 {}
75 
76 
77 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
78 
79 template<class Type>
81 {}
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
86 template<class Type>
88 (
89  Ostream& os,
90  const unitSets& units
91 ) const
92 {
93  writeEntry(os, "value", typeUnits<Type>(units.value), value_);
94 }
95 
96 
97 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
98 
99 template<class Type>
101 {
102  FieldFunction1<Type, Constant<Type>>::operator=(cnst);
103 
104  value_ = cnst.value_;
105 }
106 
107 
108 // ************************************************************************* i/
Templated function that returns a constant value.
Definition: Constant.H:60
Constant(const word &name, const Type &val)
Construct from name and value.
Definition: Constant.C:33
void operator=(const Constant< Type > &)
Copy assignment.
Definition: Constant.C:100
virtual void write(Ostream &os, const unitSets &units) const
Write in dictionary format.
Definition: Constant.C:88
virtual ~Constant()
Destructor.
Definition: Constant.C:80
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
void writeEntry(Ostream &os, const omega &a)
Definition: omega1.C:99
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.
const typeUnitsType< Type >::type & typeUnits(const unitSet &)
dictionary dict
Struct containing two unitSets for use in converting both the argument and the value of a Function1.
unitSet value
Unit conversion for result values.