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-2025 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 #include "dynamicCode.H"
28 #include "dynamicCodeContext.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  {"code", "codeInclude"}
36 );
37 
38 template<class Type>
40 (
41  {word(), word()}
42 );
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 template<class Type>
49 (
50  dynamicCode& dynCode,
51  const dynamicCodeContext& context
52 ) const
53 {
54  dynCode.setFilterVariable("typeName", codeName());
55 
56  // Set TemplateType filter variables
57  dynCode.setFilterVariable("TemplateType", pTraits<Type>::typeName);
58 
59  // Compile filtered C template
60  dynCode.addCompileFile(codeTemplateC("codedFunction2"));
61 
62  // Copy filtered H template
63  dynCode.addCopyFile(codeTemplateH("codedFunction2"));
64 
65  // Make verbose if debugging
66  dynCode.setFilterVariable("verbose", Foam::name(bool(debug)));
67 
68  if (debug)
69  {
70  Info<<"compile " << codeName() << " sha1: " << context.sha1() << endl;
71  }
72 
73  // Define Make/options
74  dynCode.setMakeOptions
75  (
76  "EXE_INC = -g \\\n"
77  + context.options()
78  + "\n\nLIB_LIBS = \\\n"
79  + " -lOpenFOAM \\\n"
80  + context.libs()
81  );
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
87 template<class Type>
89 (
90  const word& name,
91  const unitConversions& units,
92  const dictionary& dict
93 )
94 :
95  Function2<Type>(name),
96  codedBase(name, dict, codeKeys, codeDictVars),
97  units_(units)
98 {
99  this->updateLibrary(dict);
100 
101  dictionary redirectDict(dict);
102  redirectDict.set(codeName(), codeName());
103 
104  redirectFunction2Ptr_ =
105  Function2<Type>::New(codeName(), this->units_, redirectDict);
106 }
107 
108 
109 
110 template<class Type>
112 :
113  Function2<Type>(cf2),
114  codedBase(cf2),
115  units_(cf2.units_),
116  redirectFunction2Ptr_(cf2.redirectFunction2Ptr_, false)
117 {}
118 
119 
120 template<class Type>
122 {
123  return tmp<Function2<Type>>(new Coded<Type>(*this));
124 }
125 
126 
127 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
128 
129 template<class Type>
131 {}
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
136 template<class Type>
138 (
139  const scalarField& x,
140  const scalarField& y
141 ) const
142 {
143  return
144  units_.value.toStandard
145  (
146  redirectFunction2Ptr_->value
147  (
148  units_.x.toUser(x),
149  units_.y.toUser(y)
150  )
151  );
152 }
153 
154 
155 template<class Type>
157 (
158  Ostream& os,
159  const unitConversions& units
160 ) const
161 {
162  codedBase::write(os);
163 }
164 
165 
166 // ************************************************************************* //
scalar y
Run-time selectable function of two variables.
Definition: Function2.H:98
static autoPtr< Function2< Type > > New(const word &name, const Function2s::unitConversions &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.
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
Coded(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
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 function objects and boundary conditions using dynamic code.
Definition: codedBase.H:52
const word & codeName() const
Name of the dynamically generated CodedType.
Definition: codedBase.C:374
void write(Ostream &os) const
Write the code for restart.
Definition: codedBase.C:461
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
Definition: codedBase.C:398
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 managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
const HashTable< unitConversion > & units()
Get the table of unit conversions.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict