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

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