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