massSource.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) 2021-2023 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::massSource
26 
27 Description
28  This fvModel applies a mass source to the continuity equation and to all
29  field equations.
30 
31  If the mass flow rate is positive then user-supplied fixed property values
32  are introduced to the field equations. If the mass flow rate is negative
33  then properties are removed at their current value.
34 
35 Usage
36  Example usage:
37  \verbatim
38  massSource
39  {
40  type massSource;
41 
42  select cellSet;
43  cellSet massSource;
44 
45  massFlowRate 1e-4;
46 
47  fieldValues
48  {
49  U (10 0 0);
50  T 300;
51  k 0.375;
52  epsilon 14.855;
53  }
54  }
55  \endverbatim
56 
57  If the mass flow rate is positive then values should be provided for all
58  solved for fields. Warnings will be issued if values are not provided for
59  fields for which transport equations are solved. Warnings will also be
60  issued if values are provided for fields which are not solved for.
61 
62 SourceFiles
63  massSource.C
64 
65 \*---------------------------------------------------------------------------*/
66 
67 #ifndef massSource_H
68 #define massSource_H
69 
70 #include "fvModel.H"
71 #include "fvCellSet.H"
72 #include "HashPtrTable.H"
73 #include "unknownTypeFunction1.H"
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77 namespace Foam
78 {
79 namespace fv
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class massSourceBase Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class massSourceBase
87 :
88  public fvModel
89 {
90 private:
91 
92  // Private Data
93 
94  //- Name of the phase
95  word phaseName_;
96 
97  //- Name of the density field
98  word rhoName_;
99 
100  //- Name of the energy field
101  word heName_;
102 
103  //- Name of the temperature field
104  word TName_;
105 
106  //- The set of cells the fvConstraint applies to
107  fvCellSet set_;
108 
109  //- Field values
111 
112 
113  // Private Member Functions
114 
115  //- Non-virtual read
116  void readCoeffs();
117 
118  //- Return the mass flow rate
119  virtual scalar massFlowRate() const = 0;
120 
121 
122  // Sources
123 
124  //- Add a source term to an equation
125  template<class Type>
126  void addGeneralSupType
127  (
128  fvMatrix<Type>& eqn,
129  const word& fieldName
130  ) const;
131 
132  //- Add a source term to an equation
133  template<class Type>
134  void addSupType(fvMatrix<Type>& eqn, const word& fieldName) const;
135 
136  //- Add a source term to a scalar equation
137  void addSupType(fvMatrix<scalar>& eqn, const word& fieldName) const;
138 
139  //- Add a source term to a compressible equation
140  template<class Type>
141  void addSupType
142  (
143  const volScalarField& rho,
144  fvMatrix<Type>& eqn,
145  const word& fieldName
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  fvMatrix<Type>& eqn,
155  const word& fieldName
156  ) const;
157 
158 
159 protected:
160 
161  // Protected Member Functions
162 
163  //- Read the set
164  void readSet();
165 
166  //- Read the field values
167  void readFieldValues();
168 
169 
170 public:
171 
172  //- Runtime type information
173  TypeName("massSourceBase");
174 
175 
176  // Constructors
177 
178  //- Construct from explicit source name and mesh
180  (
181  const word& name,
182  const word& modelType,
183  const fvMesh& mesh,
184  const dictionary& dict
185  );
186 
187  //- Disallow default bitwise copy construction
188  massSourceBase(const massSourceBase&) = delete;
189 
190 
191  // Member Functions
192 
193  // Checks
194 
195  //- Return true if the fvModel adds a source term to the given
196  // field's transport equation
197  virtual bool addsSupToField(const word& fieldName) const;
198 
199  //- Return the list of fields for which the fvModel adds source term
200  // to the transport equation
201  virtual wordList addSupFields() const;
202 
203 
204  // Sources
205 
206  //- Add a source term to an equation
208 
209  //- Add a source term to a compressible equation
211 
212  //- Add a source term to a phase equation
214 
215 
216  // Mesh changes
217 
218  //- Update for mesh motion
219  virtual bool movePoints();
220 
221  //- Update topology using the given map
222  virtual void topoChange(const polyTopoChangeMap&);
223 
224  //- Update from another mesh using the given map
225  virtual void mapMesh(const polyMeshMap&);
226 
227  //- Redistribute or update using the given distribution map
228  virtual void distribute(const polyDistributionMap&);
229 
230 
231  // IO
232 
233  //- Read source dictionary
234  virtual bool read(const dictionary& dict);
235 
236 
237  // Member Operators
238 
239  //- Disallow default bitwise assignment
240  void operator=(const massSourceBase&) = delete;
241 };
242 
243 
244 /*---------------------------------------------------------------------------*\
245  Class massSource Declaration
246 \*---------------------------------------------------------------------------*/
247 
248 class massSource
249 :
250  public massSourceBase
251 {
252 private:
253 
254  // Private Data
255 
256  //- Mass flow rate
257  autoPtr<Function1<scalar>> massFlowRate_;
258 
259 
260  // Private Member Functions
261 
262  //- Non-virtual read
263  void readCoeffs();
264 
265  //- Return the mass flow rate
266  virtual scalar massFlowRate() const;
267 
268 
269 public:
270 
271  //- Runtime type information
272  TypeName("massSource");
273 
274 
275  // Constructors
276 
277  //- Construct from explicit source name and mesh
278  massSource
279  (
280  const word& name,
281  const word& modelType,
282  const fvMesh& mesh,
283  const dictionary& dict
284  );
285 
286 
287  // Member Functions
288 
289  // IO
290 
291  //- Read source dictionary
292  virtual bool read(const dictionary& dict);
293 };
294 
295 
296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 
298 } // End namespace fv
299 } // End namespace Foam
300 
301 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
302 
303 #endif
304 
305 // ************************************************************************* //
Generic GeometricField class.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:67
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
General run-time selected cell set selection class for fvMesh.
Definition: fvCellSet.H:88
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:101
Finite volume model abstract base class.
Definition: fvModel.H:59
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:34
const word & name() const
Return const access to the source name.
Definition: fvModelI.H:28
virtual bool movePoints()
Update for mesh motion.
Definition: massSource.C:347
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: massSource.C:325
TypeName("massSourceBase")
Runtime type information.
void readSet()
Read the set.
Definition: massSource.C:241
void operator=(const massSourceBase &)=delete
Disallow default bitwise assignment.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: massSource.C:354
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: massSource.C:366
void readFieldValues()
Read the field values.
Definition: massSource.C:247
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: massSource.C:372
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: massSource.C:360
massSourceBase(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from explicit source name and mesh.
Definition: massSource.C:265
FOR_ALL_FIELD_TYPES(DEFINE_FV_MODEL_ADD_SUP)
Add a source term to an equation.
virtual bool addsSupToField(const word &fieldName) const
Return true if the fvModel adds a source term to the given.
Definition: massSource.C:301
This fvModel applies a mass source to the continuity equation and to all field equations.
Definition: massSource.H:250
TypeName("massSource")
Runtime type information.
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: massSource.C:386
massSource(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from explicit source name and mesh.
Definition: massSource.C:285
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_SUP(Type, nullArg)
Definition: fvModelM.H:26
#define DEFINE_FV_MODEL_ADD_RHO_SUP(Type, nullArg)
Definition: fvModelM.H:43
#define DEFINE_FV_MODEL_ADD_ALPHA_RHO_SUP(Type, nullArg)
Definition: fvModelM.H:62
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
Namespace for OpenFOAM.
labelList fv(nPoints)
dictionary dict