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-2020 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 "IOdictionary.H"
52 #include "autoPtr.H"
53 #include "runTimeSelectionTables.H"
54 #include "CloudSubModelBase.H"
55 #include "vector.H"
56 #include "TimeFunction1.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 /*---------------------------------------------------------------------------*\
64  Class InjectionModel Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 template<class CloudType>
68 class InjectionModel
69 :
70  public CloudSubModelBase<CloudType>
71 {
72 public:
73 
74  //- Convenience typedef for parcelType
75  typedef typename CloudType::parcelType parcelType;
76 
77 
78  // Enumerations
79 
80  //- Parcel basis representation options
81  // i.e constant number of particles OR constant mass per parcel
82  enum parcelBasis
83  {
86  pbFixed
87  };
88 
89 
90 protected:
91 
92  // Protected data
93 
94  // Global injection properties
95 
96  //- Start of injection [s]
97  scalar SOI_;
98 
99  //- Total volume of particles introduced by this injector [m^3]
100  // - scaled to ensure massTotal is achieved
101  scalar volumeTotal_;
102 
103  //- Total mass to inject [kg]
104  scalar massTotal_;
105 
106  //- Mass flow rate profile for steady calculations
108 
109  //- Total mass injected to date [kg]
110  scalar massInjected_;
111 
112 
113  // Counters
114 
115  //- Number of injections counter
117 
118  //- Running counter of total number of parcels added
120 
121 
122  // Injection properties per Lagrangian time step
123 
124  //- Parcel basis enumeration
126 
127  //- nParticle to assign to parcels when the 'fixed' basis
128  // is selected
129  scalar nParticleFixed_;
130 
131  //- Continuous phase time at start of injection time step [s]
132  scalar time0_;
133 
134  //- Time at start of injection time step [s]
135  scalar timeStep0_;
136 
137 
138  // Protected Member Functions
139 
140  //- Additional flag to identify whether or not injection of parcelI is
141  // permitted
142  virtual bool validInjection(const label parcelI) = 0;
143 
144  //- Determine properties for next time step/injection interval
145  virtual bool prepareForNextTimeStep
146  (
147  const scalar time,
148  label& newParcels,
149  scalar& newVolumeFraction
150  );
151 
152  //- Find the cell that contains the supplied position
153  // Will modify position slightly towards the owner cell centroid to
154  // ensure that it lies in a cell and not edge/face
155  virtual bool findCellAtPosition
156  (
157  label& celli,
158  label& tetFacei,
159  label& tetPti,
160  vector& position,
161  bool errorOnNotFound = true
162  );
163 
164  //- Set number of particles to inject given parcel properties
165  virtual scalar setNumberOfParticles
166  (
167  const label parcels,
168  const scalar volumeFraction,
169  const scalar diameter,
170  const scalar rho
171  );
172 
173  //- Post injection checks
174  virtual void postInjectCheck
175  (
176  const label parcelsAdded,
177  const scalar massAdded
178  );
179 
180 
181 public:
182 
183  //- Runtime type information
184  TypeName("injectionModel");
185 
186  //- Declare runtime constructor selection table
188  (
189  autoPtr,
191  dictionary,
192  (
193  const dictionary& dict,
194  CloudType& owner,
195  const word& modelType
196  ),
197  (dict, owner, modelType)
198  );
199 
200 
201  // Constructors
202 
203  //- Construct null from owner
204  InjectionModel(CloudType& owner);
205 
206  //- Construct from dictionary
208  (
209  const dictionary& dict,
210  CloudType& owner,
211  const word& modelName,
212  const word& modelType
213  );
214 
215  //- Construct copy
217 
218  //- Construct and return a clone
219  virtual autoPtr<InjectionModel<CloudType>> clone() const = 0;
220 
221 
222  //- Destructor
223  virtual ~InjectionModel();
224 
225 
226  // Selectors
227 
228  //- Selector with lookup from dictionary
230  (
231  const dictionary& dict,
232  CloudType& owner
233  );
234 
235  //- Selector with name and type
237  (
238  const dictionary& dict,
239  const word& modelName,
240  const word& modelType,
241  CloudType& owner
242  );
243 
244 
245  // Member Functions
246 
247  // Mapping
248 
249  //- Update mesh
250  virtual void updateMesh();
251 
252 
253  // Global information
254 
255  //- Return the start-of-injection time
256  inline scalar timeStart() const;
257 
258  //- Return the total volume to be injected across the event
259  inline scalar volumeTotal() const;
260 
261  //- Return mass of particles to introduce
262  inline scalar massTotal() const;
263 
264  //- Return mass of particles injected (cumulative)
265  inline scalar massInjected() const;
266 
267  //- Return the end-of-injection time
268  virtual scalar timeEnd() const = 0;
269 
270  //- Number of parcels to introduce relative to SOI
271  virtual label parcelsToInject
272  (
273  const scalar time0,
274  const scalar time1
275  ) = 0;
276 
277  //- Volume of parcels to introduce relative to SOI
278  virtual scalar volumeToInject
279  (
280  const scalar time0,
281  const scalar time1
282  ) = 0;
283 
284  //- Return the average parcel mass over the injection period
285  virtual scalar averageParcelMass();
286 
287 
288  // Counters
289 
290  //- Return the number of injections
291  inline label nInjections() const;
292 
293  //- Return the total number parcels added
294  inline label parcelsAddedTotal() const;
295 
296 
297  // Per-injection event functions
298 
299  //- Main injection loop
300  template<class TrackCloudType>
301  void inject
302  (
303  TrackCloudType& cloud,
304  typename CloudType::parcelType::trackingData& td
305  );
306 
307  //- Main injection loop - steady-state
308  template<class TrackCloudType>
309  void injectSteadyState
310  (
311  TrackCloudType& cloud,
312  typename CloudType::parcelType::trackingData& td,
313  const scalar trackTime
314  );
315 
316 
317  // Injection geometry
318 
319  //- Set the injection position and owner cell, tetFace and tetPt
320  virtual void setPositionAndCell
321  (
322  const label parcelI,
323  const label nParcels,
324  const scalar time,
325  vector& position,
326  label& cellOwner,
327  label& tetFacei,
328  label& tetPti
329  ) = 0;
330 
331  //- Set the parcel properties
332  virtual void setProperties
333  (
334  const label parcelI,
335  const label nParcels,
336  const scalar time,
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 #define makeInjectionModel(CloudType) \
358  \
359  typedef Foam::CloudType::momentumCloudType momentumCloudType; \
360  defineNamedTemplateTypeNameAndDebug \
361  ( \
362  Foam::InjectionModel<momentumCloudType>, \
363  0 \
364  ); \
365  \
366  namespace Foam \
367  { \
368  defineTemplateRunTimeSelectionTable \
369  ( \
370  InjectionModel<momentumCloudType>, \
371  dictionary \
372  ); \
373  }
374 
376 #define makeInjectionModelType(SS, CloudType) \
377  \
378  typedef Foam::CloudType::momentumCloudType momentumCloudType; \
379  defineNamedTemplateTypeNameAndDebug(Foam::SS<momentumCloudType>, 0); \
380  \
381  Foam::InjectionModel<momentumCloudType>:: \
382  adddictionaryConstructorToTable<Foam::SS<momentumCloudType>> \
383  add##SS##CloudType##momentumCloudType##ConstructorToTable_;
384 
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 #include "InjectionModelI.H"
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #ifdef NoRepository
393  #include "InjectionModel.C"
394 #endif
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 #endif
399 
400 // ************************************************************************* //
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.
scalar massTotal_
Total mass to inject [kg].
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
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.
virtual scalar averageParcelMass()
Return the average parcel mass over the injection period.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Templated injection model class.
CloudType::parcelType parcelType
Convenience typedef for parcelType.
label parcelsAddedTotal_
Running counter of total number of parcels added.
scalar SOI_
Start of injection [s].
Base class for cloud sub-models.
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:104
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:110
virtual ~InjectionModel()
Destructor.
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
label nInjections_
Number of injections counter.
A class for handling words, derived from string.
Definition: word.H:59
virtual void info(Ostream &os)
Write injection info to stream.
A cloud is a collection of lagrangian particles.
Definition: cloud.H:51
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.
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:221
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
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:122
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].
scalar timeStep0_
Time at start of injection time step [s].
label nInjections() const
Return the number of injections.
TimeFunction1< scalar > massFlowRate_
Mass flow rate profile for steady calculations.
virtual bool fullyDescribed() const =0
Flag to identify whether model fully describes the parcel.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
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].
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:75
virtual scalar volumeToInject(const scalar time0, const scalar time1)=0
Volume of parcels to introduce relative to SOI.
Namespace for OpenFOAM.