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-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 \*---------------------------------------------------------------------------*/
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->readDuration(dict, owner)),
41  parcelsPerSecond_(this->readParcelsPerSecond(dict, owner)),
42  randomise_(readBool(this->coeffDict().lookup("randomise"))),
43  injectors_
44  (
45  IOobject
46  (
47  inputFileName_,
48  owner.db().time().constant(),
49  owner.db(),
50  IOobject::MUST_READ,
51  IOobject::NO_WRITE
52  )
53  ),
54  injectorCoordinates_(0),
55  injectorCells_(0),
56  injectorTetFaces_(0),
57  injectorTetPts_(0)
58 {
59  // Set/cache the injector cells
60  injectorCoordinates_.setSize(injectors_.size());
61  injectorCells_.setSize(injectors_.size());
62  injectorTetFaces_.setSize(injectors_.size());
63  injectorTetPts_.setSize(injectors_.size());
64 
65  topoChange();
66 }
67 
68 
69 template<class CloudType>
71 (
73 )
74 :
76  inputFileName_(im.inputFileName_),
77  duration_(im.duration_),
78  parcelsPerSecond_(im.parcelsPerSecond_, false),
79  randomise_(im.randomise_),
80  injectors_(im.injectors_),
81  injectorCoordinates_(im.injectorCoordinates_),
82  injectorCells_(im.injectorCells_),
83  injectorTetFaces_(im.injectorTetFaces_),
84  injectorTetPts_(im.injectorTetPts_)
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
89 
90 template<class CloudType>
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
96 
97 template<class CloudType>
99 {
100  // Set/cache the injector cells
101  forAll(injectors_, i)
102  {
103  this->findCellAtPosition
104  (
105  injectors_[i].x(),
106  injectorCoordinates_[i],
107  injectorCells_[i],
108  injectorTetFaces_[i],
109  injectorTetPts_[i]
110  );
111  }
112 }
113 
114 
115 template<class CloudType>
117 {
118  return this->SOI_ + duration_;
119 }
120 
121 
122 template<class CloudType>
124 (
125  const scalar time0,
126  const scalar time1
127 )
128 {
129  if (time0 >= 0 && time0 < duration_)
130  {
131  return
132  floor
133  (
134  injectorCells_.size()
135  *parcelsPerSecond_->integral(time0, time1)
136  );
137  }
138  else
139  {
140  return 0;
141  }
142 }
143 
144 
145 template<class CloudType>
147 (
148  const scalar time0,
149  const scalar time1
150 )
151 {
152  scalar mass = 0;
153 
154  if (time0 >= 0 && time0 < duration_)
155  {
156  forAll(injectors_, i)
157  {
158  mass += injectors_[i].mDot()*(time1 - time0);
159  }
160  }
161 
162  return mass;
163 }
164 
165 
166 template<class CloudType>
168 (
169  const label parcelI,
170  const label nParcels,
171  const scalar time,
172  barycentric& coordinates,
173  label& celli,
174  label& tetFacei,
175  label& tetPti,
176  label& facei
177 )
178 {
179  label injectorI = 0;
180  if (randomise_)
181  {
182  randomGenerator& rndGen = this->owner().rndGen();
183  injectorI = rndGen.sampleAB<label>(0, injectorCells_.size());
184  }
185  else
186  {
187  injectorI = parcelI*injectorCells_.size()/nParcels;
188  }
189 
190  coordinates = injectorCoordinates_[injectorI];
191  celli = injectorCells_[injectorI];
192  tetFacei = injectorTetFaces_[injectorI];
193  tetPti = injectorTetPts_[injectorI];
194 }
195 
196 
197 template<class CloudType>
199 (
200  const label parcelI,
201  const label nParcels,
202  const scalar,
203  typename CloudType::parcelType::trackingData& td,
204  typename CloudType::parcelType& parcel
205 )
206 {
207  label injectorI = parcelI*injectorCells_.size()/nParcels;
208 
209  // set particle velocity
210  parcel.U() = injectors_[injectorI].U();
211 
212  // set particle diameter
213  parcel.d() = injectors_[injectorI].d();
214 
215  // set particle density
216  parcel.rho() = injectors_[injectorI].rho();
217 
218  // set particle temperature
219  parcel.T() = injectors_[injectorI].T();
220 
221  // set particle specific heat capacity
222  parcel.Cp() = injectors_[injectorI].Cp();
223 
224  // set particle component mass fractions
225  parcel.Y() = injectors_[injectorI].Y();
226 }
227 
228 
229 template<class CloudType>
231 {
232  return true;
233 }
234 
235 
236 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:225
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Templated injection model class.
void setSize(const label)
Reset size of List.
Definition: List.C:281
Particle injection sources read from look-up table. Each row corresponds to an injection site.
virtual void topoChange()
Set injector locations when mesh is updated.
ReactingLookupTableInjection(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, typename CloudType::parcelType::trackingData &td, typename CloudType::parcelType &parcel)
Set the parcel properties.
virtual void setPositionAndCell(const label parcelI, const label nParcels, const scalar time, barycentric &coordinates, label &celli, label &tetFacei, label &tetPti, label &facei)
Set the injection position and owner cell, tetFace and tetPt.
virtual label nParcelsToInject(const scalar time0, const scalar time1)
Number of parcels to introduce relative to SOI.
virtual bool fullyDescribed() const
Flag to identify whether model fully describes the parcel.
scalar timeEnd() const
Return the end-of-injection time.
virtual scalar massToInject(const scalar time0, const scalar time1)
Parcel mass to introduce relative to SOI.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Random number generator.
Type sampleAB(const Type &a, const Type &b)
Return a type with components uniformly distributed between two.
A class for handling words, derived from string.
Definition: word.H:62
bool readBool(Istream &)
Definition: boolIO.C:66
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
dictionary dict
randomGenerator rndGen(653213)