1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 "swirlInjector.H"
28 #include "addToRunTimeSelectionTable.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(swirlInjector, 0);
38 addToRunTimeSelectionTable
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 // Construct from components
51 Foam::swirlInjector::swirlInjector
54 const Foam::dictionary& dict
57 injectorType(t, dict),
58 propsDict_(dict.subDict(typeName + "Props")),
59 position_(propsDict_.lookup("position")),
60 direction_(propsDict_.lookup("direction")),
61 d_(readScalar(propsDict_.lookup("diameter"))),
62 mass_(readScalar(propsDict_.lookup("mass"))),
63 injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
64 T_(readScalar(propsDict_.lookup("temperature"))),
65 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
66 X_(propsDict_.lookup("X")),
67 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
68 injectionPressureProfile_(propsDict_.lookup("injectionPressureProfile")),
69 velocityProfile_(injectionPressureProfile_),
70 CdProfile_(injectionPressureProfile_),
71 TProfile_(injectionPressureProfile_),
72 averageParcelMass_(mass_/nParcels_),
73 pressureIndependentVelocity_(false)
75 // convert CA to real time
76 forAll(massFlowRateProfile_, i)
78 massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
80 forAll(injectionPressureProfile_, i)
82 injectionPressureProfile_[i][0] = t.userTimeToTime(injectionPressureProfile_[i][0]);
85 // check if time entries match
86 if (mag(massFlowRateProfile_[0][0]-injectionPressureProfile_[0][0]) > SMALL)
88 FatalError << "swirlInjector::swirlInjector(const time& t, const dictionary dict) " << endl
89 << " start-times do not match for injectionPressureProfile and massFlowRateProfile."
93 // check if time entries match
94 if (mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]-injectionPressureProfile_[injectionPressureProfile_.size()-1][0]) > SMALL)
96 FatalError << "swirlInjector::swirlInjector(const time& t, const dictionary dict) " << endl
97 << " end-times do not match for injectionPressureProfile and massFlowRateProfile."
101 scalar integratedMFR = integrateTable(massFlowRateProfile_);
102 scalar integratedPressure = integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
104 forAll(massFlowRateProfile_, i)
106 // correct the massFlowRateProfile to match the injected mass
107 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
109 velocityProfile_[i][0] = massFlowRateProfile_[i][0];
111 TProfile_[i][0] = massFlowRateProfile_[i][0];
112 TProfile_[i][1] = T_;
114 CdProfile_[i][0] = massFlowRateProfile_[i][0];
118 forAll(injectionPressureProfile_, i)
120 // correct the pressureProfile to match the injection pressure
121 injectionPressureProfile_[i][1] *= injectionPressure_/integratedPressure;
124 // Normalize the direction vector
125 direction_ /= mag(direction_);
127 setTangentialVectors();
129 // check molar fractions
136 if (mag(Xsum - 1.0) > SMALL)
138 Info << "Warning!!!\n swirlInjector::swirlInjector(const time& t, Istream& is)"
139 << "X does not add up to 1.0, correcting molar fractions."
149 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
151 Foam::swirlInjector::~swirlInjector()
155 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
157 void Foam::swirlInjector::setTangentialVectors()
159 Random rndGen(label(0));
165 vector testThis = rndGen.vector01();
167 tangent = testThis - (testThis & direction_)*direction_;
171 tangentialInjectionVector1_ = tangent/magV;
172 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
177 Foam::label Foam::swirlInjector::nParcelsToInject
184 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
185 label nParcels = label(mInj/averageParcelMass_ + 0.49);
190 const Foam::vector Foam::swirlInjector::position(const label n) const
195 Foam::vector Foam::swirlInjector::position
200 const scalar angleOfWedge,
201 const vector& axisOfSymmetry,
202 const vector& axisOfWedge,
203 const vector& axisOfWedgeNormal,
209 scalar is = position_ & axisOfSymmetry;
210 scalar magInj = mag(position_ - is*axisOfSymmetry);
213 axisOfWedge*cos(0.5*angleOfWedge)
214 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
215 halfWedge /= mag(halfWedge);
217 return (is*axisOfSymmetry + magInj*halfWedge);
221 // otherwise, disc injection
222 scalar iRadius = d_*rndGen.scalar01();
223 scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
230 tangentialInjectionVector1_*cos(iAngle)
231 + tangentialInjectionVector2_*sin(iAngle)
240 Foam::label Foam::swirlInjector::nHoles() const
245 Foam::scalar Foam::swirlInjector::d() const
250 const Foam::vector& Foam::swirlInjector::direction
259 Foam::scalar Foam::swirlInjector::mass
264 const scalar angleOfWedge
267 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
269 // correct mass if calculation is 2D
272 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
278 Foam::scalar Foam::swirlInjector::mass() const
283 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::massFlowRateProfile() const
285 return massFlowRateProfile_;
288 Foam::scalar Foam::swirlInjector::massFlowRate(const scalar time) const
290 return getTableValue(massFlowRateProfile_, time);
293 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::injectionPressureProfile() const
295 return injectionPressureProfile_;
298 Foam::scalar Foam::swirlInjector::injectionPressure(const scalar time) const
300 return getTableValue(injectionPressureProfile_, time);
303 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::velocityProfile() const
305 return velocityProfile_;
308 Foam::scalar Foam::swirlInjector::velocity(const scalar time) const
310 return getTableValue(velocityProfile_, time);
313 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::CdProfile() const
318 Foam::scalar Foam::swirlInjector::Cd(const scalar time) const
320 return getTableValue(CdProfile_, time);
323 const Foam::scalarField& Foam::swirlInjector::X() const
328 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::T() const
333 Foam::scalar Foam::swirlInjector::T(const scalar time) const
338 Foam::scalar Foam::swirlInjector::tsoi() const
340 return massFlowRateProfile_[0][0];
343 Foam::scalar Foam::swirlInjector::teoi() const
345 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
348 Foam::scalar Foam::swirlInjector::fractionOfInjection(const scalar time) const
350 return integrateTable(massFlowRateProfile_, time)/mass_;
354 Foam::scalar Foam::swirlInjector::injectedMass
359 return mass_*fractionOfInjection(t);
362 void Foam::swirlInjector::correctProfiles
364 const liquidMixture& fuel,
365 const scalar referencePressure
369 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
370 scalar pDummy = 1.0e+5;
371 scalar rho = fuel.rho(pDummy, T_, X_);
373 forAll(velocityProfile_, i)
375 scalar Pinj = getTableValue(injectionPressureProfile_, massFlowRateProfile_[i][0]);
376 scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
377 scalar v = sqrt(2.0*(Pinj - referencePressure)/rho);
378 velocityProfile_[i][1] = v;
379 CdProfile_[i][1] = mfr/v;
383 Foam::vector Foam::swirlInjector::tan1(const label n) const
385 return tangentialInjectionVector1_;
388 Foam::vector Foam::swirlInjector::tan2(const label n) const
390 return tangentialInjectionVector2_;
393 // ************************************************************************* //