CodedFvSource.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-2021 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  codeAddSupRho
51  (
52  const volScalarField& rho,
53  fvMatrix<Type>& eqn,
54  const label fieldi
55  )
56 
57  codeConstrain
58  (
59  fvMatrix<Type>& eqn,
60  const label fieldi
61  )
62  \endverbatim
63 
64  where :
65  field is the name of the field in the fields list
66  eqn is the fvMatrix
67 
68  These are in addition to the usual code entries:
69  \plaintable
70  codeInclude | include files
71  codeOptions | compiler line: added to EXE_INC (Make/options)
72  codeLibs | linker line: added to LIB_LIBS (Make/options)
73  localCode | c++; local static functions
74  \endplaintable
75 
76 Usage
77  Example usage in controlDict:
78  \verbatim
79  energySource
80  {
81  type scalarCodedSource;
82 
83  scalarCodedSourceCoeffs
84  {
85  selectionMode all;
86 
87  fields (h);
88  name sourceTime;
89 
90  codeInclude
91  #{
92  #};
93 
94  codeCorrect
95  #{
96  Pout<< "**codeCorrect**" << endl;
97  #};
98 
99  codeAddSup
100  #{
101  const Time& time = mesh().time();
102  const scalarField& V = mesh_.V();
103  scalarField& heSource = eqn.source();
104  heSource -= 0.1*sqr(time.value())*V;
105  #};
106 
107  codeConstrain
108  #{
109  Pout<< "**codeConstrain**" << endl;
110  #};
111  }
112  }
113  \endverbatim
114 
115 SourceFiles
116  codedSource.C
117 
118 \*---------------------------------------------------------------------------*/
119 
120 #ifndef fv_CodedFvSource_H
121 #define fv_CodedFvSource_H
122 
123 #include "cellSetOption.H"
124 #include "codedBase.H"
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 namespace Foam
129 {
130 namespace fv
131 {
132 
133 /*---------------------------------------------------------------------------*\
134  Class codedSource Declaration
135 \*---------------------------------------------------------------------------*/
136 
137 template<class Type>
138 class CodedSource
139 :
140  public fv::cellSetOption,
141  protected codedBase
142 {
143 protected:
144 
145  // Protected Data
146 
147  word name_;
148 
149  string codeCorrect_;
150  string codeAddSup_;
151  string codeAddSupRho_;
152  string codeConstrain_;
153 
154  //- Underlying code
156 
157 
158  // Protected Member Functions
159 
160  //- Mutable access to the loaded dynamic libraries
161  virtual dlLibraryTable& libs() const;
163  //- Description (type + name) for the output
164  virtual string description() const;
165 
166  //- Clear redirected object(s)
167  virtual void clearRedirect() const;
169  //- Get the dictionary to initialize the code context
170  virtual const dictionary& codeDict() const;
171 
172  //- Adapt the context for the current object
173  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
174 
175 
176 public:
177 
178  // Static Data Members
179 
180  //- Name of the C code template to be used
181  static constexpr const char* const codeTemplateC
182  = "codedFvOptionTemplate.C";
183 
184  //- Name of the H code template to be used
185  static constexpr const char* const codeTemplateH
186  = "codedFvOptionTemplate.H";
187 
188 
189  //- Runtime type information
190  TypeName("coded");
191 
192 
193  // Constructors
194 
195  //- Construct from components
197  (
198  const word& name,
199  const word& modelType,
200  const dictionary& dict,
201  const fvMesh& mesh
202  );
203 
204 
205  // Member Functions
206 
207  //- Dynamically compiled fvOption
208  fv::option& redirectOption() const;
209 
210 
211  // Evaluation
212 
213  //- Correct field
214  virtual void correct
215  (
217  );
218 
219  //- Explicit/implicit matrix contributions
220  virtual void addSup
221  (
222  fvMatrix<Type>& eqn,
223  const label fieldi
224  );
225 
226  //- Explicit/implicit matrix contributions to compressible equation
227  virtual void addSup
228  (
229  const volScalarField& rho,
230  fvMatrix<Type>& eqn,
231  const label fieldi
232  );
233 
234  //- Set value
235  virtual void constrain
236  (
237  fvMatrix<Type>& eqn,
238  const label fieldi
239  );
240 
241 
242  // IO
243 
244  //- Read source dictionary
245  virtual bool read(const dictionary& dict);
246 };
247 
248 
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 
251 } // End namespace fv
252 } // End namespace Foam
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 #ifdef NoRepository
257  #include "CodedFvSource.C"
258 #endif
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 #endif
263 
264 // ************************************************************************* //
dictionary dict
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition: fvOptionI.H:30
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
virtual void correct(GeometricField< Type, fvPatchField, volMesh > &)
Correct field.
virtual const dictionary & codeDict() const
Get the dictionary to initialize the code context.
Definition: CodedFvSource.C:53
virtual void clearRedirect() const
Clear redirected object(s)
Definition: CodedFvSource.C:46
Generic GeometricField class.
virtual void constrain(fvMatrix< Type > &eqn, const label fieldi)
Set value.
fv::option & redirectOption() const
Dynamically compiled fvOption.
virtual bool read(const dictionary &dict)
Read source dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:63
labelList fv(nPoints)
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
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.
virtual string description() const
Description (type + name) for the output.
Definition: CodedFvSource.C:39
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:24
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedFvSource.C:61
A table of dynamically loaded libraries.
TypeName("coded")
Runtime type information.
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
CodedSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
virtual void addSup(fvMatrix< Type > &eqn, const label fieldi)
Explicit/implicit matrix contributions.
Encapsulation of dynamic code dictionaries.
autoPtr< fv::option > redirectOptionPtr_
Underlying code.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: CodedFvSource.C:32
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Namespace for OpenFOAM.
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:123