Function12.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 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 "Function12.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const word& name,
34  const unitConversions& units,
35  const dictionary& dict
36 )
37 :
38  FieldFunction2<Type, Function12<Type>>(name),
39  index_(),
40  f_()
41 {
42  static const word name1 = "value1", name2 = "value2";
43  const bool found1 = dict.found(name1), found2 = dict.found(name2);
44 
45  if (found1 && found2)
46  {
48  << "Both keywords " << name1 << " and " << name2
49  << " are undefined in dictionary " << dict.name()
50  << exit(FatalError);
51  }
52 
53  if (!found1 && !found2)
54  {
56  << "Neither keywords " << name1 << " or " << name2
57  << " are defined in dictionary " << dict.name()
58  << exit(FatalError);
59  }
60 
61  index_ = found2;
62 
63  f_ =
65  (
66  found2 ? name2 : name1,
67  {found2 ? units.y : units.x, units.value},
68  dict
69  );
70 }
71 
72 
73 template<class Type>
75 :
76  FieldFunction2<Type, Function12<Type>>(se),
77  index_(se.index_),
78  f_(se.f_, false)
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
83 
84 template<class Type>
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
91 template<class Type>
93 (
94  Ostream& os,
95  const unitConversions& units
96 ) const
97 {
98  writeEntry(os, {index_ ? units.y : units.x, units.value}, f_());
99 }
100 
101 
102 // ************************************************************************* //
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
Function2 which returns a Function1 using just one of the arguments given to the function2....
Definition: Function12.H:81
Function12(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
Definition: Function12.C:32
virtual ~Function12()
Destructor.
Definition: Function12.C:85
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
Definition: Function12.C:93
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const HashTable< unitConversion > & units()
Get the table of unit conversions.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
error FatalError
dictionary dict