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-2018 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  // Dummy entry. Make dependent on above to trigger recompilation
94  code
95  #{
96  $codeInclude
97  $codeCorrect
98  $codeAddSup
99  $codeSetValue
100  #};
101  }
102 
103  sourceTimeCoeffs
104  {
105  $scalarCodedSourceCoeffs;
106  }
107  }
108  \endverbatim
109 
110 
111 SourceFiles
112  codedSource.C
113 
114 \*---------------------------------------------------------------------------*/
115 
116 #ifndef CodedSource_H
117 #define CodedSource_H
118 
119 #include "cellSetOption.H"
120 #include "codedBase.H"
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 
124 namespace Foam
125 {
126 namespace fv
127 {
128 
129 /*---------------------------------------------------------------------------*\
130  Class codedSource Declaration
131 \*---------------------------------------------------------------------------*/
132 
133 template<class Type>
134 class CodedSource
135 :
136  public cellSetOption,
137  public codedBase
138 {
139 
140 protected:
141 
142  // Protected data
144  word name_;
146  string codeCorrect_;
147  string codeAddSup_;
148  string codeSetValue_;
149 
150  //- Underlying functionObject
152 
153 
154  // Protected Member Functions
155 
156  //- Get the loaded dynamic libraries
157  virtual dlLibraryTable& libs() const;
158 
159  //- Adapt the context for the current object
160  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
161 
162  // Return a description (type + name) for the output
163  virtual string description() const;
164 
165  // Clear any redirected objects
166  virtual void clearRedirect() const;
167 
168  // Get the dictionary to initialize the codeContext
169  virtual const dictionary& codeDict() const;
170 
171 
172 public:
173 
174  //- Runtime type information
175  TypeName("coded");
176 
177 
178  // Constructors
179 
180  //- Construct from components
182  (
183  const word& name,
184  const word& modelType,
185  const dictionary& dict,
186  const fvMesh& mesh
187  );
188 
189 
190  // Member Functions
191 
192  //- Dynamically compiled fvOption
193  option& redirectFvOption() const;
194 
195  // Evaluation
196 
197  //- Correct field
198  virtual void correct
199  (
201  );
202 
203  //- Explicit and implicit matrix contributions
204  virtual void addSup
205  (
206  fvMatrix<Type>& eqn,
207  const label fieldi
208  );
209 
210  //- Explicit and implicit matrix contributions
211  // to compressible equation
212  virtual void addSup
213  (
214  const volScalarField& rho,
215  fvMatrix<Type>& eqn,
216  const label fieldi
217  );
218 
219  //- Set value
220  virtual void constrain
221  (
222  fvMatrix<Type>& eqn,
223  const label fieldi
224  );
225 
226 
227  // IO
228 
229  //- Read source dictionary
230  virtual bool read(const dictionary& dict);
231 };
232 
233 
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 
236 } // End namespace fv
237 } // End namespace Foam
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 #ifdef NoRepository
242  #include "CodedSource.C"
243  #include "CodedSourceIO.C"
244 #endif
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #endif
249 
250 // ************************************************************************* //
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:133
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void correct(GeometricField< Type, fvPatchField, volMesh > &)
Correct field.
Definition: CodedSource.C:151
virtual const dictionary & codeDict() const
Definition: CodedSource.C:105
virtual void clearRedirect() const
Definition: CodedSource.C:98
Generic GeometricField class.
virtual void constrain(fvMatrix< Type > &eqn, const label fieldi)
Set value.
Definition: CodedSource.C:205
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvOptionI.H:34
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: CodedSourceIO.C:32
option & redirectFvOption() const
Dynamically compiled fvOption.
Definition: CodedSource.C:131
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
Definition: CodedSource.C:91
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedSource.C:36
A table of dynamically loaded libraries.
TypeName("coded")
Runtime type information.
CodedSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: CodedSource.C:115
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:168
Encapsulation of dynamic code dictionaries.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: CodedSource.C:84
Cell-set options abtract 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
Namespace for OpenFOAM.
autoPtr< option > redirectFvOptionPtr_
Underlying functionObject.
Definition: CodedSource.H:150
Finite volume options abstract base class. Provides a base set of controls, e.g.: ...
Definition: fvOption.H:66