FreeFOAM The Cross-Platform CFD Toolkit
ConeInjection.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) 1991-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 "ConeInjection.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((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 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  duration_(readScalar(this->coeffDict().lookup("duration"))),
79  position_(this->coeffDict().lookup("position")),
80  injectorCell_(-1),
81  direction_(this->coeffDict().lookup("direction")),
82  parcelsPerSecond_
83  (
84  readScalar(this->coeffDict().lookup("parcelsPerSecond"))
85  ),
86  volumeFlowRate_
87  (
89  (
90  "volumeFlowRate",
91  this->coeffDict()
92  )
93  ),
94  Umag_
95  (
97  (
98  "Umag",
99  this->coeffDict()
100  )
101  ),
102  thetaInner_
103  (
105  (
106  "thetaInner",
107  this->coeffDict()
108  )
109  ),
110  thetaOuter_
111  (
113  (
114  "thetaOuter",
115  this->coeffDict()
116  )
117  ),
118  parcelPDF_
119  (
120  pdfs::pdf::New
121  (
122  this->coeffDict().subDict("parcelPDF"),
123  owner.rndGen()
124  )
125  ),
126  tanVec1_(vector::zero),
127  tanVec2_(vector::zero)
128 {
129  // Normalise direction vector
130  direction_ /= mag(direction_);
131 
132  // Determine direction vectors tangential to direction
133  vector tangent = vector::zero;
134  scalar magTangent = 0.0;
135 
136  while (magTangent < SMALL)
137  {
138  vector v = this->owner().rndGen().vector01();
139 
140  tangent = v - (v & direction_)*direction_;
141  magTangent = mag(tangent);
142  }
143 
144  tanVec1_ = tangent/magTangent;
145  tanVec2_ = direction_^tanVec1_;
146 
147  // Set total volume to inject
148  this->volumeTotal_ = volumeFlowRate_().integrate(0.0, duration_);
149 
150  // Set/cache the injector cell
151  this->findCellAtPosition(injectorCell_, position_);
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 
157 template<class CloudType>
159 {}
160 
161 
162 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 
164 template<class CloudType>
166 {
167  return true;
168 }
169 
170 
171 template<class CloudType>
173 {
174  return this->SOI_ + duration_;
175 }
176 
177 
178 template<class CloudType>
180 (
181  const label,
182  const label,
183  const scalar,
184  vector& position,
185  label& cellOwner
186 )
187 {
188  position = position_;
189  cellOwner = injectorCell_;
190 }
191 
192 
193 template<class CloudType>
195 (
196  const label parcelI,
197  const label,
198  const scalar time,
199  typename CloudType::parcelType& parcel
200 )
201 {
202  // set particle velocity
203  const scalar deg2Rad = mathematicalConstant::pi/180.0;
204 
205  scalar t = time - this->SOI_;
206  scalar ti = thetaInner_().value(t);
207  scalar to = thetaOuter_().value(t);
208  scalar coneAngle = this->owner().rndGen().scalar01()*(to - ti) + ti;
209 
210  coneAngle *= deg2Rad;
211  scalar alpha = sin(coneAngle);
212  scalar dcorr = cos(coneAngle);
213  scalar beta = mathematicalConstant::twoPi*this->owner().rndGen().scalar01();
214 
215  vector normal = alpha*(tanVec1_*cos(beta) + tanVec2_*sin(beta));
216  vector dirVec = dcorr*direction_;
217  dirVec += normal;
218  dirVec /= mag(dirVec);
219 
220  parcel.U() = Umag_().value(t)*dirVec;
221 
222  // set particle diameter
223  parcel.d() = parcelPDF_().sample();
224 }
225 
226 
227 template<class CloudType>
229 {
230  return false;
231 }
232 
233 
234 template<class CloudType>
236 {
237  return true;
238 }
239 
240 
241 // ************************ vim: set sw=4 sts=4 et: ************************ //