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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::fv::codedSource
29 
30 Group
31  grpFvOptionsSources
32 
33 Description
34  Constructs on-the-fly fvOption source
35 
36  The hook functions take the following arguments:
37 
38  \verbatim
39  codeCorrect
40  (
41  GeometricField<Type, fvPatchField, volMesh>& field
42  )
43 
44  codeAddSup
45  (
46  fvMatrix<Type}>& eqn,
47  const label fieldi
48  )
49 
50  codeConstrain
51  (
52  fvMatrix<Type}>& eqn,
53  const label fieldi
54  )
55  \endverbatim
56 
57  where :
58  field is the name of the field in the fields list
59  eqn is the fvMatrix
60 
61 Usage
62  Example usage in controlDict:
63  \verbatim
64  energySource
65  {
66  type scalarCodedSource;
67 
68  scalarCodedSourceCoeffs
69  {
70  selectionMode all;
71 
72  fields (h);
73  name sourceTime;
74 
75  codeInclude
76  #{
77  #};
78 
79  codeCorrect
80  #{
81  Pout<< "**codeCorrect**" << endl;
82  #};
83 
84  codeAddSup
85  #{
86  const Time& time = mesh().time();
87  const scalarField& V = mesh_.V();
88  scalarField& heSource = eqn.source();
89  heSource -= 0.1*sqr(time.value())*V;
90  #};
91 
92  codeContrain
93  #{
94  Pout<< "**codeConstrain**" << endl;
95  #};
96  }
97  }
98  \endverbatim
99 
100 
101 SourceFiles
102  codedSource.C
103 
104 \*---------------------------------------------------------------------------*/
105 
106 #ifndef CodedSource_H
107 #define CodedSource_H
108 
109 #include "cellSetOption.H"
110 #include "codedBase.H"
111 
112 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
113 
114 namespace Foam
115 {
116 namespace fv
117 {
118 
119 /*---------------------------------------------------------------------------*\
120  Class codedSource Declaration
121 \*---------------------------------------------------------------------------*/
122 
123 template<class Type>
124 class CodedSource
125 :
126  public cellSetOption,
127  protected codedBase
128 {
129 
130 protected:
131 
132  // Protected Data
133 
134  word name_;
135 
136  string codeCorrect_;
137  string codeAddSup_;
138  string codeConstrain_;
139 
140  //- Underlying functionObject
142 
143 
144  // Protected Member Functions
145 
146  //- Get the loaded dynamic libraries
147  virtual dlLibraryTable& libs() const;
148 
149  //- Adapt the context for the current object
150  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
151 
152  //- Return a description (type + name) for the output
153  virtual string description() const;
154 
155  //- Clear any redirected objects
156  virtual void clearRedirect() const;
157 
158  //- Get the dictionary to initialize the codeContext
159  virtual const dictionary& codeDict() const;
160 
161 
162 public:
163 
164  //- Runtime type information
165  TypeName("coded");
166 
167 
168  // Constructors
169 
170  //- Construct from components
172  (
173  const word& name,
174  const word& modelType,
175  const dictionary& dict,
176  const fvMesh& mesh
177  );
178 
179 
180  // Member Functions
181 
182  //- Dynamically compiled fvOption
183  option& redirectFvOption() const;
184 
185 
186  // Evaluation
187 
188  //- Correct field
189  virtual void correct
190  (
192  );
193 
194  //- Explicit/implicit matrix contributions
195  virtual void addSup
196  (
197  fvMatrix<Type>& eqn,
198  const label fieldi
199  );
200 
201  //- Explicit/implicit matrix contributions to compressible equation
202  virtual void addSup
203  (
204  const volScalarField& rho,
205  fvMatrix<Type>& eqn,
206  const label fieldi
207  );
208 
209  //- Set value
210  virtual void constrain
211  (
212  fvMatrix<Type>& eqn,
213  const label fieldi
214  );
215 
216 
217  // IO
218 
219  //- Read source dictionary
220  virtual bool read(const dictionary& dict);
221 };
222 
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 } // End namespace fv
227 } // End namespace Foam
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #ifdef NoRepository
232  #include "CodedSource.C"
233  #include "CodedSourceIO.C"
234 #endif
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 #endif
239 
240 // ************************************************************************* //
Foam::fv::CodedSource::libs
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: CodedSource.C:88
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
CodedSource.C
Foam::fv::cellSetOption
Cell-set options abstract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:72
Foam::fv::CodedSource::name_
word name_
Definition: CodedSource.H:133
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:59
Foam::fv::CodedSource::redirectFvOption
option & redirectFvOption() const
Dynamically compiled fvOption.
Definition: CodedSource.C:135
Foam::fv::option::name
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:30
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:53
Foam::codedBase
Base class for function objects and boundary conditions using dynamic code that provides methods for ...
Definition: codedBase.H:66
Foam::fv::CodedSource::clearRedirect
virtual void clearRedirect() const
Clear any redirected objects.
Definition: CodedSource.C:102
rho
rho
Definition: readInitialConditions.H:88
cellSetOption.H
Foam::fv::CodedSource::correct
virtual void correct(GeometricField< Type, fvPatchField, volMesh > &)
Correct field.
Definition: CodedSource.C:156
Foam::fv::option
Finite volume options abstract base class. Provides a base set of controls, e.g.:
Definition: fvOption.H:69
Foam::fv::CodedSource::TypeName
TypeName("coded")
Runtime type information.
Foam::fv::CodedSource::codeConstrain_
string codeConstrain_
Definition: CodedSource.H:137
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::fv::CodedSource::codeAddSup_
string codeAddSup_
Definition: CodedSource.H:136
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fv::CodedSource::CodedSource
CodedSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: CodedSource.C:119
Foam::fv::CodedSource::redirectFvOptionPtr_
autoPtr< option > redirectFvOptionPtr_
Underlying functionObject.
Definition: CodedSource.H:140
Foam::fv::CodedSource::codeDict
virtual const dictionary & codeDict() const
Get the dictionary to initialize the codeContext.
Definition: CodedSource.C:109
fv
labelList fv(nPoints)
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::fv::CodedSource::description
virtual string description() const
Return a description (type + name) for the output.
Definition: CodedSource.C:95
Foam::fv::CodedSource::constrain
virtual void constrain(fvMatrix< Type > &eqn, const label fieldi)
Set value.
Definition: CodedSource.C:204
CodedSourceIO.C
Foam::fv::option::mesh
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvOptionI.H:36
Foam::fv::CodedSource::addSup
virtual void addSup(fvMatrix< Type > &eqn, const label fieldi)
Explicit/implicit matrix contributions.
Definition: CodedSource.C:171
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
codedBase.H
Foam::fv::CodedSource::codeCorrect_
string codeCorrect_
Definition: CodedSource.H:135
Foam::fv::CodedSource
Definition: CodedSource.H:123
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::fv::CodedSource::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: CodedSourceIO.C:34
Foam::fv::CodedSource::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedSource.C:39