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-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 #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  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 t0,
126  const scalar t1
127 )
128 {
129  if (t1 >= 0 && t0 < duration_)
130  {
131  return
132  injectorCells_.size()
133  *parcelsPerSecond_->integral(max(t0, 0), min(t1, duration_));
134  }
135  else
136  {
137  return 0;
138  }
139 }
140 
141 
142 template<class CloudType>
144 (
145  const scalar t0,
146  const scalar t1
147 )
148 {
149  scalar mass = 0;
150 
151  if (t1 >= 0 && t0 < duration_)
152  {
153  forAll(injectors_, i)
154  {
155  mass += injectors_[i].mDot()*(min(t1, duration_) - max(t0, 0));
156  }
157  }
158 
159  return mass;
160 }
161 
162 
163 template<class CloudType>
165 (
166  const label parcelI,
167  const label nParcels,
168  const scalar time,
170  label& celli,
171  label& tetFacei,
172  label& tetPti,
173  label& facei
174 )
175 {
176  label injectorI = 0;
177  if (randomise_)
178  {
179  randomGenerator& rndGen = this->owner().rndGen();
180  injectorI = rndGen.sampleAB<label>(0, injectorCells_.size());
181  }
182  else
183  {
184  injectorI = int64_t(parcelI)*int64_t(injectors_.size())/nParcels;
185  }
186 
187  coordinates = injectorCoordinates_[injectorI];
188  celli = injectorCells_[injectorI];
189  tetFacei = injectorTetFaces_[injectorI];
190  tetPti = injectorTetPts_[injectorI];
191 }
192 
193 
194 template<class CloudType>
196 (
197  const label parcelI,
198  const label nParcels,
199  const scalar,
200  typename CloudType::parcelType::trackingData& td,
201  typename CloudType::parcelType& parcel
202 )
203 {
204  label injectorI = int64_t(parcelI)*int64_t(injectors_.size())/nParcels;
205 
206  // set particle velocity
207  parcel.U() = injectors_[injectorI].U();
208 
209  // set particle diameter
210  parcel.d() = injectors_[injectorI].d();
211 
212  // set particle density
213  parcel.rho() = injectors_[injectorI].rho();
214 }
215 
216 
217 template<class CloudType>
219 {
220  return true;
221 }
222 
223 
224 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
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 scalar nParcelsToInject(const scalar time0, const scalar time1)
Number of parcels to introduce relative to SOI.
virtual void topoChange()
Set injector locations when mesh is updated.
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.
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.
virtual 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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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
barycentric coordinates(const polyMesh &mesh, const point &position, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the coordinates given the position and tet topology.
Definition: tracking.C:1259
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
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dictionary dict
randomGenerator rndGen(653213)