All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
codedFvModel.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-2021 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::codedFvModel
26 
27 Description
28  Constructs on-the-fly fvModel source from user-supplied code
29 
30 Usage
31  Example usage in constant/fvModels:
32  \verbatim
33  energySource
34  {
35  type coded;
36 
37  selectionMode all;
38 
39  field h;
40 
41  codeInclude
42  #{
43  #};
44 
45  codeAddSup
46  #{
47  Pout<< "**codeAddSup**" << endl;
48  const Time& time = mesh().time();
49  const scalarField& V = mesh().V();
50  scalarField& heSource = eqn.source();
51  heSource -= 0.1*sqr(time.value())*V;
52  #};
53 
54  codeAddRhoSup
55  #{
56  Pout<< "**codeAddRhoSup**" << endl;
57  #};
58 
59  codeAddAlphaRhoSup
60  #{
61  Pout<< "**codeAddAlphaRhoSup**" << endl;
62  #};
63  }
64  \endverbatim
65 
66 
67 SourceFiles
68  codedFvModel.C
69 
70 \*---------------------------------------------------------------------------*/
71 
72 #ifndef codedFvModel_H
73 #define codedFvModel_H
74 
75 #include "fvModel.H"
76 #include "fvCellSet.H"
77 #include "codedBase.H"
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
81 namespace Foam
82 {
83 namespace fv
84 {
85 
86 /*---------------------------------------------------------------------------*\
87  Class codedFvModel Declaration
88 \*---------------------------------------------------------------------------*/
89 
90 class codedFvModel
91 :
92  public fvModel,
93  public codedBase
94 {
95  // Private data
96 
97  //- The set of cells the fvConstraint applies to
98  fvCellSet set_;
99 
100  //- The name of the field that this fvModel applies to
101  word fieldName_;
102 
103  //- Underlying functionObject
104  mutable autoPtr<fvModel> redirectFvModelPtr_;
105 
106 
107  // Private Member Functions
108 
109  //- Non-virtual read
110  void readCoeffs();
111 
112  //- Return the name of the field's primitive type
113  word fieldPrimitiveTypeName() const;
114 
115  //- Adapt the context for the current object
116  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
117 
118  //- Name of the dynamically generated CodedType
119  virtual const word& codeName() const;
120 
121  //- Return a description (type + name) for the output
122  virtual string description() const;
123 
124  //- Clear any redirected objects
125  virtual void clearRedirect() const;
126 
127  //- Get the dictionary to initialise the codeContext
128  virtual const dictionary& codeDict() const;
129 
130  //- Get the keywords associated with source code
131  virtual wordList codeKeys() const;
132 
133  //- Dynamically compiled fvModel
134  fvModel& redirectFvModel() const;
135 
136 
137  // Sources
138 
139  //- Add a source term to an equation
140  template<class Type>
141  void addSupType
142  (
143  fvMatrix<Type>& eqn,
144  const word& fieldName
145  ) const;
146 
147  //- Add a source term to a compressible equation
148  template<class Type>
149  void addSupType
150  (
151  const volScalarField& rho,
152  fvMatrix<Type>& eqn,
153  const word& fieldName
154  ) const;
155 
156  //- Add a source term to a phase equation
157  template<class Type>
158  void addSupType
159  (
160  const volScalarField& alpha,
161  const volScalarField& rho,
162  fvMatrix<Type>& eqn,
163  const word& fieldName
164  ) const;
165 
166 
167 public:
168 
169  //- Runtime type information
170  TypeName("coded");
171 
172 
173  // Constructors
174 
175  //- Construct from components
177  (
178  const word& name,
179  const word& modelType,
180  const dictionary& dict,
181  const fvMesh& mesh
182  );
183 
184 
185  // Member Functions
186 
187  // Checks
188 
189  //- Return the list of fields for which the fvModel adds source term
190  // to the transport equation
191  virtual wordList addSupFields() const;
192 
193 
194  // Sources
195 
196  //- Add a source term to an equation
198 
199  //- Add a source term to a compressible equation
201 
202  //- Add a source term to a phase equation
204 
205 
206  // Mesh motion
207 
208  //- Update for mesh changes
209  virtual void updateMesh(const mapPolyMesh&);
210 
211 
212  // IO
213 
214  //- Read source dictionary
215  virtual bool read(const dictionary& dict);
216 };
217 
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 } // End namespace fv
222 } // End namespace Foam
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 #endif
227 
228 // ************************************************************************* //
dictionary dict
const word & name() const
Return const access to the source name.
Definition: fvModelI.H:28
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define DEFINE_FV_MODEL_ADD_SUP(Type, nullArg)
Definition: fvModelM.H:26
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: codedFvModel.C:266
Cell-set fvConstraint abstract base class. Provides a base set of controls regarding the location whe...
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
codedFvModel(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: codedFvModel.C:228
#define DEFINE_FV_MODEL_ADD_ALPHA_RHO_SUP(Type, nullArg)
Definition: fvModelM.H:62
Finite volume model abstract base class.
Definition: fvModel.H:55
FOR_ALL_FIELD_TYPES(DEFINE_FV_MODEL_ADD_SUP)
Add a source term to an equation.
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:34
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
virtual void updateMesh(const mapPolyMesh &)
Update for mesh changes.
Definition: codedFvModel.C:260
A class for handling words, derived from string.
Definition: word.H:59
#define DEFINE_FV_MODEL_ADD_RHO_SUP(Type, nullArg)
Definition: fvModelM.H:43
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
Constructs on-the-fly fvModel source from user-supplied code.
Definition: codedFvModel.H:89
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
Encapsulation of dynamic code dictionaries.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: codedFvModel.C:245
TypeName("coded")
Runtime type information.
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.