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

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