Function1UnitSets.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 "Function1UnitSets.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 Foam::Function1s::unitSets::unitSets(std::initializer_list<unitSet> l)
31 :
32  x(dimless),
33  value(dimless)
34 {
35  auto i = l.begin();
36  x.reset(*i);
37  value.reset(*(++i));
38 }
39 
40 
42 :
43  x(dimless),
44  value(dimless)
45 {
46  is >> *this;
47 }
48 
49 
50 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 
53 {
54  is.readBegin("Function1s::unitSets");
55  x.read(is);
56  value.read(is);
57  is.readEnd("Function1s::unitSets");
58 }
59 
60 
61 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
62 
64 (
65  const word& typeName,
66  const Function1s::unitSets& units,
67  const dictionary& dict
68 )
69 {
70  if (!units.x.standard() || !units.value.standard())
71  {
73  << "Unit conversions are not supported by "
74  << typeName << " function1 types" << abort(FatalError);
75  }
76 }
77 
78 
80 {
81  os << units;
82 }
83 
84 
85 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
86 
87 Foam::Istream& Foam::operator>>
88 (
89  Istream& is,
91 )
92 {
93  is.readBegin("Function1s::unitSets");
94  is >> units.x >> units.value;
95  is.readEnd("Function1s::unitSets");
96 
97  is.check(FUNCTION_NAME);
98 
99  return is;
100 }
101 
102 
103 Foam::Ostream& Foam::operator<<
104 (
105  Ostream& os,
106  const Function1s::unitSets& units
107 )
108 {
109  os << token::BEGIN_LIST
110  << units.x << token::SPACE << units.value
111  << token::END_LIST;
112 
113  os.check(FUNCTION_NAME);
114 
115  return os;
116 }
117 
118 
119 // ************************************************************************* //
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
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
Struct containing two unitSets for use in converting both the argument and the value of a Function1.
unitSet value
Unit conversion for result 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.