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

multiHoleInjector.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 "multiHoleInjector.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(multiHoleInjector, 0);
00037 
00038 addToRunTimeSelectionTable
00039 (
00040     injectorType,
00041     multiHoleInjector,
00042     dictionary
00043 );
00044 }
00045 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 // Construct from components
00050 Foam::multiHoleInjector::multiHoleInjector
00051 (
00052     const Foam::Time& t,
00053     const Foam::dictionary& dict
00054 )
00055 :
00056     injectorType(t, dict),
00057     propsDict_(dict.subDict(typeName + "Props")),
00058     centerPosition_(propsDict_.lookup("position")),
00059     xyAngle_(readScalar(propsDict_.lookup("xyAngle"))),
00060     zAngle_(readScalar(propsDict_.lookup("zAngle"))),
00061     nHoles_(readLabel(propsDict_.lookup("nHoles"))),
00062     umbrellaAngle_(readScalar(propsDict_.lookup("umbrellaAngle"))),
00063     nozzleTipDiameter_(readScalar(propsDict_.lookup("nozzleTipDiameter"))),
00064     angleSpacing_(propsDict_.lookup("angleSpacing")),
00065     d_(readScalar(propsDict_.lookup("diameter"))),
00066     Cd_(readScalar(propsDict_.lookup("Cd"))),
00067     mass_(readScalar(propsDict_.lookup("mass"))),
00068     nParcels_(readLabel(propsDict_.lookup("nParcels"))),
00069     X_(propsDict_.lookup("X")),
00070     massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
00071     velocityProfile_(massFlowRateProfile_),
00072     injectionPressureProfile_(massFlowRateProfile_),
00073     CdProfile_(massFlowRateProfile_),
00074     TProfile_(propsDict_.lookup("temperatureProfile")),
00075     averageParcelMass_(nHoles_*mass_/nParcels_),
00076     direction_(nHoles_),
00077     position_(nHoles_),
00078     pressureIndependentVelocity_(true),
00079     tangentialInjectionVector1_(nHoles_),
00080     tangentialInjectionVector2_(nHoles_)
00081 {
00082 
00083 
00084     // check if time entries for soi and eoi match
00085     if (mag(massFlowRateProfile_[0][0]-TProfile_[0][0]) > SMALL)
00086     {
00087         FatalError << "multiHoleInjector::multiHoleInjector(const time& t, const dictionary dict) " << endl
00088             << " start-times do not match for TemperatureProfile and massFlowRateProfile."
00089             << abort(FatalError);
00090     }
00091 
00092     if (mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]-TProfile_[TProfile_.size()-1][0]) > SMALL)
00093     {
00094         FatalError << "multiHoleInjector::multiHoleInjector(const time& t, const dictionary dict) " << endl
00095             << " end-times do not match for TemperatureProfile and massFlowRateProfile."
00096             << abort(FatalError);
00097     }
00098 
00099     // convert CA to real time
00100     forAll(massFlowRateProfile_, i)
00101     {
00102         massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
00103         velocityProfile_[i][0] = massFlowRateProfile_[i][0];
00104         injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
00105     }
00106     
00107     forAll(TProfile_, i)
00108     {
00109         TProfile_[i][0] = t.userTimeToTime(TProfile_[i][0]);
00110     }
00111 
00112     scalar integratedMFR = integrateTable(massFlowRateProfile_);
00113 
00114     forAll(massFlowRateProfile_, i)
00115     {
00116         // correct the massFlowRateProfile to match the injected mass
00117         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
00118         
00119         CdProfile_[i][0] = massFlowRateProfile_[i][0];
00120         CdProfile_[i][1] = Cd_;
00121     }
00122 
00123     setTangentialVectors();
00124 
00125     // check molar fractions
00126     scalar Xsum = 0.0;
00127     forAll(X_, i)
00128     {
00129         Xsum += X_[i];
00130     }
00131 
00132     if (mag(Xsum - 1.0) > SMALL)
00133     {
00134         Info << "Warning!!!\n multiHoleInjector::multiHoleInjector(const time& t, Istream& is)"
00135             << "X does not add up to 1.0, correcting molar fractions."
00136             << endl;
00137         forAll(X_, i)
00138         {
00139             X_[i] /= Xsum;
00140         }
00141     }
00142 
00143 }
00144 
00145 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00146 
00147 Foam::multiHoleInjector::~multiHoleInjector()
00148 {}
00149 
00150 
00151 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00152 
00153 void Foam::multiHoleInjector::setTangentialVectors()
00154 {
00155     scalar pi180 = mathematicalConstant::pi/180.0;
00156     scalar alpha = xyAngle_*pi180;
00157     scalar phi = zAngle_*pi180;
00158 
00159     vector xp(cos(alpha), sin(alpha), 0.0);
00160     vector zp(cos(alpha)*sin(phi), sin(alpha)*sin(phi), cos(phi));
00161     if (mag(zp-xp) < 1.0e-15)
00162     {
00163         xp = vector(0.0, 0.0, -1.0);
00164         xp -= (xp & zp)*zp;
00165         xp /= mag(xp);
00166     }
00167     vector yp = zp^xp;
00168 
00169 //    Info << "xp = " << xp << endl;
00170 //    Info << "yp = " << yp << endl;
00171 //    Info << "zp = " << zp << endl;
00172 
00173     scalar angle = 0.0;
00174     scalar u = umbrellaAngle_*pi180/2.0;
00175     for(label i=0; i<nHoles_; i++)
00176     {
00177         angle += angleSpacing_[i];
00178         scalar v = angle*pi180;
00179         direction_[i] = cos(v)*sin(u)*xp + sin(v)*sin(u)*yp + cos(u)*zp;
00180         vector dp = direction_[i] - (direction_[i] & zp)*direction_[i];
00181         if (mag(dp) > SMALL)
00182         {
00183             dp /= mag(dp);
00184         }
00185         position_[i] = centerPosition_ + 0.5*nozzleTipDiameter_*dp;
00186 //        Info << "i = " << i << ", dir = " << direction_[i] << ", pos = " << position_[i] << endl;
00187     }
00188 
00189     Random rndGen(label(0));
00190 
00191     for(label i=0; i<nHoles_; i++)
00192     {
00193         vector tangent(vector::zero);
00194         scalar magV = 0;
00195         while (magV < SMALL)
00196         {
00197             vector testThis = rndGen.vector01();
00198             
00199             tangent = testThis - (testThis & direction_[i])*direction_[i];
00200             magV = mag(tangent);
00201         }
00202 
00203         tangentialInjectionVector1_[i] = tangent/magV;
00204         tangentialInjectionVector2_[i] = direction_[i] ^ tangentialInjectionVector1_[i];
00205 
00206     }   
00207 }
00208 
00209 
00210 Foam::label Foam::multiHoleInjector::nParcelsToInject
00211 (
00212     const scalar time0,
00213     const scalar time1
00214 ) const
00215 {
00216 
00217     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
00218     label nParcels = label(mInj/averageParcelMass_ + 0.49);
00219     
00220     return nParcels;
00221 }
00222 
00223 const Foam::vector Foam::multiHoleInjector::position(const label n) const
00224 {
00225     return position_[n];
00226 }
00227 
00228 Foam::vector Foam::multiHoleInjector::position
00229 (
00230     const label n,
00231     const scalar time,
00232     const bool twoD,
00233     const scalar angleOfWedge,
00234     const vector& axisOfSymmetry,
00235     const vector& axisOfWedge,
00236     const vector& axisOfWedgeNormal,
00237     Random& rndGen
00238 ) const
00239 {
00240     if (twoD)
00241     {
00242         scalar is = position_[n] & axisOfSymmetry;
00243         scalar magInj = mag(position_[n] - is*axisOfSymmetry);
00244 
00245         vector halfWedge =
00246             axisOfWedge*cos(0.5*angleOfWedge)
00247           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
00248         halfWedge /= mag(halfWedge);
00249 
00250         return (is*axisOfSymmetry + magInj*halfWedge);
00251     }
00252     else
00253     {
00254         // otherwise, disc injection
00255         scalar iRadius = d_*rndGen.scalar01();
00256         scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
00257 
00258         return
00259         ( 
00260             position_[n]
00261           + iRadius
00262           * (
00263               tangentialInjectionVector1_[n]*cos(iAngle)
00264             + tangentialInjectionVector2_[n]*sin(iAngle)
00265           )
00266         );
00267         
00268     }
00269     return position_[0];
00270 }
00271 
00272 Foam::label Foam::multiHoleInjector::nHoles() const
00273 {
00274     return nHoles_;
00275 }
00276 
00277 Foam::scalar Foam::multiHoleInjector::d() const
00278 {
00279     return d_;
00280 }
00281 
00282 const Foam::vector& Foam::multiHoleInjector::direction
00283 (
00284     const label i,
00285     const scalar time
00286 ) const
00287 {
00288     return direction_[i];
00289 }
00290 
00291 Foam::scalar Foam::multiHoleInjector::mass
00292 (
00293     const scalar time0,
00294     const scalar time1,
00295     const bool twoD,
00296     const scalar angleOfWedge
00297 ) const
00298 {
00299     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
00300 
00301     // correct mass if calculation is 2D 
00302     if (twoD)
00303     {
00304         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
00305     }
00306 
00307     return mInj;
00308 }
00309 
00310 Foam::scalar Foam::multiHoleInjector::mass() const
00311 {
00312     return mass_;
00313 }
00314 
00315 const Foam::scalarField& Foam::multiHoleInjector::X() const
00316 {
00317     return X_;
00318 }
00319 
00320 Foam::List<Foam::multiHoleInjector::pair> Foam::multiHoleInjector::T() const
00321 {
00322     return TProfile_;
00323 }
00324 
00325 Foam::scalar Foam::multiHoleInjector::T(const scalar time) const
00326 {
00327     return getTableValue(TProfile_, time);
00328 }
00329 
00330 Foam::scalar Foam::multiHoleInjector::tsoi() const
00331 {
00332     return massFlowRateProfile_[0][0];
00333 }
00334 
00335 Foam::scalar Foam::multiHoleInjector::teoi() const
00336 {
00337     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
00338 }
00339 
00340 Foam::scalar Foam::multiHoleInjector::massFlowRate
00341 (
00342     const scalar time
00343 ) const
00344 {
00345     return getTableValue(massFlowRateProfile_, time);
00346 }
00347 
00348 Foam::scalar Foam::multiHoleInjector::injectionPressure
00349 (
00350     const scalar time
00351 ) const
00352 {
00353     return getTableValue(injectionPressureProfile_, time);
00354 }
00355 
00356 Foam::scalar Foam::multiHoleInjector::velocity
00357 (
00358     const scalar time
00359 ) const
00360 {
00361     return getTableValue(velocityProfile_, time);
00362 }
00363 
00364 Foam::List<Foam::multiHoleInjector::pair> Foam::multiHoleInjector::CdProfile() const
00365 {
00366     return CdProfile_;
00367 }
00368 
00369 Foam::scalar Foam::multiHoleInjector::Cd
00370 (
00371     const scalar time
00372 ) const
00373 {
00374     return Cd_;
00375 }
00376 
00377 Foam::scalar Foam::multiHoleInjector::fractionOfInjection(const scalar time) const
00378 {
00379     return integrateTable(massFlowRateProfile_, time)/mass_;
00380 }
00381 
00382 Foam::scalar Foam::multiHoleInjector::injectedMass
00383 (
00384     const scalar t
00385 ) const
00386 {
00387     return mass_*fractionOfInjection(t);
00388 }
00389 
00390 
00391 void Foam::multiHoleInjector::correctProfiles
00392 (
00393     const liquidMixture& fuel,
00394     const scalar referencePressure
00395 )
00396 {
00397 
00398     scalar A = nHoles_*0.25*mathematicalConstant::pi*pow(d_, 2.0);
00399 
00400     forAll(velocityProfile_, i)
00401     {
00402         scalar time = velocityProfile_[i][0];
00403         scalar rho = fuel.rho(referencePressure, T(time), X_);
00404         scalar v = massFlowRateProfile_[i][1]/(Cd_*rho*A);
00405         velocityProfile_[i][1] = v;
00406         injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
00407     }
00408 }
00409 
00410 Foam::vector Foam::multiHoleInjector::tan1(const label n) const
00411 {
00412     return tangentialInjectionVector1_[n];
00413 }
00414 
00415 Foam::vector Foam::multiHoleInjector::tan2(const label n) const
00416 {
00417     return tangentialInjectionVector2_[n];
00418 }
00419 
00420 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd