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

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