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

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