Coded_DimensionedFieldFunction.H
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) 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 Class
25  Foam::DimensionedFieldFunctions::Coded
26 
27 Description
28  Coded internal and patch field initialisation, evaluation and update
29  with dimension checking.
30 
31  Code can be provided for field initialisation in the \c evaluate function or
32  field update (time dependent) in the \c update function which can call the
33  \c evaluate function if appropriate. The \c evaluate function provides
34  direct access to the point, cell or face centres in the \c C field and also
35  time \c t and the \c field is set by assignment. If the \c update
36  function changes the field \c updated should be set true.
37 
38 Usage
39  To initialise the swirl velocity and set the \c inlet value using
40  Foam::functionalFixedValue in the \c incompressibleFluid/pipeCyclic case:
41  \verbatim
42  internalField
43  {
44  type coded;
45 
46  evaluate
47  #{
48  field = velocity(1, 0, 0) + (C ^ rate(2, 0, 0));
49  #};
50  }
51 
52  boundaryField
53  {
54  inlet
55  {
56  type functionalFixedValue;
57 
58  value
59  {
60  $internalField;
61  }
62  }
63  .
64  .
65  .
66  \endverbatim
67 
68 SourceFiles
69  Coded_DimensionedFieldFunction.C
70 
71 \*---------------------------------------------------------------------------*/
72 
73 #ifndef Coded_DimensionedFieldFunction_H
74 #define Coded_DimensionedFieldFunction_H
75 
77 #include "codedBase.H"
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
81 namespace Foam
82 {
83 namespace DimensionedFieldFunctions
84 {
85 
86 /*---------------------------------------------------------------------------*\
87  Class Coded Declaration
88 \*---------------------------------------------------------------------------*/
89 
90 template<class DimensionedFieldType>
91 class Coded
92 :
93  public DimensionedFieldFunction<DimensionedFieldType>,
94  public codedBase
95 {
96  // Private Data
97 
98  //- Keywords associated with source code
99  static const wordList codeKeys;
100 
101  //- Name of the dictionary variables in the source code
102  static const wordList codeDictVars;
103 
104  // Name of the code options template file
105  static const word codeOptions;
106 
107  // Names of the source files to compile
108  static const wordList compileFiles;
109 
110  // Names of the source files to copy (header files)
111  static const wordList copyFiles;
112 
113  //- The dynamically generated DimensionedFieldFunction pointer
115  redirectFunctionPtr_;
116 
117 
118 public:
119 
120  //- Runtime type information
121  TypeName("coded");
122 
123 
124  // Constructors
125 
126  //- Construct with dictionary to initialise given field
127  Coded
128  (
129  const dictionary& dict,
130  DimensionedFieldType& field
131  );
132 
133  //- Construct a copy for the given field
134  Coded(const Coded& dff, DimensionedFieldType& field);
135 
136  //- Construct and return a clone for the specified field
138  clone(DimensionedFieldType& field) const;
139 
140 
141  //- Destructor
142  virtual ~Coded()
143  {}
144 
145 
146  // Member Functions
147 
148  //- Evaluate the function and set the field
149  virtual void evaluate();
150 
151  //- Update the field if the function has changed and return true
152  // otherwise return false
153  virtual bool update();
154 
155  //- Write data to dictionary stream
156  virtual void write(Ostream& os) const;
157 };
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace DimensionedFieldFunctions
163 } // End namespace Foam
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 #ifdef NoRepository
169 #endif
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 #endif
174 
175 // ************************************************************************* //
Base class for run-time selectable internal and patch field initialisation evaluation and update with...
virtual autoPtr< DimensionedFieldFunction< DimensionedFieldType > > clone() const
Construct and return a clone for the specified field.
Coded internal and patch field initialisation, evaluation and update with dimension checking.
virtual void evaluate()
Evaluate the function and set the field.
TypeName("coded")
Runtime type information.
virtual void write(Ostream &os) const
Write data to dictionary stream.
Coded(const dictionary &dict, DimensionedFieldType &field)
Construct with dictionary to initialise given field.
virtual bool update()
Update the field if the function has changed and return true.
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 coded functionObjects, fvModels, Function1, Function2.
Definition: codedBase.H:53
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
dictionary dict