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  // Not used
163  return this->SOI_;
164 }
165 
166 
167 template<class CloudType>
169 (
170  const scalar t0,
171  const scalar t1
172 )
173 {
174  // All parcels introduced at SOI
175  if (0 >= t0 && 0 < t1)
176  {
177  return positions_.size();
178  }
179  else
180  {
181  return 0;
182  }
183 }
184 
185 
186 template<class CloudType>
188 (
189  const scalar t0,
190  const scalar t1
191 )
192 {
193  // All parcels introduced at SOI
194  if (0 >= t0 && 0 < t1)
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,
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::trackingData& td,
232  typename CloudType::parcelType& parcel
233 )
234 {
235  // set particle velocity
236  parcel.U() = U0_;
237 
238  // set particle diameter
239  parcel.d() = diameters_[parcelI];
240 }
241 
242 
243 template<class CloudType>
245 {
246  return false;
247 }
248 
249 
250 // ************************************************************************* //
#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.
Manual injection.
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 ~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 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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
mathematical constants.
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
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:258
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, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
dictionary dict
randomGenerator rndGen(653213)