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-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 "CodedFunction1.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("codedFunction1"));
57 
58  // Copy filtered H template
59  dynCode.addCopyFile(codeTemplateH("codedFunction1"));
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 Function1 provided by library
85  redirectFunction1Ptr_.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 Function1<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(dict)
113 {
114  redirectFunction1Ptr_ = compileNew();
115 }
116 
117 
118 
119 template<class Type>
121 :
122  Function1<Type>(cf1),
123  codedBase(cf1)
124 {
125  redirectFunction1Ptr_ = compileNew();
126 }
127 
128 
129 template<class Type>
131 {
132  return tmp<Function1<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
150 {
151  return redirectFunction1Ptr_->value(x);
152 }
153 
154 
155 template<class Type>
157 (
158  const scalar x1,
159  const scalar x2
160 ) const
161 {
163  return pTraits<Type>::zero;
164 }
165 
166 
167 template<class Type>
169 (
170  const scalarField& x1,
171  const scalarField& x2
172 ) const
173 {
175  return tmp<Field<Type>>();
176 }
177 
178 
179 template<class Type>
181 {
182  writeCode(os);
183 }
184 
185 
186 // ************************************************************************* //
Run-time selectable general function of one variable.
Definition: Function1.H:52
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalars.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
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 ~Coded()
Destructor.
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
virtual void write(Ostream &os) const
Write data to dictionary stream.
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
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Coded(const word &name, const dictionary &dict)
Construct from name and dictionary.
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
virtual Type value(const scalar x) const
Return value as a function of a scalar.
A class for managing temporary objects.
Definition: PtrList.H:53
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353