ThermoLookupTableInjection.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-2023 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->readDuration(dict, owner)),
42  parcelsPerSecond_(this->readParcelsPerSecond(dict, owner)),
43  randomise_(readBool(this->coeffDict().lookup("randomise"))),
44  injectors_
45  (
46  IOobject
47  (
48  inputFileName_,
49  owner.db().time().constant(),
50  owner.db(),
51  IOobject::MUST_READ,
52  IOobject::NO_WRITE
53  )
54  ),
55  injectorCoordinates_(0),
56  injectorCells_(0),
57  injectorTetFaces_(0),
58  injectorTetPts_(0)
59 {
60  // Set/cache the injector cells
61  injectorCoordinates_.setSize(injectors_.size());
62  injectorCells_.setSize(injectors_.size());
63  injectorTetFaces_.setSize(injectors_.size());
64  injectorTetPts_.setSize(injectors_.size());
65 
66  topoChange();
67 }
68 
69 
70 template<class CloudType>
72 (
74 )
75 :
77  inputFileName_(im.inputFileName_),
78  duration_(im.duration_),
79  parcelsPerSecond_(im.parcelsPerSecond_),
80  randomise_(im.randomise_),
81  injectors_(im.injectors_),
82  injectorCoordinates_(im.injectorCoordinates_),
83  injectorCells_(im.injectorCells_),
84  injectorTetFaces_(im.injectorTetFaces_),
85  injectorTetPts_(im.injectorTetPts_)
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
90 
91 template<class CloudType>
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
98 template<class CloudType>
100 {
101  // Set/cache the injector cells
102  forAll(injectors_, i)
103  {
104  this->findCellAtPosition
105  (
106  injectors_[i].x(),
107  injectorCoordinates_[i],
108  injectorCells_[i],
109  injectorTetFaces_[i],
110  injectorTetPts_[i]
111  );
112  }
113 }
114 
115 
116 template<class CloudType>
118 {
119  return this->SOI_ + duration_;
120 }
121 
122 
123 template<class CloudType>
125 (
126  const scalar time0,
127  const scalar time1
128 )
129 {
130  if (time0 >= 0 && time0 < duration_)
131  {
132  return
133  floor
134  (
135  injectorCells_.size()
136  *parcelsPerSecond_.integral(time0, time1)
137  );
138  }
139  else
140  {
141  return 0;
142  }
143 }
144 
145 
146 template<class CloudType>
148 (
149  const scalar time0,
150  const scalar time1
151 )
152 {
153  scalar mass = 0;
154 
155  if (time0 >= 0 && time0 < duration_)
156  {
157  forAll(injectors_, i)
158  {
159  mass += injectors_[i].mDot()*(time1 - time0);
160  }
161  }
162 
163  return mass;
164 }
165 
166 
167 template<class CloudType>
169 (
170  const label parcelI,
171  const label nParcels,
172  const scalar time,
173  barycentric& coordinates,
174  label& celli,
175  label& tetFacei,
176  label& tetPti,
177  label& facei
178 )
179 {
180  label injectorI = 0;
181  if (randomise_)
182  {
183  Random& rnd = this->owner().rndGen();
184  injectorI = rnd.sampleAB<label>(0, injectorCells_.size());
185  }
186  else
187  {
188  injectorI = parcelI*injectorCells_.size()/nParcels;
189  }
190 
191  coordinates = injectorCoordinates_[injectorI];
192  celli = injectorCells_[injectorI];
193  tetFacei = injectorTetFaces_[injectorI];
194  tetPti = injectorTetPts_[injectorI];
195 }
196 
197 
198 template<class CloudType>
200 (
201  const label parcelI,
202  const label nParcels,
203  const scalar,
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 
225 
226 template<class CloudType>
228 {
229  return true;
230 }
231 
232 
233 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:79
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:221
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
Random number generator.
Definition: Random.H:58
Type sampleAB(const Type &a, const Type &b)
Advance the state and return a sample of a given type from a.
Definition: RandomI.H:97
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.
ThermoLookupTableInjection(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 &parcel)
Set the parcel properties.
virtual void setPositionAndCell(const label parcelI, const label nParcels, const scalar time, barycentric &coordinates, label &cellOwner, 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:160
A class for handling words, derived from string.
Definition: word.H:62
bool readBool(Istream &)
Definition: boolIO.C:60
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