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-2024 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  fullyDescribed() flag should be set to 1 (true).
40 
41 SourceFiles
42  InjectionModel.C
43  InjectionModelNew.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef InjectionModel_H
48 #define InjectionModel_H
49 
50 #include "injectionModel.H"
51 #include "CloudSubModelBase.H"
52 #include "particle.H"
53 #include "Function1.H"
54 #include "runTimeSelectionTables.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class InjectionModel Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class CloudType>
66 class InjectionModel
67 :
68  public injectionModel,
69  public CloudSubModelBase<CloudType>
70 {
71 public:
72 
73  //- Convenience typedef for parcelType
74  typedef typename CloudType::parcelType parcelType;
75 
76 
77 protected:
78 
79  // Protected data
80 
81  // Global injection properties
82 
83  //- Start of injection [s]
84  scalar SOI_;
85 
86  //- Total mass injected to date [kg]
87  scalar massInjected_;
88 
89 
90  // Counters
91 
92  //- Number of injections counter
94 
95  //- Running counter of total number of parcels added
97 
98 
99  // Injection properties per Lagrangian time step
100 
101  //- Fixed nParticle to assign to parcels. Only valid if
102  // uniformParcelSize is nParticle.
103  scalar nParticleFixed_;
104 
105  //- Size uniform to all parcels
107 
108  //- Continuous phase time at start of injection time step [s]
109  scalar time0_;
110 
111  //- Time at start of injection time step [s]
112  scalar timeStep0_;
113 
114 
115  // Protected Member Functions
116 
117  //- Read the total mass value for instantaneous injections
118  scalar readMassTotal
119  (
120  const dictionary& dict,
122  );
123 
124  //- Read the duration for continuous injections
125  scalar readDuration
126  (
127  const dictionary& dict,
129  );
130 
131  //- Read the mass flow rate function for continuous injections
133  (
134  const dictionary& dict,
135  CloudType& owner,
136  const scalar duration
137  );
138 
139  //- Read the number of parcels injected per second for continuous
140  // injections
142  (
143  const dictionary& dict,
145  );
146 
147  //- Get the index of this injector
148  label index() const;
149 
150  //- Find the cell that contains the supplied position
151  // Will modify position slightly towards the owner cell centroid to
152  // ensure that it lies in a cell and not edge/face
153  bool findCellAtPosition
154  (
155  const point& position,
156  barycentric& coordinates,
157  label& celli,
158  label& tetFacei,
159  label& tetPti,
160  bool errorOnNotFound = true
161  );
162 
163  //- Constrain a parcel's position appropriately to the geometric
164  // dimensions of the mesh
165  void constrainPosition
166  (
167  typename CloudType::parcelType::trackingData& td,
168  typename CloudType::parcelType& parcel
169  );
170 
171  //- Return the sampling moment to be used by the size distribution
172  label sizeSampleQ() const;
173 
174  //- Set number of particles to inject given parcel properties
176  (
177  PtrList<parcelType>& parcelPtrs,
178  const scalar mass
179  ) const;
180 
181  //- Pre injection hook
182  virtual void preInject
183  (
184  typename parcelType::trackingData& td
185  );
186 
187  //- Post injection hook
188  virtual void postInject
189  (
190  const label parcelsAdded,
191  const scalar massAdded,
192  typename parcelType::trackingData& td
193  );
194 
195 
196 public:
197 
198  //- Runtime type information
199  TypeName("injectionModel");
200 
201  //- Declare runtime constructor selection table
203  (
204  autoPtr,
206  dictionary,
207  (
208  const dictionary& dict,
209  CloudType& owner,
210  const word& modelType
211  ),
212  (dict, owner, modelType)
213  );
214 
215 
216  // Constructors
217 
218  //- Construct null from owner
220 
221  //- Construct from dictionary
223  (
224  const dictionary& dict,
225  CloudType& owner,
226  const word& modelName,
227  const word& modelType
228  );
229 
230  //- Construct copy
232 
233  //- Construct and return a clone
234  virtual autoPtr<InjectionModel<CloudType>> clone() const = 0;
235 
236 
237  //- Destructor
238  virtual ~InjectionModel();
239 
240 
241  // Selectors
242 
243  //- Selector with lookup from dictionary
245  (
246  const dictionary& dict,
248  );
249 
250  //- Selector with name and type
252  (
253  const dictionary& dict,
254  const word& modelName,
255  const word& modelType,
257  );
258 
259 
260  // Member Functions
261 
262  // Mapping
263 
264  //- Update mesh
265  virtual void topoChange();
266 
267 
268  // Global information
269 
270  //- Return the start-of-injection time
271  inline scalar timeStart() const;
272 
273  //- Return mass of particles injected (cumulative)
274  inline scalar massInjected() const;
275 
276  //- Return the end-of-injection time
277  virtual scalar timeEnd() const = 0;
278 
279  //- Number of parcels to introduce relative to SOI
280  virtual label nParcelsToInject
281  (
282  const scalar time0,
283  const scalar time1
284  ) = 0;
285 
286  //- Parcel mass to introduce relative to SOI
287  virtual scalar massToInject
288  (
289  const scalar time0,
290  const scalar time1
291  ) = 0;
292 
293  //- Return the average injected parcel mass
294  scalar averageParcelMass();
295 
296 
297  // Counters
298 
299  //- Return the number of injections
300  inline label nInjections() const;
301 
302  //- Return the total number parcels added
303  inline label parcelsAddedTotal() const;
304 
305 
306  // Per-injection event functions
307 
308  //- Main injection loop
309  template<class TrackCloudType>
310  void inject
311  (
312  TrackCloudType& cloud,
313  typename CloudType::parcelType::trackingData& td
314  );
315 
316  //- Main injection loop - steady-state
317  template<class TrackCloudType>
318  void injectSteadyState
319  (
320  TrackCloudType& cloud,
321  typename CloudType::parcelType::trackingData& td
322  );
323 
324 
325  // Injection geometry
326 
327  //- Set the injection position and owner cell, tetFace and tetPt
328  virtual void setPositionAndCell
329  (
330  const label parcelI,
331  const label nParcels,
332  const scalar time,
333  barycentric& coordinates,
334  label& celli,
335  label& tetFacei,
336  label& tetPti,
337  label& facei
338  ) = 0;
339 
340  //- Set the parcel properties
341  virtual void setProperties
342  (
343  const label parcelI,
344  const label nParcels,
345  const scalar time,
346  typename parcelType::trackingData& td,
347  parcelType& parcel
348  ) = 0;
349 
350  //- Flag to identify whether model fully describes the parcel
351  virtual bool fullyDescribed() const = 0;
352 
353 
354  // I-O
355 
356  //- Write injection info to stream
357  virtual void info(Ostream& os);
358 };
359 
360 
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
362 
363 } // End namespace Foam
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 #define makeInjectionModel(CloudType) \
368  \
369  typedef Foam::CloudType::momentumCloudType momentumCloudType; \
370  defineNamedTemplateTypeNameAndDebug \
371  ( \
372  Foam::InjectionModel<momentumCloudType>, \
373  0 \
374  ); \
375  \
376  namespace Foam \
377  { \
378  defineTemplateRunTimeSelectionTable \
379  ( \
380  InjectionModel<momentumCloudType>, \
381  dictionary \
382  ); \
383  }
384 
385 
386 #define makeInjectionModelType(SS, CloudType) \
387  \
388  typedef Foam::CloudType::momentumCloudType momentumCloudType; \
389  defineNamedTemplateTypeNameAndDebug(Foam::SS<momentumCloudType>, 0); \
390  \
391  Foam::InjectionModel<momentumCloudType>:: \
392  adddictionaryConstructorToTable<Foam::SS<momentumCloudType>> \
393  add##SS##CloudType##momentumCloudType##ConstructorToTable_;
394 
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 #include "InjectionModelI.H"
399 
400 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
401 
402 #ifdef NoRepository
403  #include "InjectionModel.C"
404 #endif
405 
406 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
407 
408 #endif
409 
410 // ************************************************************************* //
Base class for cloud sub-models.
const CloudType & owner() const
Return const access to the owner cloud.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:225
Templated injection model class.
virtual bool fullyDescribed() const =0
Flag to identify whether model fully describes the parcel.
virtual void setPositionAndCell(const label parcelI, const label nParcels, const scalar time, barycentric &coordinates, label &celli, label &tetFacei, label &tetPti, label &facei)=0
Set the injection position and owner cell, tetFace and tetPt.
scalar timeStep0_
Time at start of injection time step [s].
virtual void topoChange()
Update mesh.
virtual scalar timeEnd() const =0
Return the end-of-injection time.
virtual ~InjectionModel()
Destructor.
void inject(TrackCloudType &cloud, typename CloudType::parcelType::trackingData &td)
Main injection loop.
autoPtr< Function1< scalar > > readParcelsPerSecond(const dictionary &dict, CloudType &owner)
Read the number of parcels injected per second for continuous.
void constrainPosition(typename CloudType::parcelType::trackingData &td, typename CloudType::parcelType &parcel)
Constrain a parcel's position appropriately to the geometric.
virtual void postInject(const label parcelsAdded, const scalar massAdded, typename parcelType::trackingData &td)
Post injection hook.
virtual void preInject(typename parcelType::trackingData &td)
Pre injection hook.
TypeName("injectionModel")
Runtime type information.
bool findCellAtPosition(const point &position, barycentric &coordinates, label &celli, label &tetFacei, label &tetPti, bool errorOnNotFound=true)
Find the cell that contains the supplied position.
scalar readMassTotal(const dictionary &dict, CloudType &owner)
Read the total mass value for instantaneous injections.
virtual void info(Ostream &os)
Write injection info to stream.
scalar timeStart() const
Return the start-of-injection time.
void setNumberOfParticles(PtrList< parcelType > &parcelPtrs, const scalar mass) const
Set number of particles to inject given parcel properties.
autoPtr< Function1< scalar > > readMassFlowRate(const dictionary &dict, CloudType &owner, const scalar duration)
Read the mass flow rate function for continuous injections.
uniformParcelSize uniformParcelSize_
Size uniform to all parcels.
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, typename parcelType::trackingData &td, parcelType &parcel)=0
Set the parcel properties.
virtual scalar massToInject(const scalar time0, const scalar time1)=0
Parcel mass to introduce relative to SOI.
label sizeSampleQ() const
Return the sampling moment to be used by the size distribution.
static autoPtr< InjectionModel< CloudType > > New(const dictionary &dict, CloudType &owner)
Selector with lookup from dictionary.
scalar averageParcelMass()
Return the average injected parcel mass.
declareRunTimeSelectionTable(autoPtr, InjectionModel, dictionary,(const dictionary &dict, CloudType &owner, const word &modelType),(dict, owner, modelType))
Declare runtime constructor selection table.
scalar nParticleFixed_
Fixed nParticle to assign to parcels. Only valid if.
label index() const
Get the index of this injector.
void injectSteadyState(TrackCloudType &cloud, typename CloudType::parcelType::trackingData &td)
Main injection loop - steady-state.
scalar readDuration(const dictionary &dict, CloudType &owner)
Read the duration for continuous injections.
label parcelsAddedTotal() const
Return the total number parcels added.
scalar massInjected() const
Return mass of particles injected (cumulative)
virtual autoPtr< InjectionModel< CloudType > > clone() const =0
Construct and return a clone.
virtual label nParcelsToInject(const scalar time0, const scalar time1)=0
Number of parcels to introduce relative to SOI.
label nInjections_
Number of injections counter.
InjectionModel(CloudType &owner)
Construct null from owner.
label parcelsAddedTotal_
Running counter of total number of parcels added.
CloudType::parcelType parcelType
Convenience typedef for parcelType.
scalar time0_
Continuous phase time at start of injection time step [s].
scalar SOI_
Start of injection [s].
label nInjections() const
Return the number of injections.
scalar massInjected_
Total mass injected to date [kg].
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A cloud is a collection of lagrangian particles.
Definition: cloud.H:55
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Non-templated base class for lagrangian injection models.
uniformParcelSize
Enumeration for the parcels' uniform size.
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:110
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:104
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:122
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
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
Macros to ease declaration of run-time selection tables.