All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CodedFunction1.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 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 "CodedFunction1.H"
27 #include "dynamicCode.H"
28 #include "dynamicCodeContext.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  dynamicCode& dynCode,
36  const dynamicCodeContext& context
37 ) const
38 {
39  dynCode.setFilterVariable("typeName", codeName());
40 
41  // Set TemplateType filter variables
42  dynCode.setFilterVariable("TemplateType", pTraits<Type>::typeName);
43 
44  // Compile filtered C template
45  dynCode.addCompileFile(codeTemplateC);
46 
47  // Copy filtered H template
48  dynCode.addCopyFile(codeTemplateH);
49 
50  // Debugging: make verbose
51  if (debug)
52  {
53  dynCode.setFilterVariable("verbose", "true");
54  Info<<"compile " << codeName() << " sha1: "
55  << context.sha1() << endl;
56  }
57 
58  // Define Make/options
59  dynCode.setMakeOptions
60  (
61  "EXE_INC = -g \\\n"
62  + context.options()
63  + "\n\nLIB_LIBS = \\\n"
64  + " -lOpenFOAM \\\n"
65  + context.libs()
66  );
67 }
68 
69 
70 template<class Type>
72 {
73  // Remove instantiation of Function1 provided by library
74  redirectFunction1Ptr_.clear();
75 }
76 
77 
78 template<class Type>
81 {
82  this->updateLibrary();
83 
84  dictionary redirectDict(codeDict());
85  redirectDict.set(codeName(), codeName());
86 
87  return Function1<Type>::New(codeName(), redirectDict);
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
93 template<class Type>
95 (
96  const word& entryName,
97  const dictionary& dict
98 )
99 :
100  Function1<Type>(entryName),
101  CodedBase<coded>(dict)
102 {
103  redirectFunction1Ptr_ = compileNew();
104 }
105 
106 
107 
108 template<class Type>
110 :
111  Function1<Type>(cf1),
112  CodedBase<coded>(cf1)
113 {
114  redirectFunction1Ptr_ = compileNew();
115 }
116 
117 
118 template<class Type>
120 {
121  return tmp<Function1<Type>>(new Coded<Type>(*this));
122 }
123 
124 
125 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
126 
127 template<class Type>
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
134 template<class Type>
136 (
137  const scalarField& x
138 ) const
139 {
140  return redirectFunction1Ptr_->value(x);
141 }
142 
143 
144 template<class Type>
146 (
147  const scalar x1,
148  const scalar x2
149 ) const
150 {
152  return pTraits<Type>::zero;
153 }
154 
155 
156 template<class Type>
158 (
159  const scalarField& x1,
160  const scalarField& x2
161 ) const
162 {
164  return tmp<Field<Type>>();
165 }
166 
167 
168 template<class Type>
170 {
172  os << token::END_STATEMENT << nl;
173  writeCode(os);
174 }
175 
176 
177 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:52
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
Constructs a dynamically compiled Function1.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Traits class for primitives.
Definition: pTraits.H:50
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two values.
virtual ~Coded()
Destructor.
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:98
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
virtual void writeData(Ostream &os) const
Write in dictionary format.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
messageStream Info
Coded(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
void writeCode(Ostream &os) const
Definition: CodedBase.C:100
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
virtual Type value(const scalar x) const
Return value.
A class for managing temporary objects.
Definition: PtrList.H:53
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366