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 "commonRailInjector.H"
27 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(commonRailInjector, 0);
37 addToRunTimeSelectionTable
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 // Construct from components
49 Foam::commonRailInjector::commonRailInjector
52 const Foam::dictionary& dict
55 injectorType(t, dict),
56 propsDict_(dict.subDict(typeName + "Props")),
57 position_(propsDict_.lookup("position")),
58 direction_(propsDict_.lookup("direction")),
59 d_(readScalar(propsDict_.lookup("diameter"))),
60 mass_(readScalar(propsDict_.lookup("mass"))),
61 injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
62 T_(readScalar(propsDict_.lookup("temperature"))),
63 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
64 X_(propsDict_.lookup("X")),
65 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
66 velocityProfile_(massFlowRateProfile_),
67 injectionPressureProfile_(propsDict_.lookup("injectionPressureProfile")),
68 CdProfile_(massFlowRateProfile_),
69 TProfile_(massFlowRateProfile_),
70 averageParcelMass_(mass_/nParcels_),
71 pressureIndependentVelocity_(false)
74 // convert CA to real time
75 forAll(massFlowRateProfile_, i)
77 massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
78 velocityProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
81 forAll(injectionPressureProfile_, i)
83 injectionPressureProfile_[i][0] = t.userTimeToTime(injectionPressureProfile_[i][0]);
86 if (mag(injectionPressureProfile_[0][0]-massFlowRateProfile_[0][0]) > SMALL)
88 FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
89 << " start-time entries for injectionPressureProfile and massFlowRateProfile do no match"
92 Info << "injectionPressureProfile_.size() = " << injectionPressureProfile_.size()
93 << ", massFlowRateProfile_.size() = " << massFlowRateProfile_.size()
96 if (mag(injectionPressureProfile_[injectionPressureProfile_.size()-1][0]-massFlowRateProfile_[massFlowRateProfile_.size()-1][0]) > SMALL)
98 FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
99 << " end-time entries for injectionPressureProfile and massFlowRateProfile do no match"
100 << abort(FatalError);
103 scalar integratedMFR = integrateTable(massFlowRateProfile_);
104 scalar integratedP = integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
106 forAll(massFlowRateProfile_, i)
108 // correct the massFlowRateProfile to match the injected mass
109 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
111 TProfile_[i][0] = massFlowRateProfile_[i][0];
112 TProfile_[i][1] = T_;
114 CdProfile_[i][0] = massFlowRateProfile_[i][0];
118 forAll(injectionPressureProfile_, i)
120 injectionPressureProfile_[i][1] *= injectionPressure_/integratedP;
122 // Normalize the direction vector
123 direction_ /= mag(direction_);
125 setTangentialVectors();
127 // check molar fractions
134 if (mag(Xsum - 1.0) > SMALL)
136 Info << "Warning!!!\n commonRailInjector::commonRailInjector(const time& t, Istream& is)"
137 << "X does not add up to 1.0, correcting molar fractions."
144 Info << "end constructor. in commonRail" << endl;
148 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
150 Foam::commonRailInjector::~commonRailInjector()
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
156 void Foam::commonRailInjector::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::commonRailInjector::nParcelsToInject
183 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
184 label nParcels = label(mInj/averageParcelMass_ + 0.49);
189 const Foam::vector Foam::commonRailInjector::position(const label n) const
194 Foam::vector Foam::commonRailInjector::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)
239 Foam::label Foam::commonRailInjector::nHoles() const
244 Foam::scalar Foam::commonRailInjector::d() const
249 const Foam::vector& Foam::commonRailInjector::direction
258 Foam::scalar Foam::commonRailInjector::mass
263 const scalar angleOfWedge
266 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
268 // correct mass if calculation is 2D
271 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
277 Foam::scalar Foam::commonRailInjector::mass() const
282 const Foam::scalarField& Foam::commonRailInjector::X() const
287 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::T() const
292 Foam::scalar Foam::commonRailInjector::T(const scalar time) const
297 Foam::scalar Foam::commonRailInjector::tsoi() const
299 return massFlowRateProfile_[0][0];
302 Foam::scalar Foam::commonRailInjector::teoi() const
304 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
307 Foam::scalar Foam::commonRailInjector::massFlowRate
312 return getTableValue(massFlowRateProfile_, time);
315 Foam::scalar Foam::commonRailInjector::injectionPressure
320 return getTableValue(injectionPressureProfile_, time);
323 Foam::scalar Foam::commonRailInjector::velocity
328 return getTableValue(velocityProfile_, time);
331 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::CdProfile() const
336 Foam::scalar Foam::commonRailInjector::Cd
341 return getTableValue(CdProfile_, time);
344 Foam::scalar Foam::commonRailInjector::fractionOfInjection(const scalar time) const
346 return integrateTable(massFlowRateProfile_, time)/mass_;
349 Foam::scalar Foam::commonRailInjector::injectedMass
354 return mass_*fractionOfInjection(t);
358 void Foam::commonRailInjector::correctProfiles
360 const liquidMixture& fuel,
361 const scalar referencePressure
364 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
365 scalar pDummy = 1.0e+5;
366 scalar rho = fuel.rho(pDummy, T_, X_);
368 forAll(velocityProfile_, i)
370 scalar Pinj = getTableValue(injectionPressureProfile_, velocityProfile_[i][0]);
371 scalar Vinj = sqrt(2.0*(Pinj - referencePressure)/rho);
372 scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
373 scalar Cd = mfr/Vinj;
374 velocityProfile_[i][1] = Vinj;
375 CdProfile_[i][1] = Cd;
379 Foam::vector Foam::commonRailInjector::tan1(const label n) const
381 return tangentialInjectionVector1_;
384 Foam::vector Foam::commonRailInjector::tan2(const label n) const
386 return tangentialInjectionVector2_;
389 // ************************************************************************* //