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

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