1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "unitInjector.H"
28 #include "addToRunTimeSelectionTable.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(unitInjector, 0);
38 addToRunTimeSelectionTable
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 // Construct from components
50 Foam::unitInjector::unitInjector
53 const Foam::dictionary& dict
56 injectorType(t, dict),
57 propsDict_(dict.subDict(typeName + "Props")),
58 position_(propsDict_.lookup("position")),
59 direction_(propsDict_.lookup("direction")),
60 d_(readScalar(propsDict_.lookup("diameter"))),
61 Cd_(readScalar(propsDict_.lookup("Cd"))),
62 mass_(readScalar(propsDict_.lookup("mass"))),
63 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
64 X_(propsDict_.lookup("X")),
65 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
66 velocityProfile_(massFlowRateProfile_),
67 injectionPressureProfile_(massFlowRateProfile_),
68 CdProfile_(massFlowRateProfile_),
69 TProfile_(propsDict_.lookup("temperatureProfile")),
70 averageParcelMass_(mass_/nParcels_),
71 pressureIndependentVelocity_(true)
74 // check if time entries for soi and eoi match
75 if (mag(massFlowRateProfile_[0][0]-TProfile_[0][0]) > SMALL)
79 "unitInjector::unitInjector(const time& t, const dictionary dict)"
80 )<< "start-times do not match for TemperatureProfile and "
81 << " massFlowRateProfile." << nl << exit (FatalError);
86 mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]
87 - TProfile_[TProfile_.size()-1][0])
93 "unitInjector::unitInjector(const time& t, const dictionary dict)"
94 )<< "end-times do not match for TemperatureProfile and "
95 << "massFlowRateProfile." << nl << exit(FatalError);
98 // convert CA to real time
99 forAll(massFlowRateProfile_, i)
101 massFlowRateProfile_[i][0] =
102 t.userTimeToTime(massFlowRateProfile_[i][0]);
103 velocityProfile_[i][0] = massFlowRateProfile_[i][0];
104 injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
109 TProfile_[i][0] = t.userTimeToTime(TProfile_[i][0]);
112 scalar integratedMFR = integrateTable(massFlowRateProfile_);
114 forAll(massFlowRateProfile_, i)
116 // correct the massFlowRateProfile to match the injected mass
117 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
119 CdProfile_[i][0] = massFlowRateProfile_[i][0];
120 CdProfile_[i][1] = Cd_;
123 // Normalize the direction vector
124 direction_ /= mag(direction_);
126 setTangentialVectors();
128 // check molar fractions
135 if (mag(Xsum - 1.0) > SMALL)
137 WarningIn("unitInjector::unitInjector(const time& t, Istream& is)")
138 << "X does not sum to 1.0, correcting molar fractions."
148 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
150 Foam::unitInjector::~unitInjector()
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
156 void Foam::unitInjector::setTangentialVectors()
158 Random rndGen(label(0));
164 vector testThis = rndGen.vector01();
166 tangent = testThis - (testThis & direction_)*direction_;
170 tangentialInjectionVector1_ = tangent/magV;
171 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
176 Foam::label Foam::unitInjector::nParcelsToInject
182 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
183 label nParcels = label(mInj/averageParcelMass_ + 0.49);
188 const Foam::vector Foam::unitInjector::position(const label n) const
194 Foam::vector Foam::unitInjector::position
199 const scalar angleOfWedge,
200 const vector& axisOfSymmetry,
201 const vector& axisOfWedge,
202 const vector& axisOfWedgeNormal,
208 scalar is = position_ & axisOfSymmetry;
209 scalar magInj = mag(position_ - is*axisOfSymmetry);
212 axisOfWedge*cos(0.5*angleOfWedge)
213 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
214 halfWedge /= mag(halfWedge);
216 return (is*axisOfSymmetry + magInj*halfWedge);
220 // otherwise, disc injection
221 scalar iRadius = d_*rndGen.scalar01();
222 scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
229 tangentialInjectionVector1_*cos(iAngle)
230 + tangentialInjectionVector2_*sin(iAngle)
240 Foam::label Foam::unitInjector::nHoles() const
246 Foam::scalar Foam::unitInjector::d() const
252 const Foam::vector& Foam::unitInjector::direction
262 Foam::scalar Foam::unitInjector::mass
267 const scalar angleOfWedge
270 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
272 // correct mass if calculation is 2D
275 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
282 Foam::scalar Foam::unitInjector::mass() const
288 const Foam::scalarField& Foam::unitInjector::X() const
294 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::T() const
300 Foam::scalar Foam::unitInjector::T(const scalar time) const
302 return getTableValue(TProfile_, time);
306 Foam::scalar Foam::unitInjector::tsoi() const
308 return massFlowRateProfile_[0][0];
312 Foam::scalar Foam::unitInjector::teoi() const
314 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
318 Foam::scalar Foam::unitInjector::massFlowRate(const scalar time) const
320 return getTableValue(massFlowRateProfile_, time);
324 Foam::scalar Foam::unitInjector::injectionPressure(const scalar time) const
326 return getTableValue(injectionPressureProfile_, time);
330 Foam::scalar Foam::unitInjector::velocity(const scalar time) const
332 return getTableValue(velocityProfile_, time);
336 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::CdProfile() const
342 Foam::scalar Foam::unitInjector::Cd(const scalar time) const
348 Foam::scalar Foam::unitInjector::fractionOfInjection(const scalar time) const
350 return integrateTable(massFlowRateProfile_, time)/mass_;
354 Foam::scalar Foam::unitInjector::injectedMass(const scalar t) const
356 return mass_*fractionOfInjection(t);
360 void Foam::unitInjector::correctProfiles
362 const liquidMixture& fuel,
363 const scalar referencePressure
366 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
367 scalar pDummy = 1.0e+5;
369 forAll(velocityProfile_, i)
371 scalar time = velocityProfile_[i][0];
372 scalar rho = fuel.rho(pDummy, T(time), X_);
373 scalar v = massFlowRateProfile_[i][1]/(Cd_*rho*A);
374 velocityProfile_[i][1] = v;
375 injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
380 Foam::vector Foam::unitInjector::tan1(const label) const
382 return tangentialInjectionVector1_;
386 Foam::vector Foam::unitInjector::tan2(const label) const
388 return tangentialInjectionVector2_;
392 // ************************************************************************* //