CodedFunction2.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 "CodedFunction2.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  {"code", "codeInclude"}
34 );
35 
36 template<class Type>
38 (
39  {word::null, word::null}
40 );
41 
42 template<class Type>
44 (
45  "codedFunction2Options"
46 );
47 
48 template<class Type>
50 {
51  "codedFunction2Template.C"
52 };
53 
54 template<class Type>
56 {
57  "codedFunction2Template.H"
58 };
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
63 template<class Type>
65 (
66  const word& name,
67  const unitSets& units,
68  const dictionary& dict
69 )
70 :
71  Function2<Type>(name),
72  codedBase
73  (
74  name,
75  dict,
76  codeKeys,
77  codeDictVars,
78  codeOptions,
79  compileFiles,
80  copyFiles
81  ),
82  units_(units)
83 {
84  // Set variable substitutions
85  varSubstitutions().set
86  (
87  {
88  {"TemplateType", pTraits<Type>::typeName},
89  {"verbose", Foam::name(bool(debug))}
90  }
91  );
92 
93  this->updateLibrary(dict);
94 
95  dictionary redirectDict(dict);
96  redirectDict.set(codeName(), codeName());
97 
98  redirectFunction2Ptr_ =
99  Function2<Type>::New(codeName(), this->units_, redirectDict);
100 }
101 
102 
103 
104 template<class Type>
106 :
107  Function2<Type>(cf2),
108  codedBase(cf2),
109  units_(cf2.units_),
110  redirectFunction2Ptr_(cf2.redirectFunction2Ptr_, false)
111 {}
112 
113 
114 template<class Type>
116 {
117  return tmp<Function2<Type>>(new Coded<Type>(*this));
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
122 
123 template<class Type>
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
130 template<class Type>
132 (
133  const scalarField& x,
134  const scalarField& y
135 ) const
136 {
137  return
138  units_.value.toStandard
139  (
140  redirectFunction2Ptr_->value
141  (
142  units_.x.toUser(tmp<scalarField>(x)),
143  units_.y.toUser(tmp<scalarField>(y))
144  )
145  );
146 }
147 
148 
149 template<class Type>
151 (
152  Ostream& os,
153  const unitSets& units
154 ) const
155 {
156  codedBase::write(os);
157 }
158 
159 
160 // ************************************************************************* //
scalar y
Run-time selectable function of two variables.
Definition: Function2.H:62
static autoPtr< Function2< Type > > New(const word &name, const Function2s::unitSets &units, const dictionary &dict)
Select from dictionary.
Definition: Function2New.C:32
Constructs a dynamically compiled function of two variables.
virtual tmp< Function2< Type > > clone() const
Construct and return a clone.
Coded(const word &name, const unitSets &units, const dictionary &dict)
Construct from name and dictionary.
virtual void write(Ostream &os, const unitSets &units) const
Write data to dictionary stream.
virtual ~Coded()
Destructor.
virtual Type value(const scalar x, const scalar y) const
Return value as a function of two scalars.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Base class for coded functionObjects, fvModels, Function1, Function2.
Definition: codedBase.H:53
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
Definition: codedBase.C:230
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & codeName() const
Return the code-name.
Definition: dynamicCode.H:226
HashTable< string > & varSubstitutions()
Definition: dynamicCode.H:252
void write(Ostream &os) const
Write the code for restart.
Definition: dynamicCode.C:744
Traits class for primitives.
Definition: pTraits.H:53
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict