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-2015 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  \heading Source usage
54 
55  Example usage in controlDict:
56  \verbatim
57  energySource
58  {
59  type scalarCodedSource;
60 
61  active yes;
62 
63  scalarCodedSourceCoeffs
64  {
65  selectionMode all;
66 
67  fieldNames (h);
68  redirectType sourceTime;
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  // Dummy entry
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
143 
145 
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 // ************************************************************************* //
Foam::fv::CodedSource::libs
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: CodedSource.C:83
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:49
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
CodedSource.C
Foam::fv::cellSetOption
Cell-set options abtract base class. Provides a base set of controls, e.g.
Definition: cellSetOption.H:71
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
Foam::fv::CodedSource::redirectFvOption
option & redirectFvOption() const
Dynamically compiled fvOption.
Definition: CodedSource.C:130
Foam::fv::option::name
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:28
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:49
Foam::codedBase
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:53
Foam::fv::CodedSource::clearRedirect
virtual void clearRedirect() const
Definition: CodedSource.C:97
cellSetOption.H
Foam::fv::CodedSource::constrain
virtual void constrain(fvMatrix< Type > &eqn, const label fieldI)
Set value.
Definition: CodedSource.C:204
Foam::fv::CodedSource::correct
virtual void correct(GeometricField< Type, fvPatchField, volMesh > &)
Correct field.
Definition: CodedSource.C:150
Foam::label
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
Foam::fv::option
Finite volume options abtract base class. Provides a base set of controls, e.g.
Definition: fvOption.H:65
Foam::fv::CodedSource::TypeName
TypeName("coded")
Runtime type information.
Foam::fv::CodedSource::redirectType_
word redirectType_
Definition: CodedSource.H:143
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::fv::CodedSource::codeAddSup_
string codeAddSup_
Definition: CodedSource.H:146
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::fv::CodedSource::CodedSource
CodedSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: CodedSource.C:114
Foam::fv::CodedSource::redirectFvOptionPtr_
autoPtr< option > redirectFvOptionPtr_
Underlying functionObject.
Definition: CodedSource.H:150
Foam::fv::CodedSource::codeDict
virtual const dictionary & codeDict() const
Definition: CodedSource.C:104
rho
rho
Definition: pEqn.H:3
fv
labelList fv(nPoints)
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::fv::CodedSource::description
virtual string description() const
Definition: CodedSource.C:90
CodedSourceIO.C
Foam::fv::option::mesh
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvOptionI.H:34
Foam::fvMatrix< Type >
codedBase.H
Foam::fv::CodedSource::codeSetValue_
string codeSetValue_
Definition: CodedSource.H:147
Foam::fv::CodedSource::codeCorrect_
string codeCorrect_
Definition: CodedSource.H:145
Foam::fv::CodedSource
Definition: CodedSource.H:133
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::fv::CodedSource::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: CodedSourceIO.C:32
Foam::fv::CodedSource::addSup
virtual void addSup(fvMatrix< Type > &eqn, const label fieldI)
Explicit and implicit matrix contributions.
Definition: CodedSource.C:167
Foam::fv::CodedSource::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedSource.C:36