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-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::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  fullDescribed() flag should be set to 1 (true).
40 
41 
42 SourceFiles
43  InjectionModel.C
44  InjectionModelNew.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef InjectionModel_H
49 #define InjectionModel_H
50 
51 #include "injectionModel.H"
52 #include "CloudSubModelBase.H"
53 #include "particle.H"
54 #include "TimeFunction1.H"
55 #include "runTimeSelectionTables.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class InjectionModel Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 template<class CloudType>
67 class InjectionModel
68 :
69  public injectionModel,
70  public CloudSubModelBase<CloudType>
71 {
72 public:
73 
74  //- Convenience typedef for parcelType
75  typedef typename CloudType::parcelType parcelType;
76 
77 
78 protected:
79 
80  // Protected data
81 
82  // Global injection properties
83 
84  //- Start of injection [s]
85  scalar SOI_;
86 
87  //- Total mass injected to date [kg]
88  scalar massInjected_;
89 
90 
91  // Counters
92 
93  //- Number of injections counter
95 
96  //- Running counter of total number of parcels added
98 
99 
100  // Injection properties per Lagrangian time step
101 
102  //- Fixed nParticle to assign to parcels. Only valid if
103  // uniformParcelSize is nParticle.
104  scalar nParticleFixed_;
105 
106  //- Size uniform to all parcels
108 
109  //- Continuous phase time at start of injection time step [s]
110  scalar time0_;
111 
112  //- Time at start of injection time step [s]
113  scalar timeStep0_;
114 
115 
116  // Protected Member Functions
117 
118  //- Read the total mass value for instantaneous injections
119  scalar readMassTotal
120  (
121  const dictionary& dict,
123  );
124 
125  //- Read the duration for continuous injections
126  scalar readDuration
127  (
128  const dictionary& dict,
130  );
131 
132  //- Read the mass flow rate function for continuous injections
134  (
135  const dictionary& dict,
136  CloudType& owner,
137  const scalar duration
138  );
139 
140  //- Read the number of parcels injected per second for continuous
141  // injections
143  (
144  const dictionary& dict,
146  );
147 
148  //- Get the index of this injector
149  label index() const;
150 
151  //- Find the cell that contains the supplied position
152  // Will modify position slightly towards the owner cell centroid to
153  // ensure that it lies in a cell and not edge/face
154  bool findCellAtPosition
155  (
156  const point& position,
157  barycentric& coordinates,
158  label& celli,
159  label& tetFacei,
160  label& tetPti,
161  bool errorOnNotFound = true
162  );
163 
164  //- Constrain a parcel's position appropriately to the geometric
165  // dimensions of the mesh
166  void constrainPosition
167  (
168  typename CloudType::parcelType::trackingData& td,
169  typename CloudType::parcelType& parcel
170  );
171 
172  //- Return the sampling moment to be used by the size distribution
173  label sizeSampleQ() const;
174 
175  //- Set number of particles to inject given parcel properties
177  (
178  PtrList<parcelType>& parcelPtrs,
179  const scalar mass
180  ) const;
181 
182  //- Post injection checks
183  void postInjectCheck
184  (
185  const label parcelsAdded,
186  const scalar massAdded
187  );
188 
189 
190 public:
191 
192  //- Runtime type information
193  TypeName("injectionModel");
194 
195  //- Declare runtime constructor selection table
197  (
198  autoPtr,
200  dictionary,
201  (
202  const dictionary& dict,
203  CloudType& owner,
204  const word& modelType
205  ),
206  (dict, owner, modelType)
207  );
208 
209 
210  // Constructors
211 
212  //- Construct null from owner
214 
215  //- Construct from dictionary
217  (
218  const dictionary& dict,
219  CloudType& owner,
220  const word& modelName,
221  const word& modelType
222  );
223 
224  //- Construct copy
226 
227  //- Construct and return a clone
228  virtual autoPtr<InjectionModel<CloudType>> clone() const = 0;
229 
230 
231  //- Destructor
232  virtual ~InjectionModel();
233 
234 
235  // Selectors
236 
237  //- Selector with lookup from dictionary
239  (
240  const dictionary& dict,
242  );
243 
244  //- Selector with name and type
246  (
247  const dictionary& dict,
248  const word& modelName,
249  const word& modelType,
251  );
252 
253 
254  // Member Functions
255 
256  // Mapping
257 
258  //- Update mesh
259  virtual void topoChange();
260 
261 
262  // Global information
263 
264  //- Return the start-of-injection time
265  inline scalar timeStart() const;
266 
267  //- Return mass of particles injected (cumulative)
268  inline scalar massInjected() const;
269 
270  //- Return the end-of-injection time
271  virtual scalar timeEnd() const = 0;
272 
273  //- Number of parcels to introduce relative to SOI
274  virtual label nParcelsToInject
275  (
276  const scalar time0,
277  const scalar time1
278  ) = 0;
279 
280  //- Parcel mass to introduce relative to SOI
281  virtual scalar massToInject
282  (
283  const scalar time0,
284  const scalar time1
285  ) = 0;
286 
287  //- Return the average injected parcel mass
288  scalar averageParcelMass();
289 
290 
291  // Counters
292 
293  //- Return the number of injections
294  inline label nInjections() const;
295 
296  //- Return the total number parcels added
297  inline label parcelsAddedTotal() const;
298 
299 
300  // Per-injection event functions
301 
302  //- Main injection loop
303  template<class TrackCloudType>
304  void inject
305  (
306  TrackCloudType& cloud,
307  typename CloudType::parcelType::trackingData& td
308  );
309 
310  //- Main injection loop - steady-state
311  template<class TrackCloudType>
312  void injectSteadyState
313  (
314  TrackCloudType& cloud,
315  typename CloudType::parcelType::trackingData& td
316  );
317 
318 
319  // Injection geometry
320 
321  //- Set the injection position and owner cell, tetFace and tetPt
322  virtual void setPositionAndCell
323  (
324  const label parcelI,
325  const label nParcels,
326  const scalar time,
327  barycentric& coordinates,
328  label& celli,
329  label& tetFacei,
330  label& tetPti,
331  label& facei
332  ) = 0;
333 
334  //- Set the parcel properties
335  virtual void setProperties
336  (
337  const label parcelI,
338  const label nParcels,
339  const scalar time,
340  parcelType& parcel
341  ) = 0;
342 
343  //- Flag to identify whether model fully describes the parcel
344  virtual bool fullyDescribed() const = 0;
345 
346 
347  // I-O
348 
349  //- Write injection info to stream
350  virtual void info(Ostream& os);
351 };
352 
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 
356 } // End namespace Foam
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 #define makeInjectionModel(CloudType) \
361  \
362  typedef Foam::CloudType::momentumCloudType momentumCloudType; \
363  defineNamedTemplateTypeNameAndDebug \
364  ( \
365  Foam::InjectionModel<momentumCloudType>, \
366  0 \
367  ); \
368  \
369  namespace Foam \
370  { \
371  defineTemplateRunTimeSelectionTable \
372  ( \
373  InjectionModel<momentumCloudType>, \
374  dictionary \
375  ); \
376  }
377 
378 
379 #define makeInjectionModelType(SS, CloudType) \
380  \
381  typedef Foam::CloudType::momentumCloudType momentumCloudType; \
382  defineNamedTemplateTypeNameAndDebug(Foam::SS<momentumCloudType>, 0); \
383  \
384  Foam::InjectionModel<momentumCloudType>:: \
385  adddictionaryConstructorToTable<Foam::SS<momentumCloudType>> \
386  add##SS##CloudType##momentumCloudType##ConstructorToTable_;
387 
388 
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 
391 #include "InjectionModelI.H"
392 
393 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 
395 #ifdef NoRepository
396  #include "InjectionModel.C"
397 #endif
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 #endif
402 
403 // ************************************************************************* //
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:79
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:221
Templated injection model class.
virtual bool fullyDescribed() const =0
Flag to identify whether model fully describes the parcel.
virtual void setPositionAndCell(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.
scalar timeStep0_
Time at start of injection time step [s].
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.
void constrainPosition(typename CloudType::parcelType::trackingData &td, typename CloudType::parcelType &parcel)
Constrain a parcel's position appropriately to the geometric.
TypeName("injectionModel")
Runtime type information.
bool findCellAtPosition(const point &position, barycentric &coordinates, label &celli, label &tetFacei, label &tetPti, bool errorOnNotFound=true)
Find the cell that contains the supplied position.
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.
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.
uniformParcelSize uniformParcelSize_
Size uniform to all parcels.
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.
static autoPtr< InjectionModel< CloudType > > New(const dictionary &dict, CloudType &owner)
Selector with lookup from dictionary.
scalar averageParcelMass()
Return the average injected parcel mass.
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.
label index() const
Get the index of this injector.
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, parcelType &parcel)=0
Set the parcel properties.
TimeFunction1< scalar > readParcelsPerSecond(const dictionary &dict, CloudType &owner)
Read the number of parcels injected per second for continuous.
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.
label parcelsAddedTotal() const
Return the total number parcels added.
scalar massInjected() const
Return mass of particles injected (cumulative)
virtual autoPtr< InjectionModel< CloudType > > clone() const =0
Construct and return a clone.
virtual label nParcelsToInject(const scalar time0, const scalar time1)=0
Number of parcels to introduce relative to SOI.
label nInjections_
Number of injections counter.
InjectionModel(CloudType &owner)
Construct null from owner.
TimeFunction1< scalar > readMassFlowRate(const dictionary &dict, CloudType &owner, const scalar duration)
Read the mass flow rate function for continuous injections.
label parcelsAddedTotal_
Running counter of total number of parcels added.
CloudType::parcelType parcelType
Convenience typedef for parcelType.
scalar time0_
Continuous phase time at start of injection time step [s].
scalar SOI_
Start of injection [s].
label nInjections() const
Return the number of injections.
void postInjectCheck(const label parcelsAdded, const scalar massAdded)
Post injection checks.
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
A cloud is a collection of lagrangian particles.
Definition: cloud.H:55
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Non-templated base class for lagrangian injection models.
uniformParcelSize
Enumeration for the parcels' uniform size.
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:110
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:104
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:122
A class for handling words, derived from string.
Definition: word.H:62
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.