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-2025 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  //- The name of the field that this fvModel applies to
103  word fieldName_;
104 
105  //- Cached coefficients dictionary
106  // Required for the delayed
107  dictionary coeffsDict_;
108 
109  //- Underlying functionObject
110  mutable autoPtr<fvModel> redirectFvModelPtr_;
111 
112 
113  // Private Member Functions
114 
115  //- Non-virtual read
116  void readCoeffs(const dictionary& dict);
117 
118  //- Return the name of the field's primitive type
119  word fieldPrimitiveTypeName() const;
120 
121  //- Adapt the context for the current object
122  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
123 
124  //- Compile, link and load the coded fvModel if not already loaded
125  // and return it
126  fvModel& redirectFvModel() const;
127 
128 
129  // Sources
130 
131  //- Add a source term to an equation
132  template<class Type>
133  void addSupType
134  (
135  const VolField<Type>& field,
136  fvMatrix<Type>& eqn
137  ) const;
138 
139  //- Add a source term to a compressible equation
140  template<class Type>
141  void addSupType
142  (
143  const volScalarField& rho,
144  const VolField<Type>& field,
145  fvMatrix<Type>& eqn
146  ) const;
147 
148  //- Add a source term to a phase equation
149  template<class Type>
150  void addSupType
151  (
152  const volScalarField& alpha,
153  const volScalarField& rho,
154  const VolField<Type>& field,
155  fvMatrix<Type>& eqn
156  ) const;
157 
158 
159 public:
160 
161  //- Runtime type information
162  TypeName("coded");
163 
164 
165  // Constructors
166 
167  //- Construct from components
169  (
170  const word& name,
171  const word& modelType,
172  const fvMesh& mesh,
173  const dictionary& dict
174  );
175 
176 
177  // Member Functions
178 
179  // Checks
180 
181  //- Return the list of fields for which the fvModel adds source term
182  // to the transport equation
183  virtual wordList addSupFields() const;
184 
185 
186  // Sources
187 
188  //- Add a source term to an equation
190 
191  //- Add a source term to a compressible equation
193 
194  //- Add a source term to a phase equation
196 
197 
198  // Mesh changes
199 
200  //- Update for mesh motion
201  virtual bool movePoints();
202 
203  //- Update topology using the given map
204  virtual void topoChange(const polyTopoChangeMap&);
205 
206  //- Update from another mesh using the given map
207  virtual void mapMesh(const polyMeshMap&);
208 
209  //- Redistribute or update using the given distribution map
210  virtual void distribute(const polyDistributionMap&);
211 
212 
213  // IO
214 
215  //- Read source dictionary
216  virtual bool read(const dictionary& dict);
217 };
218 
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 } // End namespace fv
223 } // End namespace Foam
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 #endif
228 
229 // ************************************************************************* //
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 function objects and boundary conditions using dynamic code.
Definition: codedBase.H:52
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Encapsulation of dynamic code dictionaries.
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:57
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:96
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:206
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: codedFvModel.C:224
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: codedFvModel.C:249
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: codedFvModel.C:261
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:267
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: codedFvModel.C:255
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:62
#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
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(makeFieldSourceTypedef)
labelList fv(nPoints)
dictionary dict