KinematicLookupTableInjection.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "scalarIOList.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class CloudType>
36 (
37  const dictionary& dict,
38  CloudType& owner,
39  const word& modelName
40 )
41 :
42  InjectionModel<CloudType>(dict, owner, modelName, typeName),
43  inputFileName_(this->coeffDict().lookup("inputFile")),
44  duration_(this->coeffDict().getScalar("duration")),
45  parcelsPerSecond_(this->coeffDict().getScalar("parcelsPerSecond")),
46  randomise_(this->coeffDict().getBool("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_(injectors_.size()),
59  injectorTetFaces_(injectors_.size()),
60  injectorTetPts_(injectors_.size())
61 {
62  updateMesh();
63 
64  duration_ = owner.db().time().userTimeToTime(duration_);
65 
66  // Determine volume of particles to inject
67  this->volumeTotal_ = 0.0;
68  forAll(injectors_, i)
69  {
70  this->volumeTotal_ += injectors_[i].mDot()/injectors_[i].rho();
71  }
72  this->volumeTotal_ *= duration_;
73 }
74 
75 
76 template<class CloudType>
78 (
80 )
81 :
83  inputFileName_(im.inputFileName_),
84  duration_(im.duration_),
85  parcelsPerSecond_(im.parcelsPerSecond_),
86  randomise_(im.randomise_),
87  injectors_(im.injectors_),
88  injectorCells_(im.injectorCells_),
89  injectorTetFaces_(im.injectorTetFaces_),
90  injectorTetPts_(im.injectorTetPts_)
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
96 template<class CloudType>
98 {
99  bitSet reject(injectors_.size());
100 
101  // Set/cache the injector cells
102  forAll(injectors_, i)
103  {
104  if
105  (
106  !this->findCellAtPosition
107  (
108  injectorCells_[i],
109  injectorTetFaces_[i],
110  injectorTetPts_[i],
111  injectors_[i].x(),
112  !this->ignoreOutOfBounds_
113 
114  )
115  )
116  {
117  reject.set(i);
118  }
119  }
120 
121  const label nRejected = reject.count();
122 
123  if (nRejected)
124  {
125  reject.flip();
126  inplaceSubset(reject, injectorCells_);
127  inplaceSubset(reject, injectorTetFaces_);
128  inplaceSubset(reject, injectorTetPts_);
129  inplaceSubset(reject, injectors_);
130 
131  Info<< " " << nRejected
132  << " positions rejected, out of bounds" << endl;
133  }
134 }
135 
136 
137 template<class CloudType>
139 {
140  return this->SOI_ + duration_;
141 }
142 
143 
144 template<class CloudType>
146 (
147  const scalar time0,
148  const scalar time1
149 )
150 {
151  if ((time0 >= 0.0) && (time0 < duration_))
152  {
153  return floor(injectorCells_.size()*(time1 - time0)*parcelsPerSecond_);
154  }
155 
156  return 0;
157 }
158 
159 
160 template<class CloudType>
162 (
163  const scalar time0,
164  const scalar time1
165 )
166 {
167  scalar volume = 0.0;
168  if ((time0 >= 0.0) && (time0 < duration_))
169  {
170  forAll(injectors_, i)
171  {
172  volume += injectors_[i].mDot()/injectors_[i].rho()*(time1 - time0);
173  }
174  }
175 
176  return volume;
177 }
178 
179 
180 template<class CloudType>
182 (
183  const label parcelI,
184  const label nParcels,
185  const scalar time,
186  vector& position,
187  label& cellOwner,
188  label& tetFacei,
189  label& tetPti
190 )
191 {
192  label injectorI = 0;
193  if (randomise_)
194  {
195  Random& rnd = this->owner().rndGen();
196  injectorI = rnd.position<label>(0, injectorCells_.size() - 1);
197  }
198  else
199  {
200  injectorI = int64_t(parcelI)*int64_t(injectors_.size())/nParcels;
201  }
202 
203  position = injectors_[injectorI].x();
204  cellOwner = injectorCells_[injectorI];
205  tetFacei = injectorTetFaces_[injectorI];
206  tetPti = injectorTetPts_[injectorI];
207 }
208 
209 
210 template<class CloudType>
212 (
213  const label parcelI,
214  const label nParcels,
215  const scalar,
216  typename CloudType::parcelType& parcel
217 )
218 {
219  label injectorI = int64_t(parcelI)*int64_t(injectors_.size())/nParcels;
220 
221  // set particle velocity
222  parcel.U() = injectors_[injectorI].U();
223 
224  // set particle diameter
225  parcel.d() = injectors_[injectorI].d();
226 
227  // set particle density
228  parcel.rho() = injectors_[injectorI].rho();
229 }
230 
231 
232 template<class CloudType>
234 {
235  return true;
236 }
237 
238 
239 template<class CloudType>
241 (
242  const label
243 )
244 {
245  return true;
246 }
247 
248 
249 // ************************************************************************* //
Foam::Random
Random number generator.
Definition: Random.H:59
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::KinematicLookupTableInjection::fullyDescribed
virtual bool fullyDescribed() const
Flag to identify whether model fully describes the parcel.
Definition: KinematicLookupTableInjection.C:233
Foam::KinematicLookupTableInjection::setPositionAndCell
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.
Definition: KinematicLookupTableInjection.C:182
KinematicLookupTableInjection.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::KinematicLookupTableInjection::KinematicLookupTableInjection
KinematicLookupTableInjection(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: KinematicLookupTableInjection.C:36
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::InjectionModel
Templated injection model class.
Definition: InjectionModel.H:73
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::fieldTypes::volume
const wordList volume
Standard volume field types (scalar, vector, tensor, etc)
Foam::KinematicLookupTableInjection::validInjection
virtual bool validInjection(const label parcelI)
Definition: KinematicLookupTableInjection.C:241
Foam::DSMCCloud::rndGen
Random & rndGen()
Return reference to the random object.
Definition: DSMCCloudI.H:124
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::KinematicLookupTableInjection::setProperties
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, typename CloudType::parcelType &parcel)
Set the parcel properties.
Definition: KinematicLookupTableInjection.C:212
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::radiation::lookup
Lookup type of boundary radiation properties.
Definition: lookup.H:63
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::KinematicLookupTableInjection::parcelsToInject
virtual label parcelsToInject(const scalar time0, const scalar time1)
Number of parcels to introduce relative to SOI.
Definition: KinematicLookupTableInjection.C:146
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::KinematicLookupTableInjection
Particle injection sources read from look-up table. Each row corresponds to an injection site.
Definition: KinematicLookupTableInjection.H:94
Foam::inplaceSubset
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
Definition: ListOpsTemplates.C:583
Foam::KinematicLookupTableInjection::updateMesh
virtual void updateMesh()
Set injector locations when mesh is updated.
Definition: KinematicLookupTableInjection.C:97
Foam::KinematicLookupTableInjection::timeEnd
scalar timeEnd() const
Return the end-of-injection time.
Definition: KinematicLookupTableInjection.C:138
Foam::KinematicLookupTableInjection::volumeToInject
virtual scalar volumeToInject(const scalar time0, const scalar time1)
Volume of parcels to introduce relative to SOI.
Definition: KinematicLookupTableInjection.C:162
Foam::Random::position
Type position(const Type &start, const Type &end)
Return a sample on the interval [start,end].
Definition: RandomTemplates.C:62
Foam::Vector< scalar >
scalarIOList.H
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::DSMCCloud::parcelType
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:220