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_;
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
121  //- Number of injections counter
122  label nInjections_;
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_;
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_;
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
371  virtual void info();
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 // ************************************************************************* //
virtual autoPtr< InjectionModel< CloudType > > clone() const =0
Construct and return a clone.
scalar massInjected() const
Return mass of particles injected (cumulative)
parcelBasis
Parcel basis representation options i.e constant number of particles OR constant mass per parcel...
scalar massTotal_
Total mass to inject [kg].
void injectSteadyState(TrackCloudType &cloud, typename CloudType::parcelType::trackingData &td, const scalar trackTime)
Main injection loop - steady-state.
scalar time0_
Continuous phase time at start of injection time step [s].
virtual void postInjectCheck(const label parcelsAdded, const scalar massAdded)
Post injection checks.
scalar minParticlesPerParcel_
Minimum number of particles used to represent each parcel default = 1.
virtual scalar averageParcelMass()
Return the average parcel mass over the injection period.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Templated injection model class.
CloudType::parcelType parcelType
Convenience typedef for parcelType.
label parcelsAddedTotal_
Running counter of total number of parcels added.
virtual ~InjectionModel()=default
Destructor.
scalar SOI_
Start of injection [s].
Base class for cloud sub-models.
bool ignoreOutOfBounds_
Optional flag to indicate that injections attempted outside the mesh should be ignored.
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, parcelType &parcel)=0
Set the parcel properties.
void inject(TrackCloudType &cloud, typename CloudType::parcelType::trackingData &td)
Main injection loop.
declareRunTimeSelectionTable(autoPtr, InjectionModel, dictionary,(const dictionary &dict, CloudType &owner, const word &modelType),(dict, owner, modelType))
Declare runtime constructor selection table.
virtual scalar timeEnd() const =0
Return the end-of-injection time.
scalar volumeTotal() const
Return the total volume to be injected across the event.
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:98
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:104
static autoPtr< InjectionModel< CloudType > > New(const dictionary &dict, CloudType &owner)
Selector with lookup from dictionary.
parcelBasis parcelBasis_
Parcel basis enumeration.
const CloudType & owner() const
Return const access to the owner cloud.
TypeName("injectionModel")
Runtime type information.
scalar nParticleFixed_
nParticle to assign to parcels when the &#39;fixed&#39; basis is selected
label nInjections_
Number of injections counter.
A class for handling words, derived from Foam::string.
Definition: word.H:63
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:53
virtual bool validInjection(const label parcelI)=0
Additional flag to identify whether or not injection of parcelI is.
label parcelsAddedTotal() const
Return the total number parcels added.
scalar massTotal() const
Return mass of particles to introduce.
virtual bool findCellAtPosition(label &celli, label &tetFacei, label &tetPti, vector &position, bool errorOnNotFound=true)
Find the cell that contains the supplied position.
virtual void info()
Write injection info.
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:290
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
InjectionModel(CloudType &owner)
Construct null from owner.
virtual void updateMesh()
Update mesh.
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:116
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.
virtual bool prepareForNextTimeStep(const scalar time, label &newParcels, scalar &newVolumeFraction)
Determine properties for next time step/injection interval.
virtual scalar setNumberOfParticles(const label parcels, const scalar volumeFraction, const scalar diameter, const scalar rho)
Set number of particles to inject given parcel properties.
scalar massInjected_
Total mass injected to date [kg].
autoPtr< Function1< scalar > > massFlowRate_
Mass flow rate profile for steady calculations.
label injectorID_
Optional injector ID.
scalar timeStep0_
Time at start of injection time step [s].
label nInjections() const
Return the number of injections.
scalar delayedVolume_
Volume that should have been injected, but would lead to less than minParticlesPerParcel_ particle pe...
virtual bool fullyDescribed() const =0
Flag to identify whether model fully describes the parcel.
label injectorID() const
Return injectorID.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual label parcelsToInject(const scalar time0, const scalar time1)=0
Number of parcels to introduce relative to SOI.
scalar volumeTotal_
Total volume of particles introduced by this injector [m^3] Note: scaled to ensure massTotal is achie...
Macros to ease declaration of run-time selection tables.
scalar timeStart() const
Return the start-of-injection time.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:67
virtual scalar volumeToInject(const scalar time0, const scalar time1)=0
Volume of parcels to introduce relative to SOI.
Namespace for OpenFOAM.