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

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