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-2026 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  cellZone 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 "codedBase.H"
77 
78 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
79 
80 namespace Foam
81 {
82 namespace fv
83 {
84 
85 /*---------------------------------------------------------------------------*\
86  Class codedFvModel Declaration
87 \*---------------------------------------------------------------------------*/
88 
89 class codedFvModel
90 :
91  public fvModel,
92  public codedBase
93 {
94  // Private data
95 
96  //- Keywords associated with source code
97  static const wordList codeKeys;
98 
99  //- Name of the dictionary variables in the source code
100  static const wordList codeDictVars;
101 
102  // Name of the code options template file
103  static const word codeOptions;
104 
105  // Names of the source files to compile
106  static const wordList compileFiles;
107 
108  // Names of the source files to copy (header files)
109  static const wordList copyFiles;
110 
111  //- The name of the field that this fvModel applies to
112  word fieldName_;
113 
114  //- Cached coefficients dictionary
115  // Required for the delayed
116  dictionary coeffsDict_;
117 
118  //- Underlying functionObject
119  mutable autoPtr<fvModel> redirectFvModelPtr_;
120 
121 
122  // Private Member Functions
123 
124  //- Non-virtual read
125  void readCoeffs(const dictionary& dict);
126 
127  //- Return the name of the field's primitive type
128  word fieldPrimitiveTypeName() const;
129 
130  //- Compile, link and load the coded fvModel if not already loaded
131  // and return it
132  fvModel& redirectFvModel() const;
133 
134 
135  // Sources
136 
137  //- Add a source term to an equation
138  template<class Type>
139  void addSupType
140  (
141  const VolField<Type>& field,
142  fvMatrix<Type>& eqn
143  ) const;
144 
145  //- Add a source term to a compressible equation
146  template<class Type>
147  void addSupType
148  (
149  const volScalarField& rho,
150  const VolField<Type>& field,
151  fvMatrix<Type>& eqn
152  ) const;
153 
154  //- Add a source term to a phase equation
155  template<class Type>
156  void addSupType
157  (
158  const volScalarField& alpha,
159  const volScalarField& rho,
160  const VolField<Type>& field,
161  fvMatrix<Type>& eqn
162  ) const;
163 
164 
165 public:
166 
167  //- Runtime type information
168  TypeName("coded");
169 
170 
171  // Constructors
172 
173  //- Construct from components
175  (
176  const word& name,
177  const word& modelType,
178  const fvMesh& mesh,
179  const dictionary& dict
180  );
181 
182 
183  // Member Functions
184 
185  // Checks
186 
187  //- Return the list of fields for which the fvModel adds source term
188  // to the transport equation
189  virtual wordList addSupFields() const;
190 
191 
192  // Sources
193 
194  //- Add a source term to an equation
196 
197  //- Add a source term to a compressible equation
199 
200  //- Add a source term to a phase equation
202 
203 
204  // Mesh changes
205 
206  //- Update for mesh motion
207  virtual bool movePoints();
208 
209  //- Update topology using the given map
210  virtual void topoChange(const polyTopoChangeMap&);
211 
212  //- Update from another mesh using the given map
213  virtual void mapMesh(const polyMeshMap&);
214 
215  //- Redistribute or update using the given distribution map
216  virtual void distribute(const polyDistributionMap&);
217 
218 
219  // IO
220 
221  //- Read source dictionary
222  virtual bool read(const dictionary& dict);
223 };
224 
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
228 } // End namespace fv
229 } // End namespace Foam
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 #endif
234 
235 // ************************************************************************* //
Generic GeometricField class.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Base class for coded functionObjects, fvModels, Function1, Function2.
Definition: codedBase.H:53
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
Finite volume model abstract base class.
Definition: fvModel.H:60
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:69
const word & name() const
Return const access to the source name.
Definition: fvModelI.H:57
Constructs on-the-fly fvModel source from user-supplied code.
Definition: codedFvModel.H:92
codedFvModel(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from components.
Definition: codedFvModel.C:193
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: codedFvModel.C:222
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: codedFvModel.C:247
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: codedFvModel.C:259
TypeName("coded")
Runtime type information.
virtual bool movePoints()
Add a source term to an equation.
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: codedFvModel.C:265
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: codedFvModel.C:253
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:63
#define DEFINE_FV_MODEL_ADD_ALPHA_RHO_FIELD_SUP(Type, nullArg)
Definition: fvModelM.H:62
#define DEFINE_FV_MODEL_ADD_RHO_FIELD_SUP(Type, nullArg)
Definition: fvModelM.H:43
#define DEFINE_FV_MODEL_ADD_FIELD_SUP(Type, nullArg)
Definition: fvModelM.H:26
rho
Definition: pEqn.H:1
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
Namespace for OpenFOAM.
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
labelList fv(nPoints)
dictionary dict