All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2021 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  // Debugging: make verbose
62  if (debug)
63  {
64  dynCode.setFilterVariable("verbose", "true");
65  Info<<"compile " << codeName() << " sha1: "
66  << 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 :
112  codedBase(name, dict)
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 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual ~Coded()
Destructor.
virtual void write(Ostream &os) const
Write data to dictionary stream.
virtual tmp< Function2< Type > > clone() const
Construct and return a clone.
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
A class for handling words, derived from string.
Definition: word.H:59
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:53
virtual void writeCode(Ostream &os) const
Definition: codedBase.C:409
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
Constructs a dynamically compiled function of two variables.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
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.
Run-time selectable function of two variables.
Definition: Function2.H:52
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
A class for managing temporary objects.
Definition: PtrList.H:53