1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "swirlInjector.H"
27 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(swirlInjector, 0);
37 addToRunTimeSelectionTable
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 Foam::swirlInjector::swirlInjector
51 const Foam::dictionary& dict
54 injectorType(t, dict),
55 propsDict_(dict.subDict(typeName + "Props")),
56 position_(propsDict_.lookup("position")),
57 direction_(propsDict_.lookup("direction")),
58 d_(readScalar(propsDict_.lookup("diameter"))),
59 mass_(readScalar(propsDict_.lookup("mass"))),
60 injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
61 T_(readScalar(propsDict_.lookup("temperature"))),
62 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
63 X_(propsDict_.lookup("X")),
64 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
65 injectionPressureProfile_(propsDict_.lookup("injectionPressureProfile")),
66 velocityProfile_(massFlowRateProfile_),
67 CdProfile_(massFlowRateProfile_),
68 TProfile_(massFlowRateProfile_),
69 averageParcelMass_(mass_/nParcels_),
70 pressureIndependentVelocity_(false)
72 // convert CA to real time
73 forAll(massFlowRateProfile_, i)
75 massFlowRateProfile_[i][0] =
76 t.userTimeToTime(massFlowRateProfile_[i][0]);
78 forAll(injectionPressureProfile_, i)
80 injectionPressureProfile_[i][0] =
81 t.userTimeToTime(injectionPressureProfile_[i][0]);
84 // check if time entries match
85 if (mag(massFlowRateProfile_[0][0]-injectionPressureProfile_[0][0]) > SMALL)
89 "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
90 ) << "Start-times do not match for "
91 "injectionPressureProfile and massFlowRateProfile."
95 // check if time entries match
100 massFlowRateProfile_[massFlowRateProfile_.size() - 1][0]
101 - injectionPressureProfile_[injectionPressureProfile_.size() - 1][0]
107 "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
108 ) << "End-times do not match for "
109 "injectionPressureProfile and massFlowRateProfile."
110 << abort(FatalError);
113 scalar integratedMFR = integrateTable(massFlowRateProfile_);
114 scalar integratedPressure =
115 integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
117 forAll(massFlowRateProfile_, i)
119 // correct the massFlowRateProfile to match the injected mass
120 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
122 velocityProfile_[i][0] = massFlowRateProfile_[i][0];
124 TProfile_[i][0] = massFlowRateProfile_[i][0];
125 TProfile_[i][1] = T_;
127 CdProfile_[i][0] = massFlowRateProfile_[i][0];
131 forAll(injectionPressureProfile_, i)
133 // correct the pressureProfile to match the injection pressure
134 injectionPressureProfile_[i][1] *=
135 injectionPressure_/integratedPressure;
138 // Normalize the direction vector
139 direction_ /= mag(direction_);
141 setTangentialVectors();
143 // check molar fractions
150 if (mag(Xsum - 1.0) > SMALL)
154 "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
155 ) << "X does not add up to 1.0, correcting molar fractions." << endl;
165 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
167 Foam::swirlInjector::~swirlInjector()
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173 void Foam::swirlInjector::setTangentialVectors()
175 Random rndGen(label(0));
181 vector testThis = rndGen.vector01();
183 tangent = testThis - (testThis & direction_)*direction_;
187 tangentialInjectionVector1_ = tangent/magV;
188 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
191 Foam::label Foam::swirlInjector::nParcelsToInject
198 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
199 label nParcels = label(mInj/averageParcelMass_ + 0.49);
204 const Foam::vector Foam::swirlInjector::position(const label n) const
209 Foam::vector Foam::swirlInjector::position
214 const scalar angleOfWedge,
215 const vector& axisOfSymmetry,
216 const vector& axisOfWedge,
217 const vector& axisOfWedgeNormal,
223 scalar is = position_ & axisOfSymmetry;
224 scalar magInj = mag(position_ - is*axisOfSymmetry);
227 axisOfWedge*cos(0.5*angleOfWedge)
228 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
229 halfWedge /= mag(halfWedge);
231 return (is*axisOfSymmetry + magInj*halfWedge);
235 // otherwise, disc injection
236 scalar iRadius = d_*rndGen.scalar01();
237 scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
244 tangentialInjectionVector1_*cos(iAngle)
245 + tangentialInjectionVector2_*sin(iAngle)
254 Foam::label Foam::swirlInjector::nHoles() const
259 Foam::scalar Foam::swirlInjector::d() const
264 const Foam::vector& Foam::swirlInjector::direction
273 Foam::scalar Foam::swirlInjector::mass
278 const scalar angleOfWedge
281 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
283 // correct mass if calculation is 2D
286 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
292 Foam::scalar Foam::swirlInjector::mass() const
297 Foam::List<Foam::swirlInjector::pair>
298 Foam::swirlInjector::massFlowRateProfile() const
300 return massFlowRateProfile_;
303 Foam::scalar Foam::swirlInjector::massFlowRate(const scalar time) const
305 return getTableValue(massFlowRateProfile_, time);
308 Foam::List<Foam::swirlInjector::pair>
309 Foam::swirlInjector::injectionPressureProfile() const
311 return injectionPressureProfile_;
314 Foam::scalar Foam::swirlInjector::injectionPressure(const scalar time) const
316 return getTableValue(injectionPressureProfile_, time);
319 Foam::List<Foam::swirlInjector::pair>
320 Foam::swirlInjector::velocityProfile() const
322 return velocityProfile_;
325 Foam::scalar Foam::swirlInjector::velocity(const scalar time) const
327 return getTableValue(velocityProfile_, time);
330 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::CdProfile() const
335 Foam::scalar Foam::swirlInjector::Cd(const scalar time) const
337 return getTableValue(CdProfile_, time);
340 const Foam::scalarField& Foam::swirlInjector::X() const
345 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::T() const
350 Foam::scalar Foam::swirlInjector::T(const scalar time) const
355 Foam::scalar Foam::swirlInjector::tsoi() const
357 return massFlowRateProfile_[0][0];
360 Foam::scalar Foam::swirlInjector::teoi() const
362 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
365 Foam::scalar Foam::swirlInjector::fractionOfInjection(const scalar time) const
367 return integrateTable(massFlowRateProfile_, time)/mass_;
370 Foam::scalar Foam::swirlInjector::injectedMass
375 return mass_*fractionOfInjection(t);
378 void Foam::swirlInjector::correctProfiles
380 const liquidMixture& fuel,
381 const scalar referencePressure
385 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
386 scalar pDummy = 1.0e+5;
387 scalar rho = fuel.rho(pDummy, T_, X_);
389 forAll(velocityProfile_, i)
391 scalar Pinj = getTableValue
393 injectionPressureProfile_,
394 massFlowRateProfile_[i][0]
396 scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
397 scalar v = sqrt(2.0*(Pinj - referencePressure)/rho);
398 velocityProfile_[i][1] = v;
399 CdProfile_[i][1] = mfr/v;
403 Foam::vector Foam::swirlInjector::tan1(const label n) const
405 return tangentialInjectionVector1_;
408 Foam::vector Foam::swirlInjector::tan2(const label n) const
410 return tangentialInjectionVector2_;
414 // ************************************************************************* //