CodedSource.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) 2012-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 Class
25  Foam::fv::CodedSource
26 
27 Description
28  Constructs on-the-fly fvOption source
29 
30  The hook functions take the following arguments:
31 
32  codeCorrect
33  (
34  GeometricField<Type, fvPatchField, volMesh>& field
35  )
36 
37  codeAddSup
38  (
39  fvMatrix<Type}>& eqn,
40  const label fieldi
41  )
42 
43  constrain
44  (
45  fvMatrix<Type}>& eqn,
46  const label fieldi
47  )
48 
49  where :
50  field is the field in fieldNames
51  eqn is the fvMatrix
52 
53 Usage
54  Example usage in controlDict:
55  \verbatim
56  energySource
57  {
58  type scalarCodedSource;
59 
60  active yes;
61 
62  name sourceTime;
63 
64  scalarCodedSourceCoeffs
65  {
66  selectionMode all;
67 
68  fields (h);
69 
70  codeInclude
71  #{
72 
73  #};
74 
75  codeCorrect
76  #{
77  Pout<< "**codeCorrect**" << endl;
78  #};
79 
80  codeAddSup
81  #{
82  const Time& time = mesh().time();
83  const scalarField& V = mesh_.V();
84  scalarField& heSource = eqn.source();
85  heSource -= 0.1*sqr(time.value())*V;
86  #};
87 
88  codeSetValue
89  #{
90  Pout<< "**codeSetValue**" << endl;
91  #};
92  }
93 
94  sourceTimeCoeffs
95  {
96  $scalarCodedSourceCoeffs;
97  }
98  }
99  \endverbatim
100 
101 
102 SourceFiles
103  codedSource.C
104 
105 \*---------------------------------------------------------------------------*/
106 
107 #ifndef CodedSource_H
108 #define CodedSource_H
109 
110 #include "cellSetOption.H"
111 #include "codedBase.H"
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 namespace Foam
116 {
117 namespace fv
118 {
119 
120 /*---------------------------------------------------------------------------*\
121  Class codedSource Declaration
122 \*---------------------------------------------------------------------------*/
123 
124 template<class Type>
125 class CodedSource
126 :
127  public cellSetOption,
128  public codedBase
129 {
130 protected:
131 
132  // Protected static data
133 
134  //- The keywords associated with source code
135  static const wordList codeKeys_;
136 
137 
138  // Protected data
139 
140  //- The name
141  word name_;
142 
143  //- Underlying functionObject
145 
146 
147  // Protected Member Functions
148 
149  //- Adapt the context for the current object
150  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
151 
152  //- Name of the dynamically generated CodedType
153  virtual const word& codeName() const
154  {
155  return name_;
156  }
157 
158  //- Return a description (type + name) for the output
159  virtual string description() const;
160 
161  //- Clear any redirected objects
162  virtual void clearRedirect() const;
163 
164  //- Get the dictionary to initialize the codeContext
165  virtual const dictionary& codeDict() const;
166 
167  //- Get the keywords associated with source code
168  virtual const wordList& codeKeys() const;
169 
170 
171 public:
172 
173  //- Runtime type information
174  TypeName("coded");
175 
176 
177  // Constructors
178 
179  //- Construct from components
181  (
182  const word& name,
183  const word& modelType,
184  const dictionary& dict,
185  const fvMesh& mesh
186  );
187 
188 
189  // Member Functions
190 
191  //- Dynamically compiled fvOption
192  option& redirectFvOption() const;
193 
194  // Evaluation
195 
196  //- Correct field
197  virtual void correct
198  (
200  );
201 
202  //- Explicit and implicit matrix contributions
203  virtual void addSup
204  (
205  fvMatrix<Type>& eqn,
206  const label fieldi
207  );
208 
209  //- Explicit and implicit matrix contributions
210  // to compressible equation
211  virtual void addSup
212  (
213  const volScalarField& rho,
214  fvMatrix<Type>& eqn,
215  const label fieldi
216  );
217 
218  //- Set value
219  virtual void constrain
220  (
221  fvMatrix<Type>& eqn,
222  const label fieldi
223  );
224 
225 
226  // IO
227 
228  //- Read source dictionary
229  virtual bool read(const dictionary& dict);
230 };
231 
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 } // End namespace fv
236 } // End namespace Foam
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 #ifdef NoRepository
241  #include "CodedSource.C"
242  #include "CodedSourceIO.C"
243 #endif
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #endif
248 
249 // ************************************************************************* //
static const wordList codeKeys_
The keywords associated with source code.
Definition: CodedSource.H:134
dictionary dict
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Constructs on-the-fly fvOption source.
Definition: CodedSource.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
virtual void correct(GeometricField< Type, fvPatchField, volMesh > &)
Correct field.
Definition: CodedSource.C:159
virtual const dictionary & codeDict() const
Get the dictionary to initialize the codeContext.
Definition: CodedSource.C:106
virtual void clearRedirect() const
Clear any redirected objects.
Definition: CodedSource.C:99
Generic GeometricField class.
virtual void constrain(fvMatrix< Type > &eqn, const label fieldi)
Set value.
Definition: CodedSource.C:213
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvOptionI.H:34
virtual const wordList & codeKeys() const
Get the keywords associated with source code.
Definition: CodedSource.C:113
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: CodedSourceIO.C:32
option & redirectFvOption() const
Dynamically compiled fvOption.
Definition: CodedSource.C:139
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:53
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:72
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:28
virtual string description() const
Return a description (type + name) for the output.
Definition: CodedSource.C:92
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedSource.C:49
TypeName("coded")
Runtime type information.
word name_
The name.
Definition: CodedSource.H:140
CodedSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: CodedSource.C:123
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
virtual void addSup(fvMatrix< Type > &eqn, const label fieldi)
Explicit and implicit matrix contributions.
Definition: CodedSource.C:176
Encapsulation of dynamic code dictionaries.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Cell-set options abstract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:69
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 const word & codeName() const
Name of the dynamically generated CodedType.
Definition: CodedSource.H:152
Namespace for OpenFOAM.
autoPtr< option > redirectFvOptionPtr_
Underlying functionObject.
Definition: CodedSource.H:143
Finite volume options abstract base class. Provides a base set of controls, e.g.: ...
Definition: fvOption.H:66