OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

commonRailInjector.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "commonRailInjector.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "Random.H"
00030 #include "mathematicalConstants.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 namespace Foam
00034 {
00035 
00036 defineTypeNameAndDebug(commonRailInjector, 0);
00037 
00038 addToRunTimeSelectionTable
00039 (
00040     injectorType,
00041     commonRailInjector,
00042     dictionary
00043 );
00044 }
00045 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 // Construct from components
00050 Foam::commonRailInjector::commonRailInjector
00051 (
00052     const Foam::Time& t,
00053     const Foam::dictionary& dict
00054 )
00055 :
00056     injectorType(t, dict),
00057     propsDict_(dict.subDict(typeName + "Props")),
00058     position_(propsDict_.lookup("position")),
00059     direction_(propsDict_.lookup("direction")),
00060     d_(readScalar(propsDict_.lookup("diameter"))),
00061     mass_(readScalar(propsDict_.lookup("mass"))),
00062     injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
00063     T_(readScalar(propsDict_.lookup("temperature"))),
00064     nParcels_(readLabel(propsDict_.lookup("nParcels"))),
00065     X_(propsDict_.lookup("X")),
00066     massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
00067     velocityProfile_(massFlowRateProfile_),
00068     injectionPressureProfile_(propsDict_.lookup("injectionPressureProfile")),
00069     CdProfile_(massFlowRateProfile_),
00070     TProfile_(massFlowRateProfile_),
00071     averageParcelMass_(mass_/nParcels_),
00072     pressureIndependentVelocity_(false)
00073 {
00074 
00075     // convert CA to real time
00076     forAll(massFlowRateProfile_, i)
00077     {
00078         massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
00079         velocityProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
00080     }
00081 
00082     forAll(injectionPressureProfile_, i)
00083     {
00084         injectionPressureProfile_[i][0] = t.userTimeToTime(injectionPressureProfile_[i][0]);
00085     }
00086 
00087     if (mag(injectionPressureProfile_[0][0]-massFlowRateProfile_[0][0]) > SMALL)
00088     {
00089         FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
00090                 << " start-time entries for injectionPressureProfile and massFlowRateProfile do no match"
00091                 << abort(FatalError);
00092     }
00093     Info << "injectionPressureProfile_.size() = " << injectionPressureProfile_.size()
00094         << ", massFlowRateProfile_.size() = " << massFlowRateProfile_.size()
00095         << endl;
00096 
00097     if (mag(injectionPressureProfile_[injectionPressureProfile_.size()-1][0]-massFlowRateProfile_[massFlowRateProfile_.size()-1][0]) > SMALL)
00098     {
00099         FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
00100                 << " end-time entries for injectionPressureProfile and massFlowRateProfile do no match"
00101                 << abort(FatalError);
00102     }
00103 
00104     scalar integratedMFR = integrateTable(massFlowRateProfile_);
00105     scalar integratedP = integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
00106 
00107     forAll(massFlowRateProfile_, i)
00108     {
00109         // correct the massFlowRateProfile to match the injected mass
00110         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
00111 
00112         TProfile_[i][0] = massFlowRateProfile_[i][0];
00113         TProfile_[i][1] = T_;
00114 
00115         CdProfile_[i][0] = massFlowRateProfile_[i][0];
00116 
00117     }
00118 
00119     forAll(injectionPressureProfile_, i)
00120     {
00121         injectionPressureProfile_[i][1] *= injectionPressure_/integratedP;
00122     }
00123     // Normalize the direction vector
00124     direction_ /= mag(direction_);
00125     
00126     setTangentialVectors();
00127 
00128     // check molar fractions
00129     scalar Xsum = 0.0;
00130     forAll(X_, i)
00131     {
00132         Xsum += X_[i];
00133     }
00134 
00135     if (mag(Xsum - 1.0) > SMALL)
00136     {
00137         Info << "Warning!!!\n commonRailInjector::commonRailInjector(const time& t, Istream& is)"
00138             << "X does not add up to 1.0, correcting molar fractions."
00139             << endl;
00140         forAll(X_, i)
00141         {
00142             X_[i] /= Xsum;
00143         }
00144     }
00145     Info << "end constructor. in commonRail" << endl;
00146 
00147 }
00148 
00149 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00150 
00151 Foam::commonRailInjector::~commonRailInjector()
00152 {}
00153 
00154 
00155 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00156 
00157 void Foam::commonRailInjector::setTangentialVectors()
00158 {
00159     Random rndGen(label(0));
00160     scalar magV = 0.0;
00161     vector tangent;
00162 
00163     while (magV < SMALL)
00164     {
00165         vector testThis = rndGen.vector01();
00166 
00167         tangent = testThis - (testThis & direction_)*direction_;
00168         magV = mag(tangent);
00169     }
00170 
00171     tangentialInjectionVector1_ = tangent/magV;
00172     tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
00173 
00174 }
00175 
00176 
00177 Foam::label Foam::commonRailInjector::nParcelsToInject
00178 (
00179     const scalar time0,
00180     const scalar time1
00181 ) const
00182 {
00183 
00184     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
00185     label nParcels = label(mInj/averageParcelMass_ + 0.49);
00186     
00187     return nParcels;
00188 }
00189 
00190 const Foam::vector Foam::commonRailInjector::position(const label n) const
00191 {
00192     return position_;
00193 }
00194 
00195 Foam::vector Foam::commonRailInjector::position
00196 (
00197     const label n,
00198     const scalar time,
00199     const bool twoD,
00200     const scalar angleOfWedge,
00201     const vector& axisOfSymmetry,
00202     const vector& axisOfWedge,
00203     const vector& axisOfWedgeNormal,
00204     Random& rndGen
00205 ) const
00206 {
00207     if (twoD)
00208     {
00209         scalar is = position_ & axisOfSymmetry;
00210         scalar magInj = mag(position_ - is*axisOfSymmetry);
00211 
00212         vector halfWedge =
00213             axisOfWedge*cos(0.5*angleOfWedge)
00214           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
00215         halfWedge /= mag(halfWedge);
00216 
00217         return (is*axisOfSymmetry + magInj*halfWedge);
00218     }
00219     else
00220     {
00221         // otherwise, disc injection
00222         scalar iRadius = d_*rndGen.scalar01();
00223         scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
00224 
00225         return
00226         ( 
00227             position_
00228           + iRadius
00229           * (
00230               tangentialInjectionVector1_*cos(iAngle)
00231             + tangentialInjectionVector2_*sin(iAngle)
00232           )
00233         );
00234         
00235     }
00236 
00237     return position_;
00238 }
00239 
00240 Foam::label Foam::commonRailInjector::nHoles() const
00241 {
00242     return 1;
00243 }
00244 
00245 Foam::scalar Foam::commonRailInjector::d() const
00246 {
00247     return d_;
00248 }
00249 
00250 const Foam::vector& Foam::commonRailInjector::direction
00251 (
00252     const label i,
00253     const scalar time
00254 ) const
00255 {
00256     return direction_;
00257 }
00258 
00259 Foam::scalar Foam::commonRailInjector::mass
00260 (
00261     const scalar time0,
00262     const scalar time1,
00263     const bool twoD,
00264     const scalar angleOfWedge
00265 ) const
00266 {
00267     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
00268 
00269     // correct mass if calculation is 2D 
00270     if (twoD)
00271     {
00272         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
00273     }
00274 
00275     return mInj;
00276 }
00277 
00278 Foam::scalar Foam::commonRailInjector::mass() const
00279 {
00280     return mass_;
00281 }
00282 
00283 const Foam::scalarField& Foam::commonRailInjector::X() const
00284 {
00285     return X_;
00286 }
00287 
00288 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::T() const
00289 {
00290     return TProfile_;
00291 }
00292 
00293 Foam::scalar Foam::commonRailInjector::T(const scalar time) const
00294 {
00295     return T_;
00296 }
00297 
00298 Foam::scalar Foam::commonRailInjector::tsoi() const
00299 {
00300     return massFlowRateProfile_[0][0];
00301 }
00302 
00303 Foam::scalar Foam::commonRailInjector::teoi() const
00304 {
00305     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
00306 }
00307 
00308 Foam::scalar Foam::commonRailInjector::massFlowRate
00309 (
00310     const scalar time
00311 ) const
00312 {
00313     return getTableValue(massFlowRateProfile_, time);
00314 }
00315 
00316 Foam::scalar Foam::commonRailInjector::injectionPressure
00317 (
00318     const scalar time
00319 ) const
00320 {
00321     return getTableValue(injectionPressureProfile_, time);
00322 }
00323 
00324 Foam::scalar Foam::commonRailInjector::velocity
00325 (
00326     const scalar time
00327 ) const
00328 {
00329     return getTableValue(velocityProfile_, time);
00330 }
00331 
00332 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::CdProfile() const
00333 {
00334     return CdProfile_;
00335 }
00336 
00337 Foam::scalar Foam::commonRailInjector::Cd
00338 (
00339     const scalar time
00340 ) const
00341 {
00342     return getTableValue(CdProfile_, time);
00343 }
00344 
00345 Foam::scalar Foam::commonRailInjector::fractionOfInjection(const scalar time) const
00346 {
00347     return integrateTable(massFlowRateProfile_, time)/mass_;
00348 }
00349 
00350 Foam::scalar Foam::commonRailInjector::injectedMass
00351 (
00352     const scalar t
00353 ) const
00354 {
00355     return mass_*fractionOfInjection(t);
00356 }
00357 
00358 
00359 void Foam::commonRailInjector::correctProfiles
00360 (
00361     const liquidMixture& fuel,
00362     const scalar referencePressure
00363 )
00364 {
00365     scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
00366     scalar pDummy = 1.0e+5;
00367     scalar rho = fuel.rho(pDummy, T_, X_);
00368 
00369     forAll(velocityProfile_, i)
00370     {
00371         scalar Pinj = getTableValue(injectionPressureProfile_, velocityProfile_[i][0]);
00372         scalar Vinj = sqrt(2.0*(Pinj - referencePressure)/rho);
00373         scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
00374         scalar Cd = mfr/Vinj;
00375         velocityProfile_[i][1] = Vinj;
00376         CdProfile_[i][1] = Cd;
00377     }
00378 }
00379 
00380 Foam::vector Foam::commonRailInjector::tan1(const label n) const
00381 {
00382     return tangentialInjectionVector1_;
00383 }
00384 
00385 Foam::vector Foam::commonRailInjector::tan2(const label n) const
00386 {
00387     return tangentialInjectionVector2_;
00388 }
00389 
00390 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd