Function2UnitSets.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) 2024-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 "Function2UnitSets.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 Foam::Function2s::unitSets::unitSets(std::initializer_list<unitSet> l)
31 :
32  x(dimless),
33  y(dimless),
34  value(dimless)
35 {
36  auto i = l.begin();
37  x.reset(*i);
38  y.reset(*(++i));
39  value.reset(*(++i));
40 }
41 
42 
44 :
45  x(dimless),
46  y(dimless),
47  value(dimless)
48 {
49  is >> *this;
50 }
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
56 {
57  is.readBegin("Function2s::unitSets");
58  is.readBegin("Function2s::unitSets");
59  x.read(is);
60  y.read(is);
61  is.readEnd("Function2s::unitSets");
62  value.read(is);
63  is.readEnd("Function2s::unitSets");
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
68 
70 (
71  const word& typeName,
72  const Function2s::unitSets& units,
73  const dictionary& dict
74 )
75 {
76  if (!units.x.standard() || !units.y.standard() || !units.value.standard())
77  {
79  << "Unit conversions are not supported by "
80  << typeName << " function2 types" << abort(FatalError);
81  }
82 }
83 
84 
86 {
87  os << units;
88 }
89 
90 
91 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
92 
93 Foam::Istream& Foam::operator>>
94 (
95  Istream& is,
97 )
98 {
99  is.readBegin("Function2s::unitSets");
100  is.readBegin("Function2s::unitSets");
101  is >> units.x >> units.y;
102  is.readEnd("Function2s::unitSets");
103  is >> units.value;
104  is.readEnd("Function2s::unitSets");
105 
106  is.check(FUNCTION_NAME);
107 
108  return is;
109 }
110 
111 
112 Foam::Ostream& Foam::operator<<
113 (
114  Ostream& os,
115  const Function2s::unitSets& units
116 )
117 {
118  os << token::BEGIN_LIST
120  << units.x << token::SPACE << units.y
122  << units.value
123  << token::END_LIST;
124 
125  os.check(FUNCTION_NAME);
126 
127  return os;
128 }
129 
130 
131 // ************************************************************************* //
scalar y
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:108
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Istream & readEnd(const char *funcName)
Definition: Istream.C:123
Istream & readBegin(const char *funcName)
Definition: Istream.C:106
virtual Istream & read(token &)=0
Return next token from stream.
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
@ BEGIN_LIST
Definition: token.H:110
@ END_LIST
Definition: token.H:111
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
bool standard() const
Return whether this unit is standard. I.e., is its multiplier one?
Definition: unitSetI.H:74
void reset(const unitSet &)
Reset the unit conversion.
Definition: unitSet.C:117
A class for handling words, derived from string.
Definition: word.H:63
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FUNCTION_NAME
const dimensionSet dimless
const dimensionSet & dimless
Definition: dimensions.C:138
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void assertNoConvertUnits(const word &typeName, const Function1s::unitSets &units, const dictionary &dict)
Generate an error in an context where unit conversions are not supported.
error FatalError
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
dictionary dict
unitSet value
Unit conversion for result values.
unitSet y
Unit conversion for y-axis values.
unitSet x
Unit conversion for x-axis values.
unitSets(std::initializer_list< unitSet >)
Construct from initialiser list.
void read(Istream &is)
Update from stream.