FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 2009-2010 OpenCFD Ltd.
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 "PatchInjection.H"
28 #include <pdf/pdf.H>
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class CloudType>
34 (
35  const scalar time0,
36  const scalar time1
37 ) const
38 {
39  if ((time0 >= 0.0) && (time0 < duration_))
40  {
41  return round(fraction_*(time1 - time0)*parcelsPerSecond_);
42  }
43  else
44  {
45  return 0;
46  }
47 }
48 
49 
50 template<class CloudType>
52 (
53  const scalar time0,
54  const scalar time1
55 ) const
56 {
57  if ((time0 >= 0.0) && (time0 < duration_))
58  {
59  return fraction_*volumeFlowRate_().integrate(time0, time1);
60  }
61  else
62  {
63  return 0.0;
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
70 template<class CloudType>
72 (
73  const dictionary& dict,
74  CloudType& owner
75 )
76 :
77  InjectionModel<CloudType>(dict, owner, typeName),
78  patchName_(this->coeffDict().lookup("patchName")),
79  duration_(readScalar(this->coeffDict().lookup("duration"))),
80  parcelsPerSecond_
81  (
82  readScalar(this->coeffDict().lookup("parcelsPerSecond"))
83  ),
84  U0_(this->coeffDict().lookup("U0")),
85  volumeFlowRate_
86  (
88  (
89  "volumeFlowRate",
90  this->coeffDict()
91  )
92  ),
93  parcelPDF_
94  (
95  pdfs::pdf::New
96  (
97  this->coeffDict().subDict("parcelPDF"),
98  owner.rndGen()
99  )
100  ),
101  cellOwners_(),
102  fraction_(1.0)
103 {
104  label patchId = owner.mesh().boundaryMesh().findPatchID(patchName_);
105 
106  if (patchId < 0)
107  {
109  (
110  "PatchInjection<CloudType>::PatchInjection"
111  "("
112  "const dictionary&, "
113  "CloudType&"
114  ")"
115  ) << "Requested patch " << patchName_ << " not found" << nl
116  << "Available patches are: " << owner.mesh().boundaryMesh().names()
117  << nl << exit(FatalError);
118  }
119 
120  const polyPatch& patch = owner.mesh().boundaryMesh()[patchId];
121 
122  cellOwners_ = patch.faceCells();
123 
124  label patchSize = cellOwners_.size();
125  label totalPatchSize = patchSize;
126  reduce(totalPatchSize, sumOp<label>());
127  fraction_ = scalar(patchSize)/totalPatchSize;
128 
129  // Set total volume/mass to inject
130  this->volumeTotal_ = fraction_*volumeFlowRate_().integrate(0.0, duration_);
131  this->massTotal_ *= fraction_;
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
136 
137 template<class CloudType>
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
144 template<class CloudType>
146 {
147  return true;
148 }
149 
150 
151 template<class CloudType>
153 {
154  return this->SOI_ + duration_;
155 }
156 
157 
158 template<class CloudType>
160 (
161  const label,
162  const label,
163  const scalar,
164  vector& position,
165  label& cellOwner
166 )
167 {
168  if (cellOwners_.size() > 0)
169  {
170  label cellI = this->owner().rndGen().integer(0, cellOwners_.size() - 1);
171 
172  cellOwner = cellOwners_[cellI];
173  position = this->owner().mesh().C()[cellOwner];
174  }
175  else
176  {
177  cellOwner = -1;
178  // dummy position
179  position = pTraits<vector>::max;
180  }
181 }
182 
183 
184 template<class CloudType>
186 (
187  const label,
188  const label,
189  const scalar,
190  typename CloudType::parcelType& parcel
191 )
192 {
193  // set particle velocity
194  parcel.U() = U0_;
195 
196  // set particle diameter
197  parcel.d() = parcelPDF_->sample();
198 }
199 
200 
201 template<class CloudType>
203 {
204  return false;
205 }
206 
207 
208 template<class CloudType>
210 {
211  return true;
212 }
213 
214 
215 // ************************ vim: set sw=4 sts=4 et: ************************ //