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 | Copyright (C) 2011-2015 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 "TimeDataEntry.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  //- Volume that should have been injected, but would lead to
138  // less than 1 particle per parcel
139  scalar delayedVolume_;
140 
141 
142  // Protected Member Functions
143 
144  //- Additional flag to identify whether or not injection of parcelI is
145  // permitted
146  virtual bool validInjection(const label parcelI) = 0;
147 
148  //- Determine properties for next time step/injection interval
149  virtual bool prepareForNextTimeStep
150  (
151  const scalar time,
152  label& newParcels,
153  scalar& newVolumeFraction
154  );
155 
156  //- Find the cell that contains the supplied position
157  // Will modify position slightly towards the owner cell centroid to
158  // ensure that it lies in a cell and not edge/face
159  virtual bool findCellAtPosition
160  (
161  label& cellI,
162  label& tetFaceI,
163  label& tetPtI,
164  vector& position,
165  bool errorOnNotFound = true
166  );
167 
168  //- Set number of particles to inject given parcel properties
169  virtual scalar setNumberOfParticles
170  (
171  const label parcels,
172  const scalar volumeFraction,
173  const scalar diameter,
174  const scalar rho
175  );
176 
177  //- Post injection checks
178  virtual void postInjectCheck
179  (
180  const label parcelsAdded,
181  const scalar massAdded
182  );
183 
184 
185 public:
186 
187  //- Runtime type information
188  TypeName("injectionModel");
189 
190  //- Declare runtime constructor selection table
192  (
193  autoPtr,
195  dictionary,
196  (
197  const dictionary& dict,
198  CloudType& owner,
199  const word& modelType
200  ),
201  (dict, owner, modelType)
202  );
203 
204 
205  // Constructors
206 
207  //- Construct null from owner
208  InjectionModel(CloudType& owner);
209 
210  //- Construct from dictionary
212  (
213  const dictionary& dict,
214  CloudType& owner,
215  const word& modelName,
216  const word& modelType
217  );
218 
219  //- Construct copy
221 
222  //- Construct and return a clone
223  virtual autoPtr<InjectionModel<CloudType> > clone() const = 0;
224 
225 
226  //- Destructor
227  virtual ~InjectionModel();
228 
229 
230  // Selectors
231 
232  //- Selector with lookup from dictionary
234  (
235  const dictionary& dict,
236  CloudType& owner
237  );
238 
239  //- Selector with name and type
241  (
242  const dictionary& dict,
243  const word& modelName,
244  const word& modelType,
245  CloudType& owner
246  );
247 
248 
249  // Member Functions
250 
251  // Mapping
252 
253  //- Update mesh
254  virtual void updateMesh();
255 
256 
257  // Global information
258 
259  //- Return the start-of-injection time
260  inline scalar timeStart() const;
261 
262  //- Return the total volume to be injected across the event
263  inline scalar volumeTotal() const;
264 
265  //- Return mass of particles to introduce
266  inline scalar massTotal() const;
267 
268  //- Return mass of particles injected (cumulative)
269  inline scalar massInjected() const;
270 
271  //- Return the end-of-injection time
272  virtual scalar timeEnd() const = 0;
273 
274  //- Number of parcels to introduce relative to SOI
275  virtual label parcelsToInject
276  (
277  const scalar time0,
278  const scalar time1
279  ) = 0;
280 
281  //- Volume of parcels to introduce relative to SOI
282  virtual scalar volumeToInject
283  (
284  const scalar time0,
285  const scalar time1
286  ) = 0;
287 
288  //- Return the average parcel mass over the injection period
289  virtual scalar averageParcelMass();
290 
291 
292  // Counters
293 
294  //- Return the number of injections
295  inline label nInjections() const;
296 
297  //- Return the total number parcels added
298  inline label parcelsAddedTotal() const;
299 
300 
301  // Per-injection event functions
302 
303  //- Main injection loop
304  template<class TrackData>
305  void inject(TrackData& td);
306 
307  //- Main injection loop - steady-state
308  template<class TrackData>
309  void injectSteadyState(TrackData& td, const scalar trackTime);
310 
311 
312  // Injection geometry
313 
314  //- Set the injection position and owner cell, tetFace and tetPt
315  virtual void setPositionAndCell
316  (
317  const label parcelI,
318  const label nParcels,
319  const scalar time,
320  vector& position,
321  label& cellOwner,
322  label& tetFaceI,
323  label& tetPtI
324  ) = 0;
325 
326  //- Set the parcel properties
327  virtual void setProperties
328  (
329  const label parcelI,
330  const label nParcels,
331  const scalar time,
332  parcelType& parcel
333  ) = 0;
334 
335  //- Flag to identify whether model fully describes the parcel
336  virtual bool fullyDescribed() const = 0;
337 
338 
339  // I-O
340 
341  //- Write injection info to stream
342  virtual void info(Ostream& os);
343 };
344 
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 } // End namespace Foam
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 #define makeInjectionModel(CloudType) \
353  \
354  typedef Foam::CloudType::kinematicCloudType kinematicCloudType; \
355  defineNamedTemplateTypeNameAndDebug \
356  ( \
357  Foam::InjectionModel<kinematicCloudType>, \
358  0 \
359  ); \
360  \
361  namespace Foam \
362  { \
363  defineTemplateRunTimeSelectionTable \
364  ( \
365  InjectionModel<kinematicCloudType>, \
366  dictionary \
367  ); \
368  }
369 
371 #define makeInjectionModelType(SS, CloudType) \
372  \
373  typedef Foam::CloudType::kinematicCloudType kinematicCloudType; \
374  defineNamedTemplateTypeNameAndDebug(Foam::SS<kinematicCloudType>, 0); \
375  \
376  Foam::InjectionModel<kinematicCloudType>:: \
377  adddictionaryConstructorToTable<Foam::SS<kinematicCloudType> > \
378  add##SS##CloudType##kinematicCloudType##ConstructorToTable_;
379 
380 
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
382 
383 #include "InjectionModelI.H"
384 
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 
387 #ifdef NoRepository
388 # include "InjectionModel.C"
389 #endif
390 
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
392 
393 #endif
394 
395 // ************************************************************************* //
virtual void postInjectCheck(const label parcelsAdded, const scalar massAdded)
Post injection checks.
static autoPtr< InjectionModel< CloudType > > New(const dictionary &dict, CloudType &owner)
Selector with lookup from dictionary.
scalar delayedVolume_
Volume that should have been injected, but would lead to.
const CloudType & owner() const
Return const access to the owner cloud.
scalar timeStart() const
Return the start-of-injection time.
parcelBasis parcelBasis_
Parcel basis enumeration.
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:122
label parcelsAddedTotal_
Running counter of total number of parcels added.
virtual bool fullyDescribed() const =0
Flag to identify whether model fully describes the parcel.
virtual scalar setNumberOfParticles(const label parcels, const scalar volumeFraction, const scalar diameter, const scalar rho)
Set number of particles to inject given parcel properties.
label parcelsAddedTotal() const
Return the total number parcels added.
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.
void injectSteadyState(TrackData &td, const scalar trackTime)
Main injection loop - steady-state.
declareRunTimeSelectionTable(autoPtr, InjectionModel, dictionary,( const dictionary &dict, CloudType &owner, const word &modelType ),(dict, owner, modelType))
Declare runtime constructor selection table.
virtual void info(Ostream &os)
Write injection info to stream.
virtual ~InjectionModel()
Destructor.
Macros to ease declaration of run-time selection tables.
virtual void updateMesh()
Update mesh.
label nInjections() const
Return the number of injections.
A class for handling words, derived from string.
Definition: word.H:59
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
virtual bool validInjection(const label parcelI)=0
Additional flag to identify whether or not injection of parcelI is.
scalar volumeTotal() const
Return the total volume to be injected across the event.
scalar massInjected() const
Return mass of particles injected (cumulative)
virtual autoPtr< InjectionModel< CloudType > > clone() const =0
Construct and return a clone.
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:104
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
TimeDataEntry< scalar > massFlowRate_
Mass flow rate profile for steady calculations.
Namespace for OpenFOAM.
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:217
scalar time0_
Continuous phase time at start of injection time step [s].
virtual bool findCellAtPosition(label &cellI, label &tetFaceI, label &tetPtI, vector &position, bool errorOnNotFound=true)
Find the cell that contains the supplied position.
label nInjections_
Number of injections counter.
scalar massTotal() const
Return mass of particles to introduce.
void inject(TrackData &td)
Main injection loop.
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:110
Templated injection model class.
scalar timeStep0_
Time at start of injection time step [s].
InjectionModel(CloudType &owner)
Construct null from owner.
parcelBasis
Parcel basis representation options.
CloudType::parcelType parcelType
Convenience typedef for parcelType.
TypeName("injectionModel")
Runtime type information.
virtual label parcelsToInject(const scalar time0, const scalar time1)=0
Number of parcels to introduce relative to SOI.
scalar massTotal_
Total mass to inject [kg].
scalar massInjected_
Total mass injected to date [kg].
virtual bool prepareForNextTimeStep(const scalar time, label &newParcels, scalar &newVolumeFraction)
Determine properties for next time step/injection interval.
Base class for cloud sub-models.
scalar nParticleFixed_
nParticle to assign to parcels when the &#39;fixed&#39; basis
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, parcelType &parcel)=0
Set the parcel properties.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
scalar volumeTotal_
Total volume of particles introduced by this injector [m^3].
virtual scalar timeEnd() const =0
Return the end-of-injection time.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
virtual scalar volumeToInject(const scalar time0, const scalar time1)=0
Volume of parcels to introduce relative to SOI.
scalar SOI_
Start of injection [s].
virtual scalar averageParcelMass()
Return the average parcel mass over the injection period.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117