FreeFOAM The Cross-Platform CFD Toolkit
swirlInjector.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 "swirlInjector.H"
28 #include <OpenFOAM/Random.H>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(swirlInjector, 0);
36 
38  (
39  injectorType,
40  swirlInjector,
41  dictionary
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
48 Foam::swirlInjector::swirlInjector
49 (
50  const Foam::Time& t,
51  const Foam::dictionary& dict
52 )
53 :
54  injectorType(t, dict),
55  propsDict_(dict.subDict(typeName + "Props")),
56  position_(propsDict_.lookup("position")),
57  direction_(propsDict_.lookup("direction")),
58  d_(readScalar(propsDict_.lookup("diameter"))),
59  mass_(readScalar(propsDict_.lookup("mass"))),
60  injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
61  T_(readScalar(propsDict_.lookup("temperature"))),
62  nParcels_(readLabel(propsDict_.lookup("nParcels"))),
63  X_(propsDict_.lookup("X")),
64  massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
65  injectionPressureProfile_(propsDict_.lookup("injectionPressureProfile")),
66  velocityProfile_(massFlowRateProfile_),
67  CdProfile_(massFlowRateProfile_),
68  TProfile_(massFlowRateProfile_),
69  averageParcelMass_(mass_/nParcels_),
70  pressureIndependentVelocity_(false)
71 {
72  // convert CA to real time
73  forAll(massFlowRateProfile_, i)
74  {
75  massFlowRateProfile_[i][0] =
76  t.userTimeToTime(massFlowRateProfile_[i][0]);
77  }
78  forAll(injectionPressureProfile_, i)
79  {
80  injectionPressureProfile_[i][0] =
81  t.userTimeToTime(injectionPressureProfile_[i][0]);
82  }
83 
84  // check if time entries match
85  if (mag(massFlowRateProfile_[0][0]-injectionPressureProfile_[0][0]) > SMALL)
86  {
88  (
89  "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
90  ) << "Start-times do not match for "
91  "injectionPressureProfile and massFlowRateProfile."
92  << abort(FatalError);
93  }
94 
95  // check if time entries match
96  if
97  (
98  mag
99  (
100  massFlowRateProfile_[massFlowRateProfile_.size() - 1][0]
101  - injectionPressureProfile_[injectionPressureProfile_.size() - 1][0]
102  ) > SMALL
103  )
104  {
106  (
107  "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
108  ) << "End-times do not match for "
109  "injectionPressureProfile and massFlowRateProfile."
110  << abort(FatalError);
111  }
112 
113  scalar integratedMFR = integrateTable(massFlowRateProfile_);
114  scalar integratedPressure =
115  integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
116 
117  forAll(massFlowRateProfile_, i)
118  {
119  // correct the massFlowRateProfile to match the injected mass
120  massFlowRateProfile_[i][1] *= mass_/integratedMFR;
121 
122  velocityProfile_[i][0] = massFlowRateProfile_[i][0];
123 
124  TProfile_[i][0] = massFlowRateProfile_[i][0];
125  TProfile_[i][1] = T_;
126 
127  CdProfile_[i][0] = massFlowRateProfile_[i][0];
128 
129  }
130 
131  forAll(injectionPressureProfile_, i)
132  {
133  // correct the pressureProfile to match the injection pressure
134  injectionPressureProfile_[i][1] *=
135  injectionPressure_/integratedPressure;
136  }
137 
138  // Normalize the direction vector
139  direction_ /= mag(direction_);
140 
141  setTangentialVectors();
142 
143  // check molar fractions
144  scalar Xsum = 0.0;
145  forAll(X_, i)
146  {
147  Xsum += X_[i];
148  }
149 
150  if (mag(Xsum - 1.0) > SMALL)
151  {
152  WarningIn
153  (
154  "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
155  ) << "X does not add up to 1.0, correcting molar fractions." << endl;
156 
157  forAll(X_, i)
158  {
159  X_[i] /= Xsum;
160  }
161  }
162 }
163 
164 
165 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
166 
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
173 void Foam::swirlInjector::setTangentialVectors()
174 {
175  Random rndGen(label(0));
176  scalar magV = 0.0;
177  vector tangent;
178 
179  while (magV < SMALL)
180  {
181  vector testThis = rndGen.vector01();
182 
183  tangent = testThis - (testThis & direction_)*direction_;
184  magV = mag(tangent);
185  }
186 
187  tangentialInjectionVector1_ = tangent/magV;
188  tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
189 }
190 
192 (
193  const scalar time0,
194  const scalar time1
195 ) const
196 {
197 
198  scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
199  label nParcels = label(mInj/averageParcelMass_ + 0.49);
200 
201  return nParcels;
202 }
203 
204 const Foam::vector Foam::swirlInjector::position(const label n) const
205 {
206  return position_;
207 }
208 
210 (
211  const label n,
212  const scalar time,
213  const bool twoD,
214  const scalar angleOfWedge,
215  const vector& axisOfSymmetry,
216  const vector& axisOfWedge,
217  const vector& axisOfWedgeNormal,
218  Random& rndGen
219 ) const
220 {
221  if (twoD)
222  {
223  scalar is = position_ & axisOfSymmetry;
224  scalar magInj = mag(position_ - is*axisOfSymmetry);
225 
226  vector halfWedge =
227  axisOfWedge*cos(0.5*angleOfWedge)
228  + axisOfWedgeNormal*sin(0.5*angleOfWedge);
229  halfWedge /= mag(halfWedge);
230 
231  return (is*axisOfSymmetry + magInj*halfWedge);
232  }
233  else
234  {
235  // otherwise, disc injection
236  scalar iRadius = d_*rndGen.scalar01();
237  scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
238 
239  return
240  (
241  position_
242  + iRadius
243  * (
244  tangentialInjectionVector1_*cos(iAngle)
245  + tangentialInjectionVector2_*sin(iAngle)
246  )
247  );
248 
249  }
250 
251  return position_;
252 }
253 
254 Foam::label Foam::swirlInjector::nHoles() const
255 {
256  return 1;
257 }
258 
259 Foam::scalar Foam::swirlInjector::d() const
260 {
261  return d_;
262 }
263 
265 (
266  const label i,
267  const scalar time
268 ) const
269 {
270  return direction_;
271 }
272 
273 Foam::scalar Foam::swirlInjector::mass
274 (
275  const scalar time0,
276  const scalar time1,
277  const bool twoD,
278  const scalar angleOfWedge
279 ) const
280 {
281  scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
282 
283  // correct mass if calculation is 2D
284  if (twoD)
285  {
286  mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
287  }
288 
289  return mInj;
290 }
291 
292 Foam::scalar Foam::swirlInjector::mass() const
293 {
294  return mass_;
295 }
296 
299 {
300  return massFlowRateProfile_;
301 }
302 
303 Foam::scalar Foam::swirlInjector::massFlowRate(const scalar time) const
304 {
305  return getTableValue(massFlowRateProfile_, time);
306 }
307 
310 {
311  return injectionPressureProfile_;
312 }
313 
314 Foam::scalar Foam::swirlInjector::injectionPressure(const scalar time) const
315 {
316  return getTableValue(injectionPressureProfile_, time);
317 }
318 
321 {
322  return velocityProfile_;
323 }
324 
325 Foam::scalar Foam::swirlInjector::velocity(const scalar time) const
326 {
327  return getTableValue(velocityProfile_, time);
328 }
329 
331 {
332  return CdProfile_;
333 }
334 
335 Foam::scalar Foam::swirlInjector::Cd(const scalar time) const
336 {
337  return getTableValue(CdProfile_, time);
338 }
339 
341 {
342  return X_;
343 }
344 
346 {
347  return TProfile_;
348 }
349 
350 Foam::scalar Foam::swirlInjector::T(const scalar time) const
351 {
352  return T_;
353 }
354 
355 Foam::scalar Foam::swirlInjector::tsoi() const
356 {
357  return massFlowRateProfile_[0][0];
358 }
359 
360 Foam::scalar Foam::swirlInjector::teoi() const
361 {
362  return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
363 }
364 
365 Foam::scalar Foam::swirlInjector::fractionOfInjection(const scalar time) const
366 {
367  return integrateTable(massFlowRateProfile_, time)/mass_;
368 }
369 
371 (
372  const scalar t
373 ) const
374 {
375  return mass_*fractionOfInjection(t);
376 }
377 
379 (
380  const liquidMixture& fuel,
381  const scalar referencePressure
382 )
383 {
384 
385  scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
386  scalar pDummy = 1.0e+5;
387  scalar rho = fuel.rho(pDummy, T_, X_);
388 
389  forAll(velocityProfile_, i)
390  {
391  scalar Pinj = getTableValue
392  (
393  injectionPressureProfile_,
394  massFlowRateProfile_[i][0]
395  );
396  scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
397  scalar v = sqrt(2.0*(Pinj - referencePressure)/rho);
398  velocityProfile_[i][1] = v;
399  CdProfile_[i][1] = mfr/v;
400  }
401 }
402 
404 {
405  return tangentialInjectionVector1_;
406 }
407 
409 {
410  return tangentialInjectionVector2_;
411 }
412 
413 
414 // ************************ vim: set sw=4 sts=4 et: ************************ //