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

sprayFunctions.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 "spray.H"
00028 #include "mathematicalConstants.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00036 
00037 scalar spray::injectedMass(const scalar t) const
00038 {
00039     scalar sum = 0.0;
00040 
00041     forAll (injectors_, i)
00042     {
00043         sum += injectors_[i].properties()->injectedMass(t);
00044     }
00045 
00046     return sum;
00047 }
00048 
00049 
00050 scalar spray::totalMassToInject() const
00051 {
00052     scalar sum = 0.0;
00053 
00054     forAll (injectors_, i)
00055     {
00056         sum += injectors_[i].properties()->mass();
00057     }
00058 
00059     return sum;
00060 }
00061 
00062 
00063 scalar spray::injectedEnthalpy
00064 (
00065     const scalar time
00066 ) const
00067 {
00068     scalar sum = 0.0;
00069     label Nf = fuels_->components().size();
00070 
00071     forAll (injectors_, i)
00072     {
00073         scalar T = injectors_[i].properties()->T(time);
00074         scalarField X(injectors_[i].properties()->X());
00075         scalar pi = 1.0e+5;
00076         scalar hl = fuels_->hl(pi, T, X);
00077         scalar Wl = fuels_->W(X);
00078         scalar hg = 0.0;
00079 
00080         for(label j=0; j<Nf; j++)
00081         {
00082             label k = liquidToGasIndex_[j];
00083             hg += gasProperties()[k].H(T)*gasProperties()[k].W()*X[j]/Wl;
00084         }
00085 
00086         sum += injectors_[i].properties()->injectedMass(time)*(hg-hl);
00087     }
00088 
00089     return sum;
00090 }
00091 
00092 
00093 scalar spray::liquidMass() const
00094 {
00095     scalar sum = 0.0;
00096 
00097     for
00098     (
00099         spray::const_iterator elmnt = begin();
00100         elmnt != end();
00101         ++elmnt
00102     )
00103     {
00104         sum += elmnt().m();
00105     }
00106 
00107     if (twoD())
00108     {
00109         sum *= 2.0*mathematicalConstant::pi/angleOfWedge();
00110     }
00111 
00112     reduce(sum, sumOp<scalar>());
00113 
00114     return sum;
00115 }
00116 
00117 
00118 scalar spray::liquidEnthalpy() const
00119 {
00120     scalar sum = 0.0;
00121     label Nf = fuels().components().size();
00122 
00123     for
00124     (
00125         spray::const_iterator elmnt = begin();
00126         elmnt != end();
00127         ++elmnt
00128     )
00129     {
00130         scalar T = elmnt().T();
00131         scalar pc = p()[elmnt().cell()];
00132         scalar hlat = fuels().hl(pc, T, elmnt().X());
00133         scalar hg = 0.0;
00134         scalar Wl = fuels().W(elmnt().X());
00135 
00136         for(label j=0; j<Nf; j++)
00137         {
00138             label k = liquidToGasIndex_[j];
00139 
00140             hg += 
00141                 gasProperties()[k].H(T)*gasProperties()[k].W()*elmnt().X()[j]
00142                /Wl;
00143         }
00144 
00145         scalar h = hg - hlat;
00146         sum += elmnt().m()*h;
00147     }
00148 
00149     if (twoD())
00150     {
00151         sum *= 2.0*mathematicalConstant::pi/angleOfWedge();
00152     }
00153 
00154     reduce(sum, sumOp<scalar>());
00155 
00156     return sum;
00157 }
00158 
00159 
00160 scalar spray::liquidTotalEnthalpy() const
00161 {
00162     scalar sum = 0.0;
00163     label Nf = fuels().components().size();
00164 
00165     for
00166     (
00167         spray::const_iterator elmnt = begin();
00168         elmnt != end();
00169         ++elmnt
00170     )
00171     {
00172         label celli = elmnt().cell();
00173         scalar T = elmnt().T();
00174         scalar pc = p()[celli];
00175         scalar rho = fuels().rho(pc, T, elmnt().X());
00176         scalar hlat = fuels().hl(pc, T, elmnt().X());
00177         scalar hg = 0.0;
00178         scalar Wl = fuels().W(elmnt().X());
00179 
00180         for(label j=0; j<Nf; j++)
00181         {
00182             label k = liquidToGasIndex_[j];
00183             hg += 
00184                 gasProperties()[k].H(T)*gasProperties()[k].W()*elmnt().X()[j]
00185                /Wl;
00186         }
00187 
00188         scalar psat = fuels().pv(pc, T, elmnt().X());
00189 
00190         scalar h = hg - hlat + (pc - psat)/rho;
00191         sum += elmnt().m()*h;
00192     }
00193 
00194     if (twoD())
00195     {
00196         sum *= 2.0*mathematicalConstant::pi/angleOfWedge();
00197     }
00198 
00199     reduce(sum, sumOp<scalar>());
00200 
00201     return sum;
00202 }
00203 
00204 
00205 scalar spray::liquidKineticEnergy() const
00206 {
00207     scalar sum = 0.0;
00208     for
00209     (
00210         spray::const_iterator elmnt = begin();
00211         elmnt != end();
00212         ++elmnt
00213     )
00214     {
00215         scalar ke = pow(mag(elmnt().U()), 2.0);
00216         sum += elmnt().m()*ke;
00217     }
00218 
00219     if (twoD())
00220     {
00221         sum *= 2.0*mathematicalConstant::pi/angleOfWedge();
00222     }
00223 
00224     reduce(sum, sumOp<scalar>());
00225 
00226     return 0.5*sum;
00227 
00228 }
00229 
00230 
00231 scalar spray::injectedLiquidKineticEnergy() const
00232 {
00233     return injectedLiquidKE_;
00234 }
00235 
00236 
00237 scalar spray::liquidPenetration(const scalar prc) const
00238 {
00239     return liquidPenetration(0, prc);
00240 }
00241 
00242 
00243 scalar spray::liquidPenetration
00244 (
00245     const label nozzlei,
00246     const scalar prc
00247 ) const
00248 {
00249 
00250     label nHoles = injectors_[nozzlei].properties()->nHoles();
00251     vector ip(vector::zero);
00252     if (nHoles > 1)
00253     {
00254         for(label i=0;i<nHoles;i++)
00255         {
00256             ip += injectors_[nozzlei].properties()->position(i);
00257         }
00258         ip /= nHoles;
00259     }
00260     else
00261     {
00262         ip = injectors_[nozzlei].properties()->position(0);
00263     }
00264 
00265 //    vector ip = injectors_[nozzlei].properties()->position();
00266     scalar d = 0.0;
00267     scalar mTot = 0.0;
00268 
00269     label Np = size();
00270     
00271     // arrays containing the parcels mass and
00272     // distance from injector in ascending order
00273     scalarField m(Np);
00274     scalarField dist(Np);
00275     label n = 0;
00276 
00277     if (Np > 1)
00278     {
00279         // NN.
00280         // first arrange the parcels in ascending order
00281         // the first parcel is closest to injector
00282         // and the last one is most far away.
00283         spray::const_iterator first = begin();
00284         m[n] = first().m();
00285         dist[n] = mag(first().position() - ip);
00286 
00287         mTot += m[n];
00288 
00289         for
00290         (
00291             spray::const_iterator elmnt = ++first;
00292             elmnt != end();
00293             ++elmnt
00294         )
00295         {
00296             scalar de = mag(elmnt().position() - ip);
00297             scalar me = elmnt().m();
00298             mTot += me;
00299 
00300             n++;
00301 
00302             label i = 0;
00303             bool found = false;
00304 
00305             // insert the parcel in the correct place
00306             // and move the others 
00307             while ( ( i < n-1 ) && ( !found ) ) 
00308             {
00309                 if (de < dist[i])
00310                 {
00311                     found = true;
00312                     for(label j=n; j>i; j--)
00313                     {
00314                         m[j]    = m[j-1];
00315                         dist[j] = dist[j-1];
00316                     }
00317                     m[i]    = me;
00318                     dist[i] = de;
00319                 }
00320                 i++;
00321             }
00322 
00323             if (!found)
00324             {
00325                 m[n]    = me;
00326                 dist[n] = de;
00327             }
00328         }
00329     }
00330 
00331     reduce(mTot, sumOp<scalar>());
00332 
00333     if (Np > 1)
00334     {
00335         scalar mLimit = prc*mTot;
00336         scalar mOff = (1.0 - prc)*mTot;
00337 
00338         // 'prc' is large enough that the parcel most far
00339         // away will be used, no need to loop...
00340         if (mLimit > mTot - m[Np-1])
00341         {
00342             d = dist[Np-1];
00343         }
00344         else
00345         {
00346             scalar mOffSum = 0.0;
00347             label i = Np;
00348 
00349             while ((mOffSum < mOff) && (i>0))
00350             {
00351                 i--;
00352                 mOffSum += m[i];
00353             }
00354             d = dist[i];
00355         }
00356 
00357     }
00358     else
00359     {
00360         if (Np > 0)
00361         {
00362             spray::const_iterator elmnt = begin();
00363             d = mag(elmnt().position() - ip);
00364         }
00365     }
00366 
00367     reduce(d, maxOp<scalar>());
00368 
00369     return d;
00370 }
00371 
00372 
00373 scalar spray::smd() const
00374 {
00375     scalar numerator = 0.0, denominator = VSMALL;
00376 
00377     for
00378     (
00379         spray::const_iterator elmnt = begin();
00380         elmnt != end();
00381         ++elmnt
00382     )
00383     {
00384         label celli = elmnt().cell();
00385         scalar Pc = p()[celli];
00386         scalar T = elmnt().T();
00387         scalar rho = fuels_->rho(Pc, T, elmnt().X());
00388 
00389         scalar tmp = elmnt().N(rho)*pow(elmnt().d(), 2.0);
00390         numerator += tmp*elmnt().d();
00391         denominator += tmp;
00392     }
00393 
00394     reduce(numerator, sumOp<scalar>());
00395     reduce(denominator, sumOp<scalar>());
00396 
00397     return numerator/denominator;
00398 }
00399 
00400 
00401 scalar spray::maxD() const
00402 {
00403     scalar maxD = 0.0;
00404 
00405     for
00406     (
00407         spray::const_iterator elmnt = begin();
00408         elmnt != end();
00409         ++elmnt
00410     )
00411     {
00412         maxD = max(maxD, elmnt().d());
00413     }
00414 
00415     reduce(maxD, maxOp<scalar>());
00416 
00417     return maxD;
00418 }
00419 
00420 
00421 void spray::calculateAmbientPressure()
00422 {
00423     ambientPressure_ = p_.average().value();
00424 }
00425 
00426 
00427 void spray::calculateAmbientTemperature()
00428 {
00429     ambientTemperature_ = T_.average().value();
00430 }
00431 
00432 
00433 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00434 
00435 } // End namespace Foam
00436 
00437 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd