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 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 "TimeFunction1.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
123 
124  //- Running counter of total number of parcels added
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
153 
154 
155  // Protected Member Functions
156 
157  //- Additional flag to identify whether or not injection of parcelI is
158  // permitted
159  virtual bool validInjection(const label parcelI) = 0;
160 
161  //- Determine properties for next time step/injection interval
162  virtual bool prepareForNextTimeStep
163  (
164  const scalar time,
165  label& newParcels,
166  scalar& newVolumeFraction
167  );
168 
169  //- Find the cell that contains the supplied position
170  // Will modify position slightly towards the owner cell centroid to
171  // ensure that it lies in a cell and not edge/face
172  virtual bool findCellAtPosition
173  (
174  label& celli,
175  label& tetFacei,
176  label& tetPti,
177  vector& position,
178  bool errorOnNotFound = true
179  );
180 
181  //- Set number of particles to inject given parcel properties
182  virtual scalar setNumberOfParticles
183  (
184  const label parcels,
185  const scalar volumeFraction,
186  const scalar diameter,
187  const scalar rho
188  );
189 
190  //- Post injection checks
191  virtual void postInjectCheck
192  (
193  const label parcelsAdded,
194  const scalar massAdded
195  );
196 
197 
198 public:
199 
200  //- Runtime type information
201  TypeName("injectionModel");
202 
203  //- Declare runtime constructor selection table
205  (
206  autoPtr,
208  dictionary,
209  (
210  const dictionary& dict,
211  CloudType& owner,
212  const word& modelType
213  ),
214  (dict, owner, modelType)
215  );
216 
217 
218  // Constructors
219 
220  //- Construct null from owner
222 
223  //- Construct from dictionary
225  (
226  const dictionary& dict,
227  CloudType& owner,
228  const word& modelName,
229  const word& modelType
230  );
231 
232  //- Construct copy
234 
235  //- Construct and return a clone
236  virtual autoPtr<InjectionModel<CloudType>> clone() const = 0;
237 
238 
239  //- Destructor
240  virtual ~InjectionModel();
241 
242 
243  // Selectors
244 
245  //- Selector with lookup from dictionary
247  (
248  const dictionary& dict,
250  );
251 
252  //- Selector with name and type
254  (
255  const dictionary& dict,
256  const word& modelName,
257  const word& modelType,
259  );
260 
261 
262  // Member Functions
263 
264  // Mapping
265 
266  //- Update mesh
267  virtual void updateMesh();
268 
269 
270  // Global information
271 
272  //- Return the start-of-injection time
273  inline scalar timeStart() const;
274 
275  //- Return the total volume to be injected across the event
276  inline scalar volumeTotal() const;
277 
278  //- Return mass of particles to introduce
279  inline scalar massTotal() const;
280 
281  //- Return mass of particles injected (cumulative)
282  inline scalar massInjected() const;
283 
284  //- Return injectorID
285  inline label injectorID() const;
286 
287  //- Return the end-of-injection time
288  virtual scalar timeEnd() const = 0;
289 
290  //- Number of parcels to introduce relative to SOI
291  virtual label parcelsToInject
292  (
293  const scalar time0,
294  const scalar time1
295  ) = 0;
296 
297  //- Volume of parcels to introduce relative to SOI
298  virtual scalar volumeToInject
299  (
300  const scalar time0,
301  const scalar time1
302  ) = 0;
303 
304  //- Return the average parcel mass over the injection period
305  virtual scalar averageParcelMass();
306 
307 
308  // Counters
309 
310  //- Return the number of injections
311  inline label nInjections() const;
312 
313  //- Return the total number parcels added
314  inline label parcelsAddedTotal() const;
315 
316 
317  // Per-injection event functions
318 
319  //- Main injection loop
320  template<class TrackCloudType>
321  void inject
322  (
323  TrackCloudType& cloud,
324  typename CloudType::parcelType::trackingData& td
325  );
326 
327  //- Main injection loop - steady-state
328  template<class TrackCloudType>
329  void injectSteadyState
330  (
331  TrackCloudType& cloud,
332  typename CloudType::parcelType::trackingData& td,
333  const scalar trackTime
334  );
335 
336 
337  // Injection geometry
338 
339  //- Set the injection position and owner cell, tetFace and tetPt
340  virtual void setPositionAndCell
341  (
342  const label parcelI,
343  const label nParcels,
344  const scalar time,
345  vector& position,
346  label& cellOwner,
347  label& tetFacei,
348  label& tetPti
349  ) = 0;
350 
351  //- Set the parcel properties
352  virtual void setProperties
353  (
354  const label parcelI,
355  const label nParcels,
356  const scalar time,
357  parcelType& parcel
358  ) = 0;
359 
360  //- Flag to identify whether model fully describes the parcel
361  virtual bool fullyDescribed() const = 0;
362 
363 
364  // I-O
365 
366  //- Write injection info to stream
367  virtual void info(Ostream& os);
368 };
369 
370 
371 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
372 
373 } // End namespace Foam
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 #define makeInjectionModel(CloudType) \
378  \
379  typedef Foam::CloudType::kinematicCloudType kinematicCloudType; \
380  defineNamedTemplateTypeNameAndDebug \
381  ( \
382  Foam::InjectionModel<kinematicCloudType>, \
383  0 \
384  ); \
385  \
386  namespace Foam \
387  { \
388  defineTemplateRunTimeSelectionTable \
389  ( \
390  InjectionModel<kinematicCloudType>, \
391  dictionary \
392  ); \
393  }
394 
395 
396 #define makeInjectionModelType(SS, CloudType) \
397  \
398  typedef Foam::CloudType::kinematicCloudType kinematicCloudType; \
399  defineNamedTemplateTypeNameAndDebug(Foam::SS<kinematicCloudType>, 0); \
400  \
401  Foam::InjectionModel<kinematicCloudType>:: \
402  adddictionaryConstructorToTable<Foam::SS<kinematicCloudType>> \
403  add##SS##CloudType##kinematicCloudType##ConstructorToTable_;
404 
405 
406 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
407 
408 #include "InjectionModelI.H"
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 #ifdef NoRepository
413  #include "InjectionModel.C"
414 #endif
415 
416 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
417 
418 #endif
419 
420 // ************************************************************************* //
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:662
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:96
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:264
Foam::InjectionModel::updateMesh
virtual void updateMesh()
Update mesh.
Definition: InjectionModel.C:408
InjectionModelI.H
Foam::InjectionModel::massFlowRate_
TimeFunction1< scalar > massFlowRate_
Mass flow rate profile for steady calculations.
Definition: InjectionModel.H:112
Foam::InjectionModel
Templated injection model class.
Definition: InjectionModel.H:73
Foam::CloudSubModelBase
Base class for cloud sub-models.
Definition: CloudSubModelBase.H:51
Foam::TimeFunction1< scalar >
Foam::InjectionModel::prepareForNextTimeStep
virtual bool prepareForNextTimeStep(const scalar time, label &newParcels, scalar &newVolumeFraction)
Determine properties for next time step/injection interval.
Definition: InjectionModel.C:40
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:189
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:96
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::label
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:62
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:562
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:232
Foam::InjectionModel::averageParcelMass
virtual scalar averageParcelMass()
Return the average parcel mass over the injection period.
Definition: InjectionModel.C:413
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::InjectionModel::massTotal_
scalar massTotal_
Total mass to inject [kg].
Definition: InjectionModel.H:109
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::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
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:432
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::~InjectionModel
virtual ~InjectionModel()
Destructor.
Definition: InjectionModel.C:401
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
TimeFunction1.H
InjectionModel.C
Foam::InjectionModel::nParticleFixed_
scalar nParticleFixed_
Definition: InjectionModel.H:134
autoPtr.H