1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "commonRailInjector.H"
28 #include "addToRunTimeSelectionTable.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(commonRailInjector, 0);
38 addToRunTimeSelectionTable
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 // Construct from components
50 Foam::commonRailInjector::commonRailInjector
53 const Foam::dictionary& dict
56 injectorType(t, dict),
57 propsDict_(dict.subDict(typeName + "Props")),
58 position_(propsDict_.lookup("position")),
59 direction_(propsDict_.lookup("direction")),
60 d_(readScalar(propsDict_.lookup("diameter"))),
61 mass_(readScalar(propsDict_.lookup("mass"))),
62 injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
63 T_(readScalar(propsDict_.lookup("temperature"))),
64 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
65 X_(propsDict_.lookup("X")),
66 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
67 velocityProfile_(massFlowRateProfile_),
68 injectionPressureProfile_(propsDict_.lookup("injectionPressureProfile")),
69 CdProfile_(massFlowRateProfile_),
70 TProfile_(massFlowRateProfile_),
71 averageParcelMass_(mass_/nParcels_),
72 pressureIndependentVelocity_(false)
75 // convert CA to real time
76 forAll(massFlowRateProfile_, i)
78 massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
79 velocityProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
82 forAll(injectionPressureProfile_, i)
84 injectionPressureProfile_[i][0] = t.userTimeToTime(injectionPressureProfile_[i][0]);
87 if (mag(injectionPressureProfile_[0][0]-massFlowRateProfile_[0][0]) > SMALL)
89 FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
90 << " start-time entries for injectionPressureProfile and massFlowRateProfile do no match"
93 Info << "injectionPressureProfile_.size() = " << injectionPressureProfile_.size()
94 << ", massFlowRateProfile_.size() = " << massFlowRateProfile_.size()
97 if (mag(injectionPressureProfile_[injectionPressureProfile_.size()-1][0]-massFlowRateProfile_[massFlowRateProfile_.size()-1][0]) > SMALL)
99 FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
100 << " end-time entries for injectionPressureProfile and massFlowRateProfile do no match"
101 << abort(FatalError);
104 scalar integratedMFR = integrateTable(massFlowRateProfile_);
105 scalar integratedP = integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
107 forAll(massFlowRateProfile_, i)
109 // correct the massFlowRateProfile to match the injected mass
110 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
112 TProfile_[i][0] = massFlowRateProfile_[i][0];
113 TProfile_[i][1] = T_;
115 CdProfile_[i][0] = massFlowRateProfile_[i][0];
119 forAll(injectionPressureProfile_, i)
121 injectionPressureProfile_[i][1] *= injectionPressure_/integratedP;
123 // Normalize the direction vector
124 direction_ /= mag(direction_);
126 setTangentialVectors();
128 // check molar fractions
135 if (mag(Xsum - 1.0) > SMALL)
137 Info << "Warning!!!\n commonRailInjector::commonRailInjector(const time& t, Istream& is)"
138 << "X does not add up to 1.0, correcting molar fractions."
145 Info << "end constructor. in commonRail" << endl;
149 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
151 Foam::commonRailInjector::~commonRailInjector()
155 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
157 void Foam::commonRailInjector::setTangentialVectors()
159 Random rndGen(label(0));
165 vector testThis = rndGen.vector01();
167 tangent = testThis - (testThis & direction_)*direction_;
171 tangentialInjectionVector1_ = tangent/magV;
172 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
177 Foam::label Foam::commonRailInjector::nParcelsToInject
184 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
185 label nParcels = label(mInj/averageParcelMass_ + 0.49);
190 const Foam::vector Foam::commonRailInjector::position(const label n) const
195 Foam::vector Foam::commonRailInjector::position
200 const scalar angleOfWedge,
201 const vector& axisOfSymmetry,
202 const vector& axisOfWedge,
203 const vector& axisOfWedgeNormal,
209 scalar is = position_ & axisOfSymmetry;
210 scalar magInj = mag(position_ - is*axisOfSymmetry);
213 axisOfWedge*cos(0.5*angleOfWedge)
214 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
215 halfWedge /= mag(halfWedge);
217 return (is*axisOfSymmetry + magInj*halfWedge);
221 // otherwise, disc injection
222 scalar iRadius = d_*rndGen.scalar01();
223 scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
230 tangentialInjectionVector1_*cos(iAngle)
231 + tangentialInjectionVector2_*sin(iAngle)
240 Foam::label Foam::commonRailInjector::nHoles() const
245 Foam::scalar Foam::commonRailInjector::d() const
250 const Foam::vector& Foam::commonRailInjector::direction
259 Foam::scalar Foam::commonRailInjector::mass
264 const scalar angleOfWedge
267 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
269 // correct mass if calculation is 2D
272 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
278 Foam::scalar Foam::commonRailInjector::mass() const
283 const Foam::scalarField& Foam::commonRailInjector::X() const
288 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::T() const
293 Foam::scalar Foam::commonRailInjector::T(const scalar time) const
298 Foam::scalar Foam::commonRailInjector::tsoi() const
300 return massFlowRateProfile_[0][0];
303 Foam::scalar Foam::commonRailInjector::teoi() const
305 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
308 Foam::scalar Foam::commonRailInjector::massFlowRate
313 return getTableValue(massFlowRateProfile_, time);
316 Foam::scalar Foam::commonRailInjector::injectionPressure
321 return getTableValue(injectionPressureProfile_, time);
324 Foam::scalar Foam::commonRailInjector::velocity
329 return getTableValue(velocityProfile_, time);
332 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::CdProfile() const
337 Foam::scalar Foam::commonRailInjector::Cd
342 return getTableValue(CdProfile_, time);
345 Foam::scalar Foam::commonRailInjector::fractionOfInjection(const scalar time) const
347 return integrateTable(massFlowRateProfile_, time)/mass_;
350 Foam::scalar Foam::commonRailInjector::injectedMass
355 return mass_*fractionOfInjection(t);
359 void Foam::commonRailInjector::correctProfiles
361 const liquidMixture& fuel,
362 const scalar referencePressure
365 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
366 scalar pDummy = 1.0e+5;
367 scalar rho = fuel.rho(pDummy, T_, X_);
369 forAll(velocityProfile_, i)
371 scalar Pinj = getTableValue(injectionPressureProfile_, velocityProfile_[i][0]);
372 scalar Vinj = sqrt(2.0*(Pinj - referencePressure)/rho);
373 scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
374 scalar Cd = mfr/Vinj;
375 velocityProfile_[i][1] = Vinj;
376 CdProfile_[i][1] = Cd;
380 Foam::vector Foam::commonRailInjector::tan1(const label n) const
382 return tangentialInjectionVector1_;
385 Foam::vector Foam::commonRailInjector::tan2(const label n) const
387 return tangentialInjectionVector2_;
390 // ************************************************************************* //