FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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