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