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-2023 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 {
35  return
36  {
37  "code",
38  "codeInclude"
39  };
40 }
41 
42 
43 template<class Type>
45 (
46  dynamicCode& dynCode,
47  const dynamicCodeContext& context
48 ) const
49 {
50  dynCode.setFilterVariable("typeName", codeName());
51 
52  // Set TemplateType filter variables
53  dynCode.setFilterVariable("TemplateType", pTraits<Type>::typeName);
54 
55  // Compile filtered C template
56  dynCode.addCompileFile(codeTemplateC("codedFunction2"));
57 
58  // Copy filtered H template
59  dynCode.addCopyFile(codeTemplateH("codedFunction2"));
60 
61  // Make verbose if debugging
62  dynCode.setFilterVariable("verbose", Foam::name(bool(debug)));
63 
64  if (debug)
65  {
66  Info<<"compile " << codeName() << " sha1: " << context.sha1() << endl;
67  }
68 
69  // Define Make/options
70  dynCode.setMakeOptions
71  (
72  "EXE_INC = -g \\\n"
73  + context.options()
74  + "\n\nLIB_LIBS = \\\n"
75  + " -lOpenFOAM \\\n"
76  + context.libs()
77  );
78 }
79 
80 
81 template<class Type>
83 {
84  // Remove instantiation of Function2 provided by library
85  redirectFunction2Ptr_.clear();
86 }
87 
88 
89 template<class Type>
92 {
93  this->updateLibrary();
94 
95  dictionary redirectDict(codeDict());
96  redirectDict.set(codeName(), codeName());
97 
98  return Function2<Type>::New(codeName(), redirectDict);
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
103 
104 template<class Type>
106 (
107  const word& name,
108  const dictionary& dict
109 )
110 :
111  Function2<Type>(name),
113 {
114  redirectFunction2Ptr_ = compileNew();
115 }
116 
117 
118 
119 template<class Type>
121 :
122  Function2<Type>(cf1),
123  codedBase(cf1)
124 {
125  redirectFunction2Ptr_ = compileNew();
126 }
127 
128 
129 template<class Type>
131 {
132  return tmp<Function2<Type>>(new Coded<Type>(*this));
133 }
134 
135 
136 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
137 
138 template<class Type>
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
145 template<class Type>
147 (
148  const scalarField& x,
149  const scalarField& y
150 ) const
151 {
152  return redirectFunction2Ptr_->value(x, y);
153 }
154 
155 
156 template<class Type>
158 {
159  writeCode(os);
160 }
161 
162 
163 // ************************************************************************* //
scalar y
Run-time selectable function of two variables.
Definition: Function2.H:64
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
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.
Coded(const word &name, const dictionary &dict)
Construct from name and dictionary.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:54
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
dictionary dict