InjectionModel.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) 2011-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::InjectionModel
26 
27 Description
28  Templated injection model class.
29 
30  The injection model nominally describes the parcel:
31  - position
32  - diameter
33  - velocity
34  In this case, the fullyDescribed() flag should be set to 0 (false). When
35  the parcel is then added to the cloud, the remaining properties are
36  populated using values supplied in the constant properties.
37 
38  If, however, all of a parcel's properties are described in the model, the
39  fullyDescribed() flag should be set to 1 (true).
40 
41 SourceFiles
42  InjectionModel.C
43  InjectionModelNew.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef InjectionModel_H
48 #define InjectionModel_H
49 
50 #include "injectionModel.H"
51 #include "CloudSubModelBase.H"
52 #include "particle.H"
53 #include "Function1.H"
54 #include "runTimeSelectionTables.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class InjectionModel Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class CloudType>
66 class InjectionModel
67 :
68  public injectionModel,
69  public CloudSubModelBase<CloudType>
70 {
71 public:
72 
73  //- Convenience typedef for parcelType
74  typedef typename CloudType::parcelType parcelType;
75 
76 
77 protected:
78 
79  // Protected data
80 
81  // Global injection properties
82 
83  //- Start of injection [s]
84  scalar SOI_;
85 
86  //- Total mass injected to date [kg]
87  scalar massInjected_;
88 
89  //- Total number of parcels injected to date
91 
92  //- Mass deferred to be injected at a later time step
93  scalar massDeferred_;
94 
95  //- Number of parcels deferred to be injected at a later time step
96  scalar nParcelsDeferred_;
97 
98 
99  // Injection properties per Lagrangian time step
100 
101  //- Fixed nParticle to assign to parcels. Only valid if
102  // uniformParcelSize is nParticle.
103  scalar nParticleFixed_;
104 
105  //- Size uniform to all parcels
107 
108 
109  // Protected Member Functions
110 
111  //- Read the total mass value for instantaneous injections
112  scalar readMassTotal
113  (
114  const dictionary& dict,
116  );
117 
118  //- Read the duration for continuous injections
119  scalar readDuration
120  (
121  const dictionary& dict,
123  );
124 
125  //- Read the mass flow rate function for continuous injections
127  (
128  const dictionary& dict,
129  CloudType& owner,
130  const scalar duration
131  );
132 
133  //- Read the number of parcels injected per second for continuous
134  // injections
136  (
137  const dictionary& dict,
139  );
140 
141  //- Get the index of this injector
142  label index() const;
143 
144  //- Find the cell that contains the supplied position
145  // Will modify position slightly towards the owner cell centroid to
146  // ensure that it lies in a cell and not edge/face
147  bool findCellAtPosition
148  (
149  const meshSearch& searchEngine,
150  const point& position,
152  label& celli,
153  label& tetFacei,
154  label& tetPti,
155  bool errorOnNotFound = true
156  );
157 
158  //- Constrain a parcel's position appropriately to the geometric
159  // dimensions of the mesh
160  void constrainPosition
161  (
162  typename CloudType::parcelType::trackingData& td,
163  typename CloudType::parcelType& parcel
164  );
165 
166  //- Return the sampling moment to be used by the size distribution
167  label sizeSampleQ() const;
168 
169  //- Set number of particles to inject given parcel properties
171  (
172  PtrList<parcelType>& parcelPtrs,
173  const scalar mass
174  ) const;
175 
176  //- Pre injection hook
177  virtual void preInject
178  (
179  typename parcelType::trackingData& td
180  );
181 
182  //- Post injection hook
183  virtual void postInject
184  (
185  const label parcelsAdded,
186  const scalar massAdded,
187  typename parcelType::trackingData& td
188  );
189 
190 
191 public:
192 
193  //- Runtime type information
194  TypeName("injectionModel");
195 
196  //- Declare runtime constructor selection table
198  (
199  autoPtr,
201  dictionary,
202  (
203  const dictionary& dict,
204  CloudType& owner,
205  const word& modelType
206  ),
207  (dict, owner, modelType)
208  );
209 
210 
211  // Constructors
212 
213  //- Construct null from owner
215 
216  //- Construct from dictionary
218  (
219  const dictionary& dict,
220  CloudType& owner,
221  const word& modelName,
222  const word& modelType
223  );
224 
225  //- Construct copy
227 
228  //- Construct and return a clone
229  virtual autoPtr<InjectionModel<CloudType>> clone() const = 0;
230 
231 
232  //- Destructor
233  virtual ~InjectionModel();
234 
235 
236  // Selectors
237 
238  //- Selector with lookup from dictionary
240  (
241  const dictionary& dict,
243  );
244 
245  //- Selector with name and type
247  (
248  const dictionary& dict,
249  const word& modelName,
250  const word& modelType,
252  );
253 
254 
255  // Member Functions
256 
257  // Mapping
258 
259  //- Update mesh
260  virtual void topoChange();
261 
262 
263  // Global information
264 
265  //- Return the start-of-injection time
266  inline scalar timeStart() const;
267 
268  //- Return mass of parcels injected (cumulative)
269  inline scalar massInjected() const;
270 
271  //- Return number of parcels injected (cumulative)
272  inline label nParcelsInjected() const;
273 
274  //- Return the end-of-injection time
275  virtual scalar timeEnd() const = 0;
276 
277  //- Number of parcels to introduce relative to SOI
278  virtual scalar nParcelsToInject
279  (
280  const scalar time0,
281  const scalar time1
282  ) = 0;
283 
284  //- Parcel mass to introduce relative to SOI
285  virtual scalar massToInject
286  (
287  const scalar time0,
288  const scalar time1
289  ) = 0;
290 
291  //- Return the average injected parcel mass
292  scalar averageParcelMass();
293 
294 
295  // Per-injection event functions
296 
297  //- Main injection loop
298  template<class TrackCloudType>
299  void inject
300  (
301  TrackCloudType& cloud,
302  typename CloudType::parcelType::trackingData& td
303  );
304 
305  //- Main injection loop - steady-state
306  template<class TrackCloudType>
307  void injectSteadyState
308  (
309  TrackCloudType& cloud,
310  typename CloudType::parcelType::trackingData& td
311  );
312 
313 
314  // Injection geometry
315 
316  //- Set the injection position and owner cell, tetFace and tetPt
317  virtual void setPositionAndCell
318  (
319  const meshSearch& searchEngine,
320  const label parcelI,
321  const label nParcels,
322  const scalar time,
324  label& celli,
325  label& tetFacei,
326  label& tetPti,
327  label& facei
328  ) = 0;
329 
330  //- Set the parcel properties
331  virtual void setProperties
332  (
333  const label parcelI,
334  const label nParcels,
335  const scalar time,
336  typename parcelType::trackingData& td,
337  parcelType& parcel
338  ) = 0;
339 
340  //- Flag to identify whether model fully describes the parcel
341  virtual bool fullyDescribed() const = 0;
342 
343 
344  // I-O
345 
346  //- Write injection info to stream
347  virtual void info(Ostream& os);
348 };
349 
350 
351 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 
353 } // End namespace Foam
354 
355 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 
357 #define makeInjectionModel(CloudType) \
358  \
359  typedef Foam::CloudType::momentumCloudType CloudType##momentumCloudType; \
360  \
361  defineNamedTemplateTypeNameAndDebug \
362  ( \
363  Foam::InjectionModel<CloudType##momentumCloudType>, \
364  0 \
365  ); \
366  \
367  namespace Foam \
368  { \
369  defineTemplateRunTimeSelectionTable \
370  ( \
371  InjectionModel<CloudType##momentumCloudType>, \
372  dictionary \
373  ); \
374  }
375 
376 
377 #define makeInjectionModelType(SS, CloudType) \
378  \
379  typedef Foam::CloudType::momentumCloudType CloudType##momentumCloudType; \
380  \
381  defineNamedTemplateTypeNameAndDebug \
382  ( \
383  Foam::SS<CloudType##momentumCloudType>, \
384  0 \
385  ); \
386  \
387  Foam::InjectionModel<CloudType##momentumCloudType>:: \
388  adddictionaryConstructorToTable<Foam::SS<CloudType##momentumCloudType>>\
389  add##SS##CloudType##momentumCloudType##ConstructorToTable_;
390 
391 
392 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
393 
394 #include "InjectionModelI.H"
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 #ifdef NoRepository
399  #include "InjectionModel.C"
400 #endif
401 
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403 
404 #endif
405 
406 // ************************************************************************* //
Base class for cloud sub-models.
const CloudType & owner() const
Return const access to the owner cloud.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:225
Templated injection model class.
virtual bool fullyDescribed() const =0
Flag to identify whether model fully describes the parcel.
virtual void topoChange()
Update mesh.
virtual scalar timeEnd() const =0
Return the end-of-injection time.
virtual ~InjectionModel()
Destructor.
void inject(TrackCloudType &cloud, typename CloudType::parcelType::trackingData &td)
Main injection loop.
autoPtr< Function1< scalar > > readParcelsPerSecond(const dictionary &dict, CloudType &owner)
Read the number of parcels injected per second for continuous.
void constrainPosition(typename CloudType::parcelType::trackingData &td, typename CloudType::parcelType &parcel)
Constrain a parcel's position appropriately to the geometric.
virtual void postInject(const label parcelsAdded, const scalar massAdded, typename parcelType::trackingData &td)
Post injection hook.
virtual void preInject(typename parcelType::trackingData &td)
Pre injection hook.
TypeName("injectionModel")
Runtime type information.
scalar readMassTotal(const dictionary &dict, CloudType &owner)
Read the total mass value for instantaneous injections.
virtual void info(Ostream &os)
Write injection info to stream.
label nParcelsInjected_
Total number of parcels injected to date.
scalar timeStart() const
Return the start-of-injection time.
void setNumberOfParticles(PtrList< parcelType > &parcelPtrs, const scalar mass) const
Set number of particles to inject given parcel properties.
autoPtr< Function1< scalar > > readMassFlowRate(const dictionary &dict, CloudType &owner, const scalar duration)
Read the mass flow rate function for continuous injections.
uniformParcelSize uniformParcelSize_
Size uniform to all parcels.
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, typename parcelType::trackingData &td, parcelType &parcel)=0
Set the parcel properties.
scalar massDeferred_
Mass deferred to be injected at a later time step.
virtual scalar massToInject(const scalar time0, const scalar time1)=0
Parcel mass to introduce relative to SOI.
label sizeSampleQ() const
Return the sampling moment to be used by the size distribution.
bool findCellAtPosition(const meshSearch &searchEngine, const point &position, barycentric &coordinates, label &celli, label &tetFacei, label &tetPti, bool errorOnNotFound=true)
Find the cell that contains the supplied position.
static autoPtr< InjectionModel< CloudType > > New(const dictionary &dict, CloudType &owner)
Selector with lookup from dictionary.
scalar averageParcelMass()
Return the average injected parcel mass.
virtual scalar nParcelsToInject(const scalar time0, const scalar time1)=0
Number of parcels to introduce relative to SOI.
declareRunTimeSelectionTable(autoPtr, InjectionModel, dictionary,(const dictionary &dict, CloudType &owner, const word &modelType),(dict, owner, modelType))
Declare runtime constructor selection table.
scalar nParticleFixed_
Fixed nParticle to assign to parcels. Only valid if.
virtual void setPositionAndCell(const meshSearch &searchEngine, const label parcelI, const label nParcels, const scalar time, barycentric &coordinates, label &celli, label &tetFacei, label &tetPti, label &facei)=0
Set the injection position and owner cell, tetFace and tetPt.
label index() const
Get the index of this injector.
void injectSteadyState(TrackCloudType &cloud, typename CloudType::parcelType::trackingData &td)
Main injection loop - steady-state.
scalar readDuration(const dictionary &dict, CloudType &owner)
Read the duration for continuous injections.
scalar massInjected() const
Return mass of parcels injected (cumulative)
virtual autoPtr< InjectionModel< CloudType > > clone() const =0
Construct and return a clone.
InjectionModel(CloudType &owner)
Construct null from owner.
CloudType::parcelType parcelType
Convenience typedef for parcelType.
label nParcelsInjected() const
Return number of parcels injected (cumulative)
scalar SOI_
Start of injection [s].
scalar nParcelsDeferred_
Number of parcels deferred to be injected at a later time step.
scalar massInjected_
Total mass injected to date [kg].
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
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 clouds. Provides a basic evolution algorithm, models, and a database for caching deriv...
Definition: cloud.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Non-templated base class for lagrangian injection models.
uniformParcelSize
Enumeration for the parcels' uniform size.
Mesh object that implements searches within the local cells and faces.
Definition: meshSearch.H:59
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:109
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:103
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:121
A class for handling words, derived from string.
Definition: word.H:63
const dimensionSet time
const dimensionSet mass
barycentric coordinates(const polyMesh &mesh, const point &position, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the coordinates given the position and tet topology.
Definition: tracking.C:1258
point position(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the position given the coordinates and tet topology.
Definition: trackingI.H:224
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Macros to ease declaration of run-time selection tables.