FieldActivatedInjection.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 
27 #include "volFields.H"
28 #include "mathematicalConstants.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  factor_(this->typeDict().template lookup<scalar>("factor")),
44  referenceField_
45  (
46  owner.parent().objectRegistry::template lookupObject<volScalarField>
47  (
48  this->typeDict().lookup("referenceField")
49  )
50  ),
51  thresholdField_
52  (
53  owner.parent().objectRegistry::template lookupObject<volScalarField>
54  (
55  this->typeDict().lookup("thresholdField")
56  )
57  ),
58  positionsFile_(this->typeDict().lookup("positionsFile")),
59  positions_
60  (
61  IOobject
62  (
63  positionsFile_,
64  owner.time().constant(),
65  owner.mesh(),
66  IOobject::MUST_READ,
67  IOobject::NO_WRITE
68  )
69  ),
70  injectorCoordinates_(positions_.size()),
71  injectorCells_(positions_.size()),
72  injectorTetFaces_(positions_.size()),
73  injectorTetPts_(positions_.size()),
74  massTotal_(this->readMassTotal(dict, owner)),
75  nParcelsPerInjector_
76  (
77  this->typeDict().template lookup<label>("parcelsPerInjector")
78  ),
79  nParcelsInjected_(positions_.size(), 0),
80  U0_(this->typeDict().lookup("U0")),
81  diameters_(positions_.size()),
82  sizeDistribution_
83  (
85  (
86  dimLength,
87  this->typeDict().subDict("sizeDistribution"),
88  this->sizeSampleQ(),
89  owner.rndGen().generator()
90  )
91  )
92 {
93  // Construct parcel diameters - one per injector cell
94  forAll(diameters_, i)
95  {
96  diameters_[i] = sizeDistribution_->sample();
97  }
98 
99  topoChange();
100 }
101 
102 
103 template<class CloudType>
105 (
107 )
108 :
110  factor_(im.factor_),
111  referenceField_(im.referenceField_),
112  thresholdField_(im.thresholdField_),
113  positionsFile_(im.positionsFile_),
114  positions_(im.positions_),
115  injectorCoordinates_(im.injectorCoordinates_),
116  injectorCells_(im.injectorCells_),
117  injectorTetFaces_(im.injectorTetFaces_),
118  injectorTetPts_(im.injectorTetPts_),
119  massTotal_(im.massTotal_),
120  nParcelsPerInjector_(im.nParcelsPerInjector_),
121  nParcelsInjected_(im.nParcelsInjected_),
122  U0_(im.U0_),
123  diameters_(im.diameters_),
124  sizeDistribution_(im.sizeDistribution_, false)
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
129 
130 template<class CloudType>
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
137 template<class CloudType>
139 {
140  const meshSearch& searchEngine = meshSearch::New(this->owner().mesh());
141 
142  // Set/cache the injector cells
143  forAll(positions_, i)
144  {
145  this->findCellAtPosition
146  (
147  searchEngine,
148  positions_[i],
149  injectorCoordinates_[i],
150  injectorCells_[i],
151  injectorTetFaces_[i],
152  injectorTetPts_[i]
153  );
154  }
155 }
156 
157 
158 template<class CloudType>
160 {
161  return vGreat;
162 }
163 
164 
165 template<class CloudType>
167 (
168  const scalar,
169  const scalar
170 )
171 {
172  if (sum(nParcelsInjected_) < nParcelsPerInjector_*positions_.size())
173  {
174  return positions_.size();
175  }
176  else
177  {
178  return 0;
179  }
180 }
181 
182 
183 template<class CloudType>
185 (
186  const scalar,
187  const scalar
188 )
189 {
190  if (sum(nParcelsInjected_) < nParcelsPerInjector_*positions_.size())
191  {
192  return massTotal_/nParcelsPerInjector_;
193  }
194  else
195  {
196  return 0;
197  }
198 }
199 
200 
201 template<class CloudType>
203 (
204  const meshSearch& searchEngine,
205  const label parceli,
206  const label,
207  const scalar,
209  label& celli,
210  label& tetFacei,
211  label& tetPti,
212  label& facei
213 )
214 {
215  const label injectorCelli = injectorCells_[parceli];
216 
217  if
218  (
219  nParcelsInjected_[parceli] < nParcelsPerInjector_
220  && factor_*referenceField_[injectorCelli] > thresholdField_[injectorCelli]
221  )
222  {
223  coordinates = injectorCoordinates_[parceli];
224  celli = injectorCells_[parceli];
225  tetFacei = injectorTetFaces_[parceli];
226  tetPti = injectorTetPts_[parceli];
227 
228  nParcelsInjected_[parceli]++;
229  }
230 }
231 
232 
233 template<class CloudType>
235 (
236  const label parceli,
237  const label,
238  const scalar,
239  typename CloudType::parcelType::trackingData& td,
240  typename CloudType::parcelType& parcel
241 )
242 {
243  // set particle velocity
244  parcel.U() = U0_;
245 
246  // set particle diameter
247  parcel.d() = diameters_[parceli];
248 }
249 
250 
251 template<class CloudType>
253 {
254  return false;
255 }
256 
257 
258 // ************************************************************************* //
#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
Injection at specified positions, with the conditions:
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 ~FieldActivatedInjection()
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.
FieldActivatedInjection(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.
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.
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Templated injection model class.
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
Registry of regIOobjects.
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
const dimensionSet & dimLength
Definition: dimensions.C:141
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
dictionary dict
randomGenerator rndGen(653213)