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-2026 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 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  {"code", "codeInclude"}
34 );
35 
36 template<class Type>
38 (
39  {word::null, word::null}
40 );
41 
42 template<class Type>
44 (
45  "codedFunction1Options"
46 );
47 
48 template<class Type>
50 {
51  "codedFunction1Template.C"
52 };
53 
54 template<class Type>
56 {
57  "codedFunction1Template.H"
58 };
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
63 template<class Type>
65 (
66  const word& name,
67  const Function1s::unitSets& units,
68  const dictionary& dict
69 )
70 :
71  Function1<Type>(name),
72  codedBase
73  (
74  dict.lookup("name"),
75  dict,
76  codeKeys,
77  codeDictVars,
78  codeOptions,
79  compileFiles,
80  copyFiles
81  ),
82  units_(units)
83 {
84  // Set variable substitutions
85  varSubstitutions().set
86  (
87  {
88  {"TemplateType", pTraits<Type>::typeName},
89  {"verbose", Foam::name(bool(debug))}
90  }
91  );
92 
93  this->updateLibrary(dict);
94 
95  dictionary redirectDict(dict);
96  redirectDict.set(codeName(), codeName());
97 
98  redirectFunction1Ptr_ =
100 }
101 
102 
103 template<class Type>
105 :
106  Function1<Type>(cf1),
107  codedBase(cf1),
108  units_(cf1.units_),
109  redirectFunction1Ptr_(cf1.redirectFunction1Ptr_, false)
110 {}
111 
112 
113 template<class Type>
115 {
116  return tmp<Function1<Type>>(new Coded<Type>(*this));
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
121 
122 template<class Type>
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
129 template<class Type>
131 (
132  const scalarField& x
133 ) const
134 {
135  return
136  units_.value.toStandard
137  (
138  redirectFunction1Ptr_->value
139  (
140  units_.x.toUser(tmp<scalarField>(x))
141  )
142  );
143 }
144 
145 
146 template<class Type>
148 (
149  const scalar x1,
150  const scalar x2
151 ) const
152 {
154  return pTraits<Type>::zero;
155 }
156 
157 
158 template<class Type>
160 (
161  const scalarField& x1,
162  const scalarField& x2
163 ) const
164 {
166  return tmp<Field<Type>>();
167 }
168 
169 
170 template<class Type>
172 (
173  Ostream& os,
174  const unitSets& units
175 ) const
176 {
177  codedBase::write(os);
178 }
179 
180 
181 // ************************************************************************* //
Run-time selectable general function of one variable.
Definition: Function1.H:62
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitSets &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
Constructs a dynamically compiled Function1.
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalars.
virtual void write(Ostream &os, const unitSets &units) const
Write data to dictionary stream.
Coded(const word &name, const Function1s::unitSets &units, const dictionary &dict)
Construct from name and dictionary.
virtual ~Coded()
Destructor.
virtual Type value(const scalar x) const
Return value as a function of a scalar.
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Base class for coded functionObjects, fvModels, Function1, Function2.
Definition: codedBase.H:53
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
Definition: codedBase.C:230
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & codeName() const
Return the code-name.
Definition: dynamicCode.H:226
HashTable< string > & varSubstitutions()
Definition: dynamicCode.H:252
void write(Ostream &os) const
Write the code for restart.
Definition: dynamicCode.C:744
Traits class for primitives.
Definition: pTraits.H:53
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
const unitSet any
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict
Struct containing two unitSets for use in converting both the argument and the value of a Function1.