PatchInjection.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "PatchInjection.H"
30 #include "TimeFunction1.H"
31 #include "distributionModel.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class CloudType>
37 (
38  const dictionary& dict,
39  CloudType& owner,
40  const word& modelName
41 )
42 :
43  InjectionModel<CloudType>(dict, owner, modelName, typeName),
44  patchInjectionBase(owner.mesh(), this->coeffDict().getWord("patch")),
45  duration_(this->coeffDict().getScalar("duration")),
46  parcelsPerSecond_
47  (
48  this->coeffDict().getScalar("parcelsPerSecond")
49  ),
50  U0_(this->coeffDict().lookup("U0")),
51  flowRateProfile_
52  (
54  (
55  owner.db().time(),
56  "flowRateProfile",
57  this->coeffDict()
58  )
59  ),
60  sizeDistribution_
61  (
63  (
64  this->coeffDict().subDict("sizeDistribution"),
65  owner.rndGen()
66  )
67  )
68 {
69  duration_ = owner.db().time().userTimeToTime(duration_);
70 
71  patchInjectionBase::updateMesh(owner.mesh());
72 
73  // Set total volume/mass to inject
74  this->volumeTotal_ = flowRateProfile_.integrate(0.0, duration_);
75 }
76 
77 
78 template<class CloudType>
80 (
82 )
83 :
86  duration_(im.duration_),
87  parcelsPerSecond_(im.parcelsPerSecond_),
88  U0_(im.U0_),
89  flowRateProfile_(im.flowRateProfile_),
90  sizeDistribution_(im.sizeDistribution_.clone())
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
95 
96 template<class CloudType>
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
103 template<class CloudType>
105 {
106  patchInjectionBase::updateMesh(this->owner().mesh());
107 }
108 
109 
110 template<class CloudType>
112 {
113  return this->SOI_ + duration_;
114 }
115 
116 
117 template<class CloudType>
119 (
120  const scalar time0,
121  const scalar time1
122 )
123 {
124  if ((time0 >= 0.0) && (time0 < duration_))
125  {
126  scalar nParcels = (time1 - time0)*parcelsPerSecond_;
127  Random& rnd = this->owner().rndGen();
128  scalar rndPos = rnd.globalPosition(scalar(0), scalar(1));
129  label nParcelsToInject = floor(nParcels);
130 
131  // Inject an additional parcel with a probability based on the
132  // remainder after the floor function
133  if
134  (
135  nParcelsToInject > 0
136  && (nParcels - scalar(nParcelsToInject) > rndPos)
137  )
138  {
139  ++nParcelsToInject;
140  }
141 
142  return nParcelsToInject;
143  }
144 
145  return 0;
146 }
147 
148 
149 template<class CloudType>
151 (
152  const scalar time0,
153  const scalar time1
154 )
155 {
156  if ((time0 >= 0.0) && (time0 < duration_))
157  {
158  return flowRateProfile_.integrate(time0, time1);
159  }
160 
161  return 0.0;
162 }
163 
164 
165 template<class CloudType>
167 (
168  const label,
169  const label,
170  const scalar,
171  vector& position,
172  label& cellOwner,
173  label& tetFacei,
174  label& tetPti
175 )
176 {
177  patchInjectionBase::setPositionAndCell
178  (
179  this->owner().mesh(),
180  this->owner().rndGen(),
181  position,
182  cellOwner,
183  tetFacei,
184  tetPti
185  );
186 }
187 
188 
189 template<class CloudType>
191 (
192  const label,
193  const label,
194  const scalar,
195  typename CloudType::parcelType& parcel
196 )
197 {
198  // set particle velocity
199  parcel.U() = U0_;
200 
201  // set particle diameter
202  parcel.d() = sizeDistribution_->sample();
203 }
204 
205 
206 template<class CloudType>
208 {
209  return false;
210 }
211 
212 
213 template<class CloudType>
215 {
216  return true;
217 }
218 
219 
220 // ************************************************************************* //
Foam::PatchInjection::fullyDescribed
virtual bool fullyDescribed() const
Flag to identify whether model fully describes the parcel.
Definition: PatchInjection.C:207
Foam::Random
Random number generator.
Definition: Random.H:59
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::PatchInjection::parcelsToInject
virtual label parcelsToInject(const scalar time0, const scalar time1)
Number of parcels to introduce relative to SOI.
Definition: PatchInjection.C:119
Foam::PatchInjection::validInjection
virtual bool validInjection(const label parcelI)
Return flag to identify whether or not injection of parcelI is.
Definition: PatchInjection.C:214
Foam::InjectionModel
Templated injection model class.
Definition: InjectionModel.H:73
Foam::TimeFunction1< scalar >
PatchInjection.H
Foam::DSMCCloud::rndGen
Random & rndGen()
Return reference to the random object.
Definition: DSMCCloudI.H:124
Foam::PatchInjection::PatchInjection
PatchInjection(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: PatchInjection.C:37
Foam::DSMCCloud::mesh
const fvMesh & mesh() const
Return reference to the mesh.
Definition: DSMCCloudI.H:44
Foam::PatchInjection::setPositionAndCell
virtual void setPositionAndCell(const label parcelI, const label nParcels, const scalar time, vector &position, label &cellOwner, label &tetFacei, label &tetPti)
Set the injection position and owner cell, tetFace and tetPt.
Definition: PatchInjection.C:167
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dictionary::getWord
word getWord(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< word >(const word&, keyType::option)
Definition: dictionary.H:1500
Foam::PatchInjection
Patch injection.
Definition: PatchInjection.H:71
Foam::PatchInjection::timeEnd
virtual scalar timeEnd() const
Return the end-of-injection time.
Definition: PatchInjection.C:111
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::Vector< scalar >
Foam::patchInjectionBase
Definition: patchInjectionBase.H:64
Foam::PatchInjection::~PatchInjection
virtual ~PatchInjection()
Destructor.
Definition: PatchInjection.C:97
Foam::PatchInjection::setProperties
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, typename CloudType::parcelType &parcel)
Set the parcel properties.
Definition: PatchInjection.C:191
rndGen
Random rndGen
Definition: createFields.H:23
Foam::PatchInjection::volumeToInject
virtual scalar volumeToInject(const scalar time0, const scalar time1)
Volume of parcels to introduce relative to SOI.
Definition: PatchInjection.C:151
Foam::DSMCCloud::parcelType
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:220
TimeFunction1.H
Foam::PatchInjection::updateMesh
virtual void updateMesh()
Set injector locations when mesh is updated.
Definition: PatchInjection.C:104
Foam::Random::globalPosition
Type globalPosition(const Type &start, const Type &end)
Return a sample on the interval [start,end].
Definition: RandomTemplates.C:126
distributionModel.H