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

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