CodedSource.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2016 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  scalarCodedSourceCoeffs
63  {
64  selectionMode all;
65 
66  fieldNames (h);
67  name sourceTime;
68 
69  codeInclude
70  #{
71 
72  #};
73 
74  codeCorrect
75  #{
76  Pout<< "**codeCorrect**" << endl;
77  #};
78 
79  codeAddSup
80  #{
81  const Time& time = mesh().time();
82  const scalarField& V = mesh_.V();
83  scalarField& heSource = eqn.source();
84  heSource -= 0.1*sqr(time.value())*V;
85  #};
86 
87  codeSetValue
88  #{
89  Pout<< "**codeSetValue**" << endl;
90  #};
91 
92  // Dummy entry. Make dependent on above to trigger recompilation
93  code
94  #{
95  $codeInclude
96  $codeCorrect
97  $codeAddSup
98  $codeSetValue
99  #};
100  }
101 
102  sourceTimeCoeffs
103  {
104  // Dummy entry
105  }
106  }
107  \endverbatim
108 
109 
110 SourceFiles
111  codedSource.C
112 
113 \*---------------------------------------------------------------------------*/
114 
115 #ifndef CodedSource_H
116 #define CodedSource_H
117 
118 #include "cellSetOption.H"
119 #include "codedBase.H"
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 namespace Foam
124 {
125 namespace fv
126 {
127 
128 /*---------------------------------------------------------------------------*\
129  Class codedSource Declaration
130 \*---------------------------------------------------------------------------*/
131 
132 template<class Type>
133 class CodedSource
134 :
135  public cellSetOption,
136  public codedBase
137 {
138 
139 protected:
140 
141  // Protected data
143  word name_;
145  string codeCorrect_;
146  string codeAddSup_;
147  string codeSetValue_;
148 
149  //- Underlying functionObject
151 
152 
153  // Protected Member Functions
154 
155  //- Get the loaded dynamic libraries
156  virtual dlLibraryTable& libs() const;
157 
158  //- Adapt the context for the current object
159  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
160 
161  // Return a description (type + name) for the output
162  virtual string description() const;
163 
164  // Clear any redirected objects
165  virtual void clearRedirect() const;
166 
167  // Get the dictionary to initialize the codeContext
168  virtual const dictionary& codeDict() 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 // ************************************************************************* //
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:28
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
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedSource.C:36
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:150
Generic GeometricField class.
virtual string description() const
Definition: CodedSource.C:90
virtual void constrain(fvMatrix< Type > &eqn, const label fieldi)
Set value.
Definition: CodedSource.C:204
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: CodedSourceIO.C:32
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
virtual void clearRedirect() const
Definition: CodedSource.C:97
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:71
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: CodedSource.C:83
A table of dynamically loaded libraries.
TypeName("coded")
Runtime type information.
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvOptionI.H:34
CodedSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: CodedSource.C:114
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:167
Encapsulation of dynamic code dictionaries.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:72
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
virtual const dictionary & codeDict() const
Definition: CodedSource.C:104
Namespace for OpenFOAM.
autoPtr< option > redirectFvOptionPtr_
Underlying functionObject.
Definition: CodedSource.H:149
option & redirectFvOption() const
Dynamically compiled fvOption.
Definition: CodedSource.C:130
Finite volume options abstract base class. Provides a base set of controls, e.g.: ...
Definition: fvOption.H:66