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-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 
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 :
42  InjectionModel<CloudType>(dict, owner, modelName, typeName),
43  factor_(this->coeffDict().template lookup<scalar>("factor")),
44  referenceField_
45  (
46  owner.db().objectRegistry::template lookupObject<volScalarField>
47  (
48  this->coeffDict().lookup("referenceField")
49  )
50  ),
51  thresholdField_
52  (
53  owner.db().objectRegistry::template lookupObject<volScalarField>
54  (
55  this->coeffDict().lookup("thresholdField")
56  )
57  ),
58  positionsFile_(this->coeffDict().lookup("positionsFile")),
59  positions_
60  (
61  IOobject
62  (
63  positionsFile_,
64  owner.db().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->coeffDict().template lookup<label>("parcelsPerInjector")
78  ),
79  nParcelsInjected_(positions_.size(), 0),
80  U0_(this->coeffDict().lookup("U0")),
81  diameters_(positions_.size()),
82  sizeDistribution_
83  (
85  (
86  this->coeffDict().subDict("sizeDistribution"),
87  owner.rndGen(),
88  this->sizeSampleQ()
89  )
90  )
91 {
92  // Construct parcel diameters - one per injector cell
93  forAll(diameters_, i)
94  {
95  diameters_[i] = sizeDistribution_->sample();
96  }
97 
98  topoChange();
99 }
100 
101 
102 template<class CloudType>
104 (
106 )
107 :
109  factor_(im.factor_),
110  referenceField_(im.referenceField_),
111  thresholdField_(im.thresholdField_),
112  positionsFile_(im.positionsFile_),
113  positions_(im.positions_),
114  injectorCoordinates_(im.injectorCoordinates_),
115  injectorCells_(im.injectorCells_),
116  injectorTetFaces_(im.injectorTetFaces_),
117  injectorTetPts_(im.injectorTetPts_),
118  massTotal_(im.massTotal_),
119  nParcelsPerInjector_(im.nParcelsPerInjector_),
120  nParcelsInjected_(im.nParcelsInjected_),
121  U0_(im.U0_),
122  diameters_(im.diameters_),
123  sizeDistribution_(im.sizeDistribution_().clone().ptr())
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
128 
129 template<class CloudType>
131 {}
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
136 template<class CloudType>
138 {
139  // Set/cache the injector cells
140  forAll(positions_, i)
141  {
142  this->findCellAtPosition
143  (
144  positions_[i],
145  injectorCoordinates_[i],
146  injectorCells_[i],
147  injectorTetFaces_[i],
148  injectorTetPts_[i]
149  );
150  }
151 }
152 
153 
154 template<class CloudType>
156 {
157  return great;
158 }
159 
160 
161 template<class CloudType>
163 (
164  const scalar time0,
165  const scalar time1
166 )
167 {
168  if (sum(nParcelsInjected_) < nParcelsPerInjector_*positions_.size())
169  {
170  return positions_.size();
171  }
172  else
173  {
174  return 0;
175  }
176 }
177 
178 
179 template<class CloudType>
181 (
182  const scalar time0,
183  const scalar time1
184 )
185 {
186  if (sum(nParcelsInjected_) < nParcelsPerInjector_*positions_.size())
187  {
188  return massTotal_/nParcelsPerInjector_;
189  }
190  else
191  {
192  return 0;
193  }
194 }
195 
196 
197 template<class CloudType>
199 (
200  const label parceli,
201  const label,
202  const scalar,
203  barycentric& coordinates,
204  label& celli,
205  label& tetFacei,
206  label& tetPti,
207  label& facei
208 )
209 {
210  const label injectorCelli = injectorCells_[parceli];
211 
212  if
213  (
214  nParcelsInjected_[parceli] < nParcelsPerInjector_
215  && factor_*referenceField_[injectorCelli] > thresholdField_[injectorCelli]
216  )
217  {
218  coordinates = injectorCoordinates_[parceli];
219  celli = injectorCells_[parceli];
220  tetFacei = injectorTetFaces_[parceli];
221  tetPti = injectorTetPts_[parceli];
222 
223  nParcelsInjected_[parceli]++;
224  }
225 }
226 
227 
228 template<class CloudType>
230 (
231  const label parceli,
232  const label,
233  const scalar,
234  typename CloudType::parcelType& parcel
235 )
236 {
237  // set particle velocity
238  parcel.U() = U0_;
239 
240  // set particle diameter
241  parcel.d() = diameters_[parceli];
242 }
243 
244 
245 template<class CloudType>
247 {
248  return false;
249 }
250 
251 
252 // ************************************************************************* //
#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
Injection at specified positions, with the conditions:
virtual void topoChange()
Set injector locations when mesh is updated.
virtual void setProperties(const label parceli, const label nParcels, const scalar time, typename CloudType::parcelType &parcel)
Set the parcel properties.
virtual ~FieldActivatedInjection()
Destructor.
virtual label nParcelsToInject(const scalar time0, const scalar time1)
Number of parcels to introduce relative to SOI.
FieldActivatedInjection(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.
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 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
Registry of regIOobjects.
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
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
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))