ReactingLookupTableInjection.C
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-2019 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 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class CloudType>
32 (
33  const dictionary& dict,
34  CloudType& owner,
35  const word& modelName
36 )
37 :
38  InjectionModel<CloudType>(dict, owner, modelName, typeName),
39  inputFileName_(this->coeffDict().lookup("inputFile")),
40  duration_(this->coeffDict().template lookup<scalar>("duration")),
41  parcelsPerSecond_
42  (
43  this->coeffDict().template lookup<scalar>("parcelsPerSecond")
44  ),
45  randomise_(readBool(this->coeffDict().lookup("randomise"))),
46  injectors_
47  (
48  IOobject
49  (
50  inputFileName_,
51  owner.db().time().constant(),
52  owner.db(),
53  IOobject::MUST_READ,
54  IOobject::NO_WRITE
55  )
56  ),
57  injectorCells_(0),
58  injectorTetFaces_(0),
59  injectorTetPts_(0)
60 {
61  duration_ = owner.db().time().userTimeToTime(duration_);
62 
63  // Set/cache the injector cells
64  injectorCells_.setSize(injectors_.size());
65  injectorTetFaces_.setSize(injectors_.size());
66  injectorTetPts_.setSize(injectors_.size());
67 
68  updateMesh();
69 
70  // Determine volume of particles to inject
71  this->volumeTotal_ = 0.0;
72  forAll(injectors_, i)
73  {
74  this->volumeTotal_ += injectors_[i].mDot()/injectors_[i].rho();
75  }
76  this->volumeTotal_ *= duration_;
77 }
78 
79 
80 template<class CloudType>
82 (
84 )
85 :
87  inputFileName_(im.inputFileName_),
88  duration_(im.duration_),
89  parcelsPerSecond_(im.parcelsPerSecond_),
90  randomise_(im.randomise_),
91  injectors_(im.injectors_),
92  injectorCells_(im.injectorCells_),
93  injectorTetFaces_(im.injectorTetFaces_),
94  injectorTetPts_(im.injectorTetPts_)
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
99 
100 template<class CloudType>
102 {}
103 
104 
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 
107 template<class CloudType>
109 {
110  // Set/cache the injector cells
111  forAll(injectors_, i)
112  {
113  this->findCellAtPosition
114  (
115  injectorCells_[i],
116  injectorTetFaces_[i],
117  injectorTetPts_[i],
118  injectors_[i].x()
119  );
120  }
121 }
122 
123 
124 template<class CloudType>
126 {
127  return this->SOI_ + duration_;
128 }
129 
130 
131 template<class CloudType>
133 (
134  const scalar time0,
135  const scalar time1
136 )
137 {
138  if ((time0 >= 0.0) && (time0 < duration_))
139  {
140  return floor(injectorCells_.size()*(time1 - time0)*parcelsPerSecond_);
141  }
142  else
143  {
144  return 0;
145  }
146 }
147 
148 
149 template<class CloudType>
151 (
152  const scalar time0,
153  const scalar time1
154 )
155 {
156  scalar volume = 0.0;
157  if ((time0 >= 0.0) && (time0 < duration_))
158  {
159  forAll(injectors_, i)
160  {
161  volume += injectors_[i].mDot()/injectors_[i].rho()*(time1 - time0);
162  }
163  }
164 
165  return volume;
166 }
167 
168 
169 template<class CloudType>
171 (
172  const label parcelI,
173  const label nParcels,
174  const scalar time,
175  vector& position,
176  label& cellOwner,
177  label& tetFacei,
178  label& tetPti
179 )
180 {
181  label injectorI = 0;
182  if (randomise_)
183  {
184  Random& rnd = this->owner().rndGen();
185  injectorI = rnd.sampleAB<label>(0, injectorCells_.size());
186  }
187  else
188  {
189  injectorI = parcelI*injectorCells_.size()/nParcels;
190  }
191 
192  position = injectors_[injectorI].x();
193  cellOwner = injectorCells_[injectorI];
194  tetFacei = injectorTetFaces_[injectorI];
195  tetPti = injectorTetPts_[injectorI];
196 }
197 
198 
199 template<class CloudType>
201 (
202  const label parcelI,
203  const label nParcels,
204  const scalar,
205  typename CloudType::parcelType& parcel
206 )
207 {
208  label injectorI = parcelI*injectorCells_.size()/nParcels;
209 
210  // set particle velocity
211  parcel.U() = injectors_[injectorI].U();
212 
213  // set particle diameter
214  parcel.d() = injectors_[injectorI].d();
215 
216  // set particle density
217  parcel.rho() = injectors_[injectorI].rho();
218 
219  // set particle temperature
220  parcel.T() = injectors_[injectorI].T();
221 
222  // set particle specific heat capacity
223  parcel.Cp() = injectors_[injectorI].Cp();
224 
225  // set particle component mass fractions
226  parcel.Y() = injectors_[injectorI].Y();
227 }
228 
229 
230 template<class CloudType>
232 {
233  return true;
234 }
235 
236 
237 template<class CloudType>
239 {
240  return true;
241 }
242 
243 
244 // ************************************************************************* //
scalar timeEnd() const
Return the end-of-injection time.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
Templated injection model class.
virtual bool validInjection(const label parcelI)
Return flag to identify whether or not injection of parcelI is.
Type sampleAB(const Type &a, const Type &b)
Advance the state and return a sample of a given type from a.
Definition: RandomI.H:98
virtual void setPositionAndCell(const label parcelI, const label nParcels, const scalar time, vector &position, label &cellOwner, label &tetFacei, label &tetPti)
Set the injection position and owner cell, tetFace and tetPt.
bool readBool(Istream &)
Definition: boolIO.C:60
stressControl lookup("compactNormalStress") >> compactNormalStress
A class for handling words, derived from string.
Definition: word.H:59
Particle injection sources read from look-up table. Each row corresponds to an injection site...
ReactingLookupTableInjection(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
virtual bool fullyDescribed() const
Flag to identify whether model fully describes the parcel.
const Cmpt & x() const
Definition: VectorI.H:75
Random number generator.
Definition: Random.H:57
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, typename CloudType::parcelType &parcel)
Set the parcel properties.
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:215
virtual scalar volumeToInject(const scalar time0, const scalar time1)
Volume of parcels to introduce relative to SOI.
virtual void updateMesh()
Set injector locations when mesh is updated.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:69
virtual label parcelsToInject(const scalar time0, const scalar time1)
Number of parcels to introduce relative to SOI.