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-2026 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 :
43  positionsFile_(this->typeDict().lookup("positionsFile")),
44  positions_
45  (
46  IOobject
47  (
48  positionsFile_,
49  owner.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->typeDict().lookup("U0")),
62  sizeDistribution_
63  (
65  (
66  dimLength,
67  this->typeDict().subDict("sizeDistribution"),
68  this->sizeSampleQ(),
69  owner.rndGen().generator()
70  )
71  ),
72  ignoreOutOfBounds_
73  (
74  this->typeDict().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  const meshSearch& searchEngine = meshSearch::New(this->owner().mesh());
121 
122  label nRejected = 0;
123 
124  PackedBoolList keep(positions_.size(), true);
125 
126  forAll(positions_, pI)
127  {
128  if
129  (
130  !this->findCellAtPosition
131  (
132  searchEngine,
133  positions_[pI],
134  injectorCoordinates_[pI],
135  injectorCells_[pI],
136  injectorTetFaces_[pI],
137  injectorTetPts_[pI],
138  !ignoreOutOfBounds_
139  )
140  )
141  {
142  keep[pI] = false;
143  nRejected++;
144  }
145  }
146 
147  if (nRejected > 0)
148  {
149  inplaceSubset(keep, positions_);
150  inplaceSubset(keep, diameters_);
151  inplaceSubset(keep, injectorCoordinates_);
152  inplaceSubset(keep, injectorCells_);
153  inplaceSubset(keep, injectorTetFaces_);
154  inplaceSubset(keep, injectorTetPts_);
155 
156  Info<< " " << nRejected
157  << " particles ignored, out of bounds" << endl;
158  }
159 }
160 
161 
162 template<class CloudType>
164 {
165  // Not used
166  return this->SOI_;
167 }
168 
169 
170 template<class CloudType>
172 (
173  const scalar t0,
174  const scalar t1
175 )
176 {
177  // All parcels introduced at SOI
178  if (0 >= t0 && 0 < t1)
179  {
180  return positions_.size();
181  }
182  else
183  {
184  return 0;
185  }
186 }
187 
188 
189 template<class CloudType>
191 (
192  const scalar t0,
193  const scalar t1
194 )
195 {
196  // All parcels introduced at SOI
197  if (0 >= t0 && 0 < t1)
198  {
199  return massTotal_;
200  }
201  else
202  {
203  return 0;
204  }
205 }
206 
207 
208 template<class CloudType>
210 (
211  const meshSearch& searchEngine,
212  const label parcelI,
213  const label,
214  const scalar,
216  label& celli,
217  label& tetFacei,
218  label& tetPti,
219  label& facei
220 )
221 {
222  coordinates = injectorCoordinates_[parcelI];
223  celli = injectorCells_[parcelI];
224  tetFacei = injectorTetFaces_[parcelI];
225  tetPti = injectorTetPts_[parcelI];
226 }
227 
228 
229 template<class CloudType>
231 (
232  const label parcelI,
233  const label,
234  const scalar,
235  typename CloudType::parcelType::trackingData& td,
236  typename CloudType::parcelType& parcel
237 )
238 {
239  // set particle velocity
240  parcel.U() = U0_;
241 
242  // set particle diameter
243  parcel.d() = diameters_[parcelI];
244 }
245 
246 
247 template<class CloudType>
249 {
250  return false;
251 }
252 
253 
254 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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 meshSearch &searchEngine, 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
Mesh object that implements searches within the local cells and faces.
Definition: meshSearch.H:59
static const meshSearch & New(const polyMesh &mesh, const pointInCellShapes=pointInCellShapes::tets)
Lookup or construct from mesh and cell decomposition option.
Definition: meshSearch.C:61
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
mathematical constants.
const dimensionSet time
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:1258
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
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:288
const dimensionSet & dimLength
Definition: dimensions.C:141
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, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
dictionary dict
randomGenerator rndGen(653213)