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-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 
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  dimLength,
67  this->coeffDict().subDict("sizeDistribution"),
68  this->sizeSampleQ(),
69  owner.rndGen().generator()
70  )
71  ),
72  ignoreOutOfBounds_
73  (
74  this->coeffDict().lookupOrDefault("ignoreOutOfBounds", false)
75  )
76 {
77  topoChange();
78 
79  // Construct parcel diameters
80  forAll(diameters_, i)
81  {
82  diameters_[i] = sizeDistribution_->sample();
83  }
84 }
85 
86 
87 template<class CloudType>
89 (
91 )
92 :
94  positionsFile_(im.positionsFile_),
95  positions_(im.positions_),
96  diameters_(im.diameters_),
97  injectorCoordinates_(im.injectorCoordinates_),
98  injectorCells_(im.injectorCells_),
99  injectorTetFaces_(im.injectorTetFaces_),
100  injectorTetPts_(im.injectorTetPts_),
101  massTotal_(im.massTotal_),
102  U0_(im.U0_),
103  sizeDistribution_(im.sizeDistribution_, false),
104  ignoreOutOfBounds_(im.ignoreOutOfBounds_)
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
109 
110 template<class CloudType>
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
117 template<class CloudType>
119 {
120  label nRejected = 0;
121 
122  PackedBoolList keep(positions_.size(), true);
123 
124  forAll(positions_, pI)
125  {
126  if
127  (
128  !this->findCellAtPosition
129  (
130  positions_[pI],
131  injectorCoordinates_[pI],
132  injectorCells_[pI],
133  injectorTetFaces_[pI],
134  injectorTetPts_[pI],
135  !ignoreOutOfBounds_
136  )
137  )
138  {
139  keep[pI] = false;
140  nRejected++;
141  }
142  }
143 
144  if (nRejected > 0)
145  {
146  inplaceSubset(keep, positions_);
147  inplaceSubset(keep, diameters_);
148  inplaceSubset(keep, injectorCoordinates_);
149  inplaceSubset(keep, injectorCells_);
150  inplaceSubset(keep, injectorTetFaces_);
151  inplaceSubset(keep, injectorTetPts_);
152 
153  Info<< " " << nRejected
154  << " particles ignored, out of bounds" << endl;
155  }
156 }
157 
158 
159 template<class CloudType>
161 {
162  // Injection is instantaneous - but allow for a finite interval to
163  // avoid numerical issues when interval is zero
164  return rootVSmall;
165 }
166 
167 
168 template<class CloudType>
170 (
171  const scalar time0,
172  const scalar time1
173 )
174 {
175  // All parcels introduced at SOI
176  if (0 >= time0 && 0 < time1)
177  {
178  return positions_.size();
179  }
180  else
181  {
182  return 0;
183  }
184 }
185 
186 
187 template<class CloudType>
189 (
190  const scalar time0,
191  const scalar time1
192 )
193 {
194  // All parcels introduced at SOI
195  if (0 >= time0 && 0 < time1)
196  {
197  return massTotal_;
198  }
199  else
200  {
201  return 0;
202  }
203 }
204 
205 
206 template<class CloudType>
208 (
209  const label parcelI,
210  const label,
211  const scalar,
212  barycentric& coordinates,
213  label& celli,
214  label& tetFacei,
215  label& tetPti,
216  label& facei
217 )
218 {
219  coordinates = injectorCoordinates_[parcelI];
220  celli = injectorCells_[parcelI];
221  tetFacei = injectorTetFaces_[parcelI];
222  tetPti = injectorTetPts_[parcelI];
223 }
224 
225 
226 template<class CloudType>
228 (
229  const label parcelI,
230  const label,
231  const scalar,
232  typename CloudType::parcelType::trackingData& td,
233  typename CloudType::parcelType& parcel
234 )
235 {
236  // set particle velocity
237  parcel.U() = U0_;
238 
239  // set particle diameter
240  parcel.d() = diameters_[parcelI];
241 }
242 
243 
244 template<class CloudType>
246 {
247  return false;
248 }
249 
250 
251 // ************************************************************************* //
#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.
Manual injection.
virtual void topoChange()
Set injector locations when mesh is updated.
virtual ~ManualInjection()
Destructor.
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.
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 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:162
Base class for statistical distributions.
Definition: distribution.H:76
A class for handling words, derived from string.
Definition: word.H:62
mathematical constants.
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:257
void inplaceSubset(const UList< T > &select, const T &value, ListType &)
Inplace extract elements of List when select is a certain value.
messageStream Info
const dimensionSet dimLength
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
dictionary dict
randomGenerator rndGen(653213)