ManualInjection.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 
26 #include "ManualInjection.H"
27 #include "mathematicalConstants.H"
28 #include "PackedBoolList.H"
29 
30 using namespace Foam::constant::mathematical;
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  positionsFile_(this->coeffDict().lookup("positionsFile")),
44  positions_
45  (
46  IOobject
47  (
48  positionsFile_,
49  owner.db().time().constant(),
50  owner.mesh(),
51  IOobject::MUST_READ,
52  IOobject::NO_WRITE
53  )
54  ),
55  diameters_(positions_.size()),
56  injectorCoordinates_(positions_.size(), barycentric::uniform(NaN)),
57  injectorCells_(positions_.size(), -1),
58  injectorTetFaces_(positions_.size(), -1),
59  injectorTetPts_(positions_.size(), -1),
60  massTotal_(this->readMassTotal(dict, owner)),
61  U0_(this->coeffDict().lookup("U0")),
62  sizeDistribution_
63  (
65  (
66  this->coeffDict().subDict("sizeDistribution"),
67  owner.rndGen(),
68  this->sizeSampleQ()
69  )
70  ),
71  ignoreOutOfBounds_
72  (
73  this->coeffDict().lookupOrDefault("ignoreOutOfBounds", false)
74  )
75 {
76  topoChange();
77 
78  // Construct parcel diameters
79  forAll(diameters_, i)
80  {
81  diameters_[i] = sizeDistribution_->sample();
82  }
83 }
84 
85 
86 template<class CloudType>
88 (
90 )
91 :
93  positionsFile_(im.positionsFile_),
94  positions_(im.positions_),
95  diameters_(im.diameters_),
96  injectorCoordinates_(im.injectorCoordinates_),
97  injectorCells_(im.injectorCells_),
98  injectorTetFaces_(im.injectorTetFaces_),
99  injectorTetPts_(im.injectorTetPts_),
100  massTotal_(im.massTotal_),
101  U0_(im.U0_),
102  sizeDistribution_(im.sizeDistribution_().clone().ptr()),
103  ignoreOutOfBounds_(im.ignoreOutOfBounds_)
104 {}
105 
106 
107 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
108 
109 template<class CloudType>
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
116 template<class CloudType>
118 {
119  label nRejected = 0;
120 
121  PackedBoolList keep(positions_.size(), true);
122 
123  forAll(positions_, pI)
124  {
125  if
126  (
127  !this->findCellAtPosition
128  (
129  positions_[pI],
130  injectorCoordinates_[pI],
131  injectorCells_[pI],
132  injectorTetFaces_[pI],
133  injectorTetPts_[pI],
134  !ignoreOutOfBounds_
135  )
136  )
137  {
138  keep[pI] = false;
139  nRejected++;
140  }
141  }
142 
143  if (nRejected > 0)
144  {
145  inplaceSubset(keep, positions_);
146  inplaceSubset(keep, diameters_);
147  inplaceSubset(keep, injectorCoordinates_);
148  inplaceSubset(keep, injectorCells_);
149  inplaceSubset(keep, injectorTetFaces_);
150  inplaceSubset(keep, injectorTetPts_);
151 
152  Info<< " " << nRejected
153  << " particles ignored, out of bounds" << endl;
154  }
155 }
156 
157 
158 template<class CloudType>
160 {
161  // Injection is instantaneous - but allow for a finite interval to
162  // avoid numerical issues when interval is zero
163  return rootVSmall;
164 }
165 
166 
167 template<class CloudType>
169 (
170  const scalar time0,
171  const scalar time1
172 )
173 {
174  // All parcels introduced at SOI
175  if (0 >= time0 && 0 < time1)
176  {
177  return positions_.size();
178  }
179  else
180  {
181  return 0;
182  }
183 }
184 
185 
186 template<class CloudType>
188 (
189  const scalar time0,
190  const scalar time1
191 )
192 {
193  // All parcels introduced at SOI
194  if (0 >= time0 && 0 < time1)
195  {
196  return massTotal_;
197  }
198  else
199  {
200  return 0;
201  }
202 }
203 
204 
205 template<class CloudType>
207 (
208  const label parcelI,
209  const label,
210  const scalar,
211  barycentric& coordinates,
212  label& celli,
213  label& tetFacei,
214  label& tetPti,
215  label& facei
216 )
217 {
218  coordinates = injectorCoordinates_[parcelI];
219  celli = injectorCells_[parcelI];
220  tetFacei = injectorTetFaces_[parcelI];
221  tetPti = injectorTetPts_[parcelI];
222 }
223 
224 
225 template<class CloudType>
227 (
228  const label parcelI,
229  const label,
230  const scalar,
231  typename CloudType::parcelType& parcel
232 )
233 {
234  // set particle velocity
235  parcel.U() = U0_;
236 
237  // set particle diameter
238  parcel.d() = diameters_[parcelI];
239 }
240 
241 
242 template<class CloudType>
244 {
245  return false;
246 }
247 
248 
249 // ************************************************************************* //
#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.
Manual injection.
virtual void topoChange()
Set injector locations when mesh is updated.
virtual ~ManualInjection()
Destructor.
ManualInjection(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
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 void setProperties(const label parcelI, const label nParcels, const scalar time, typename CloudType::parcelType &parcel)
Set the parcel properties.
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.
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 bit-packed bool list.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
Definition: distribution.H:61
A class for handling words, derived from string.
Definition: word.H:62
mathematical constants.
static Type NaN()
Return a primitive with all components set to NaN.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void inplaceSubset(const UList< T > &select, const T &value, ListType &)
Inplace extract elements of List when select is a certain value.
messageStream Info
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
T clone(const T &t)
Definition: List.H:55
dictionary dict
Random rndGen(label(0))