InjectionModel.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::InjectionModel
29 
30 Group
31  grpLagrangianIntermediateInjectionSubModels
32 
33 Description
34  Templated injection model class.
35 
36  The injection model nominally describes the parcel:
37  - position
38  - diameter
39  - velocity
40  In this case, the fullyDescribed() flag should be set to 0 (false). When
41  the parcel is then added to the cloud, the remaining properties are
42  populated using values supplied in the constant properties.
43 
44  If, however, all of a parcel's properties are described in the model, the
45  fullDescribed() flag should be set to 1 (true).
46 
47 
48 SourceFiles
49  InjectionModel.C
50  InjectionModelNew.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef InjectionModel_H
55 #define InjectionModel_H
56 
57 #include "IOdictionary.H"
58 #include "autoPtr.H"
59 #include "runTimeSelectionTables.H"
60 #include "CloudSubModelBase.H"
61 #include "vector.H"
62 #include "Function1.H"
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 
66 namespace Foam
67 {
68 
69 /*---------------------------------------------------------------------------*\
70  Class InjectionModel Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 template<class CloudType>
74 class InjectionModel
75 :
76  public CloudSubModelBase<CloudType>
77 {
78 public:
79 
80  //- Convenience typedef for parcelType
81  typedef typename CloudType::parcelType parcelType;
82 
83 
84  // Enumerations
85 
86  //- Parcel basis representation options
87  //- i.e constant number of particles OR constant mass per parcel
88  enum parcelBasis
89  {
92  pbFixed
93  };
94 
95 
96 protected:
97 
98  // Protected data
99 
100  // Global injection properties
101 
102  //- Start of injection [s]
103  scalar SOI_;
104 
105  //- Total volume of particles introduced by this injector [m^3]
106  //- Note: scaled to ensure massTotal is achieved
107  scalar volumeTotal_;
108 
109  //- Total mass to inject [kg]
110  scalar massTotal_;
111 
112  //- Mass flow rate profile for steady calculations
114 
115  //- Total mass injected to date [kg]
116  scalar massInjected_;
117 
118 
119  // Counters
120 
121  //- Number of injections counter
122  label nInjections_;
123 
124  //- Running counter of total number of parcels added
125  label parcelsAddedTotal_;
126 
127 
128  // Injection properties per Lagrangian time step
129 
130  //- Parcel basis enumeration
132 
133  //- nParticle to assign to parcels when the 'fixed' basis
134  //- is selected
135  scalar nParticleFixed_;
136 
137  //- Continuous phase time at start of injection time step [s]
138  scalar time0_;
139 
140  //- Time at start of injection time step [s]
141  scalar timeStep0_;
142 
143  //- Minimum number of particles used to represent each parcel
144  //- default = 1
145  scalar minParticlesPerParcel_;
146 
147  //- Volume that should have been injected, but would lead to
148  //- less than minParticlesPerParcel_ particle per parcel
149  scalar delayedVolume_;
150 
151  //- Optional injector ID
152  label injectorID_;
153 
154  //- Optional flag to indicate that injections attempted outside
155  //- the mesh should be ignored
156  bool ignoreOutOfBounds_;
157 
158 
159  // Protected Member Functions
160 
161  //- Additional flag to identify whether or not injection of parcelI is
162  // permitted
163  virtual bool validInjection(const label parcelI) = 0;
164 
165  //- Determine properties for next time step/injection interval
166  virtual bool prepareForNextTimeStep
167  (
168  const scalar time,
169  label& newParcels,
170  scalar& newVolumeFraction
171  );
172 
173  //- Find the cell that contains the supplied position
174  // Will modify position slightly towards the owner cell centroid to
175  // ensure that it lies in a cell and not edge/face
176  virtual bool findCellAtPosition
177  (
178  label& celli,
179  label& tetFacei,
180  label& tetPti,
181  vector& position,
182  bool errorOnNotFound = true
183  );
184 
185  //- Set number of particles to inject given parcel properties
186  virtual scalar setNumberOfParticles
187  (
188  const label parcels,
189  const scalar volumeFraction,
190  const scalar diameter,
191  const scalar rho
192  );
193 
194  //- Post injection checks
195  virtual void postInjectCheck
196  (
197  const label parcelsAdded,
198  const scalar massAdded
199  );
200 
201 
202 public:
203 
204  //- Runtime type information
205  TypeName("injectionModel");
206 
207  //- Declare runtime constructor selection table
209  (
210  autoPtr,
212  dictionary,
213  (
214  const dictionary& dict,
215  CloudType& owner,
216  const word& modelType
217  ),
218  (dict, owner, modelType)
219  );
220 
221 
222  // Constructors
223 
224  //- Construct null from owner
226 
227  //- Construct from dictionary
229  (
230  const dictionary& dict,
231  CloudType& owner,
232  const word& modelName,
233  const word& modelType
234  );
235 
236  //- Construct copy
238 
239  //- Construct and return a clone
240  virtual autoPtr<InjectionModel<CloudType>> clone() const = 0;
241 
242 
243  //- Destructor
244  virtual ~InjectionModel() = default;
245 
246 
247  // Selectors
248 
249  //- Selector with lookup from dictionary
251  (
252  const dictionary& dict,
254  );
255 
256  //- Selector with name and type
258  (
259  const dictionary& dict,
260  const word& modelName,
261  const word& modelType,
263  );
264 
265 
266  // Member Functions
267 
268  // Mapping
269 
270  //- Update mesh
271  virtual void updateMesh();
272 
273 
274  // Global information
275 
276  //- Return the start-of-injection time
277  inline scalar timeStart() const;
278 
279  //- Return the total volume to be injected across the event
280  inline scalar volumeTotal() const;
281 
282  //- Return mass of particles to introduce
283  inline scalar massTotal() const;
284 
285  //- Return mass of particles injected (cumulative)
286  inline scalar massInjected() const;
287 
288  //- Return injectorID
289  inline label injectorID() const;
290 
291  //- Return the end-of-injection time
292  virtual scalar timeEnd() const = 0;
293 
294  //- Number of parcels to introduce relative to SOI
295  virtual label parcelsToInject
296  (
297  const scalar time0,
298  const scalar time1
299  ) = 0;
300 
301  //- Volume of parcels to introduce relative to SOI
302  virtual scalar volumeToInject
303  (
304  const scalar time0,
305  const scalar time1
306  ) = 0;
307 
308  //- Return the average parcel mass over the injection period
309  virtual scalar averageParcelMass();
310 
311 
312  // Counters
313 
314  //- Return the number of injections
315  inline label nInjections() const;
316 
317  //- Return the total number parcels added
318  inline label parcelsAddedTotal() const;
319 
320 
321  // Per-injection event functions
322 
323  //- Main injection loop
324  template<class TrackCloudType>
325  void inject
326  (
327  TrackCloudType& cloud,
328  typename CloudType::parcelType::trackingData& td
329  );
330 
331  //- Main injection loop - steady-state
332  template<class TrackCloudType>
333  void injectSteadyState
334  (
335  TrackCloudType& cloud,
336  typename CloudType::parcelType::trackingData& td,
337  const scalar trackTime
338  );
339 
340 
341  // Injection geometry
342 
343  //- Set the injection position and owner cell, tetFace and tetPt
344  virtual void setPositionAndCell
345  (
346  const label parcelI,
347  const label nParcels,
348  const scalar time,
349  vector& position,
350  label& cellOwner,
351  label& tetFacei,
352  label& tetPti
353  ) = 0;
354 
355  //- Set the parcel properties
356  virtual void setProperties
357  (
358  const label parcelI,
359  const label nParcels,
360  const scalar time,
361  parcelType& parcel
362  ) = 0;
363 
364  //- Flag to identify whether model fully describes the parcel
365  virtual bool fullyDescribed() const = 0;
366 
367 
368  // I-O
369 
370  //- Write injection info to stream
371  virtual void info(Ostream& os);
372 };
373 
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 } // End namespace Foam
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 #define makeInjectionModel(CloudType) \
382  \
383  typedef Foam::CloudType::kinematicCloudType kinematicCloudType; \
384  defineNamedTemplateTypeNameAndDebug \
385  ( \
386  Foam::InjectionModel<kinematicCloudType>, \
387  0 \
388  ); \
389  \
390  namespace Foam \
391  { \
392  defineTemplateRunTimeSelectionTable \
393  ( \
394  InjectionModel<kinematicCloudType>, \
395  dictionary \
396  ); \
397  }
398 
399 
400 #define makeInjectionModelType(SS, CloudType) \
401  \
402  typedef Foam::CloudType::kinematicCloudType kinematicCloudType; \
403  defineNamedTemplateTypeNameAndDebug(Foam::SS<kinematicCloudType>, 0); \
404  \
405  Foam::InjectionModel<kinematicCloudType>:: \
406  adddictionaryConstructorToTable<Foam::SS<kinematicCloudType>> \
407  add##SS##CloudType##kinematicCloudType##ConstructorToTable_;
408 
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 #include "InjectionModelI.H"
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 #ifdef NoRepository
417  #include "InjectionModel.C"
418 #endif
419 
420 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
421 
422 #endif
423 
424 // ************************************************************************* //
Foam::InjectionModel::validInjection
virtual bool validInjection(const label parcelI)=0
Additional flag to identify whether or not injection of parcelI is.
Foam::InjectionModel::massTotal
scalar massTotal() const
Return mass of particles to introduce.
Definition: InjectionModelI.H:48
Foam::InjectionModel::info
virtual void info(Ostream &os)
Write injection info to stream.
Definition: InjectionModel.C:669
Foam::InjectionModel::findCellAtPosition
virtual bool findCellAtPosition(label &celli, label &tetFacei, label &tetPti, vector &position, bool errorOnNotFound=true)
Find the cell that contains the supplied position.
Definition: InjectionModel.C:95
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::InjectionModel::parcelsAddedTotal
label parcelsAddedTotal() const
Return the total number parcels added.
Definition: InjectionModelI.H:76
Foam::InjectionModel::setPositionAndCell
virtual void setPositionAndCell(const label parcelI, const label nParcels, const scalar time, vector &position, label &cellOwner, label &tetFacei, label &tetPti)=0
Set the injection position and owner cell, tetFace and tetPt.
Foam::InjectionModel::InjectionModel
InjectionModel(CloudType &owner)
Construct null from owner.
Definition: InjectionModel.C:263
Foam::InjectionModel::updateMesh
virtual void updateMesh()
Update mesh.
Definition: InjectionModel.C:415
Function1.H
InjectionModelI.H
Foam::InjectionModel
Templated injection model class.
Definition: InjectionModel.H:73
Foam::CloudSubModelBase
Base class for cloud sub-models.
Definition: CloudSubModelBase.H:51
Foam::InjectionModel::prepareForNextTimeStep
virtual bool prepareForNextTimeStep(const scalar time, label &newParcels, scalar &newVolumeFraction)
Determine properties for next time step/injection interval.
Definition: InjectionModel.C:39
Foam::InjectionModel::massInjected_
scalar massInjected_
Total mass injected to date [kg].
Definition: InjectionModel.H:115
Foam::InjectionModel::parcelsToInject
virtual label parcelsToInject(const scalar time0, const scalar time1)=0
Number of parcels to introduce relative to SOI.
Foam::InjectionModel::setNumberOfParticles
virtual scalar setNumberOfParticles(const label parcels, const scalar volumeFraction, const scalar diameter, const scalar rho)
Set number of particles to inject given parcel properties.
Definition: InjectionModel.C:188
Foam::InjectionModel::massFlowRate_
autoPtr< Function1< scalar > > massFlowRate_
Mass flow rate profile for steady calculations.
Definition: InjectionModel.H:112
Foam::subModelBase::modelName
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:107
Foam::InjectionModel::delayedVolume_
scalar delayedVolume_
Definition: InjectionModel.H:148
Foam::InjectionModel::volumeTotal_
scalar volumeTotal_
Definition: InjectionModel.H:106
rho
rho
Definition: readInitialConditions.H:88
Foam::InjectionModel::timeStep0_
scalar timeStep0_
Time at start of injection time step [s].
Definition: InjectionModel.H:140
Foam::InjectionModel::injectorID_
label injectorID_
Optional injector ID.
Definition: InjectionModel.H:151
Foam::InjectionModel::nInjections
label nInjections() const
Return the number of injections.
Definition: InjectionModelI.H:69
Foam::InjectionModel::timeStart
scalar timeStart() const
Return the start-of-injection time.
Definition: InjectionModelI.H:34
Foam::InjectionModel::fullyDescribed
virtual bool fullyDescribed() const =0
Flag to identify whether model fully describes the parcel.
Foam::InjectionModel::injectorID
label injectorID() const
Return injectorID.
Definition: InjectionModelI.H:62
Foam::InjectionModel::pbNumber
Definition: InjectionModel.H:89
Foam::subModelBase::dict
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:113
CloudSubModelBase.H
Foam::InjectionModel::clone
virtual autoPtr< InjectionModel< CloudType > > clone() const =0
Construct and return a clone.
Foam::InjectionModel::massInjected
scalar massInjected() const
Return mass of particles injected (cumulative)
Definition: InjectionModelI.H:55
Foam::InjectionModel::parcelBasis
parcelBasis
Definition: InjectionModel.H:87
Foam::InjectionModel::injectSteadyState
void injectSteadyState(TrackCloudType &cloud, typename CloudType::parcelType::trackingData &td, const scalar trackTime)
Main injection loop - steady-state.
Definition: InjectionModel.C:569
Foam::InjectionModel::time0_
scalar time0_
Continuous phase time at start of injection time step [s].
Definition: InjectionModel.H:137
Foam::InjectionModel::volumeToInject
virtual scalar volumeToInject(const scalar time0, const scalar time1)=0
Volume of parcels to introduce relative to SOI.
Foam::CloudSubModelBase::owner
const CloudType & owner() const
Return const access to the owner cloud.
Definition: CloudSubModelBase.C:106
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
Foam::InjectionModel::minParticlesPerParcel_
scalar minParticlesPerParcel_
Definition: InjectionModel.H:144
Foam::InjectionModel::postInjectCheck
virtual void postInjectCheck(const label parcelsAdded, const scalar massAdded)
Post injection checks.
Definition: InjectionModel.C:231
Foam::InjectionModel::averageParcelMass
virtual scalar averageParcelMass()
Return the average parcel mass over the injection period.
Definition: InjectionModel.C:420
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::InjectionModel::massTotal_
scalar massTotal_
Total mass to inject [kg].
Definition: InjectionModel.H:109
os
OBJstream os(runTime.globalPath()/outputName)
Foam::InjectionModel::pbMass
Definition: InjectionModel.H:90
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::InjectionModel::parcelsAddedTotal_
label parcelsAddedTotal_
Running counter of total number of parcels added.
Definition: InjectionModel.H:124
Foam::subModelBase::modelType
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:125
IOdictionary.H
Foam::InjectionModel::~InjectionModel
virtual ~InjectionModel()=default
Destructor.
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::cloud
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:57
Foam::InjectionModel::ignoreOutOfBounds_
bool ignoreOutOfBounds_
Definition: InjectionModel.H:155
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::InjectionModel::inject
void inject(TrackCloudType &cloud, typename CloudType::parcelType::trackingData &td)
Main injection loop.
Definition: InjectionModel.C:439
Foam::InjectionModel::parcelType
CloudType::parcelType parcelType
Convenience typedef for parcelType.
Definition: InjectionModel.H:80
Foam::Vector< scalar >
Foam::InjectionModel::pbFixed
Definition: InjectionModel.H:91
Foam::InjectionModel::SOI_
scalar SOI_
Start of injection [s].
Definition: InjectionModel.H:102
vector.H
Foam::InjectionModel::setProperties
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, parcelType &parcel)=0
Set the parcel properties.
Foam::InjectionModel::volumeTotal
scalar volumeTotal() const
Return the total volume to be injected across the event.
Definition: InjectionModelI.H:41
Foam::DSMCCloud::parcelType
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:220
Foam::InjectionModel::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, InjectionModel, dictionary,(const dictionary &dict, CloudType &owner, const word &modelType),(dict, owner, modelType))
Declare runtime constructor selection table.
Foam::InjectionModel::timeEnd
virtual scalar timeEnd() const =0
Return the end-of-injection time.
Foam::InjectionModel::TypeName
TypeName("injectionModel")
Runtime type information.
Foam::InjectionModel::nInjections_
label nInjections_
Number of injections counter.
Definition: InjectionModel.H:121
Foam::InjectionModel::New
static autoPtr< InjectionModel< CloudType > > New(const dictionary &dict, CloudType &owner)
Selector with lookup from dictionary.
Definition: InjectionModelNew.C:36
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::InjectionModel::parcelBasis_
parcelBasis parcelBasis_
Parcel basis enumeration.
Definition: InjectionModel.H:130
InjectionModel.C
Foam::InjectionModel::nParticleFixed_
scalar nParticleFixed_
Definition: InjectionModel.H:134
autoPtr.H