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 "unitInjector.H"
27 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(unitInjector, 0);
37 addToRunTimeSelectionTable
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 // Construct from components
49 Foam::unitInjector::unitInjector
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 Cd_(readScalar(propsDict_.lookup("Cd"))),
61 mass_(readScalar(propsDict_.lookup("mass"))),
62 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
63 X_(propsDict_.lookup("X")),
64 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
65 velocityProfile_(massFlowRateProfile_),
66 injectionPressureProfile_(massFlowRateProfile_),
67 CdProfile_(massFlowRateProfile_),
68 TProfile_(propsDict_.lookup("temperatureProfile")),
69 averageParcelMass_(mass_/nParcels_),
70 pressureIndependentVelocity_(true)
73 // check if time entries for soi and eoi match
74 if (mag(massFlowRateProfile_[0][0]-TProfile_[0][0]) > SMALL)
78 "unitInjector::unitInjector(const time& t, const dictionary dict)"
79 )<< "start-times do not match for TemperatureProfile and "
80 << " massFlowRateProfile." << nl << exit (FatalError);
85 mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]
86 - TProfile_[TProfile_.size()-1][0])
92 "unitInjector::unitInjector(const time& t, const dictionary dict)"
93 )<< "end-times do not match for TemperatureProfile and "
94 << "massFlowRateProfile." << nl << exit(FatalError);
97 // convert CA to real time
98 forAll (massFlowRateProfile_, i)
100 massFlowRateProfile_[i][0] =
101 t.userTimeToTime(massFlowRateProfile_[i][0]);
102 velocityProfile_[i][0] = massFlowRateProfile_[i][0];
103 injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
106 forAll (TProfile_, i)
108 TProfile_[i][0] = t.userTimeToTime(TProfile_[i][0]);
111 scalar integratedMFR = integrateTable(massFlowRateProfile_);
113 forAll (massFlowRateProfile_, i)
115 // correct the massFlowRateProfile to match the injected mass
116 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
118 CdProfile_[i][0] = massFlowRateProfile_[i][0];
119 CdProfile_[i][1] = Cd_;
122 // Normalize the direction vector
123 direction_ /= mag(direction_);
125 setTangentialVectors();
127 // Check molar fractions
134 if (mag(Xsum - 1.0) > SMALL)
136 WarningIn("unitInjector::unitInjector(const time& t, Istream& is)")
137 << "X does not sum to 1.0, correcting molar fractions."
147 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
149 Foam::unitInjector::~unitInjector()
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155 void Foam::unitInjector::setTangentialVectors()
157 Random rndGen(label(0));
163 vector testThis = rndGen.vector01();
165 tangent = testThis - (testThis & direction_)*direction_;
169 tangentialInjectionVector1_ = tangent/magV;
170 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
175 Foam::label Foam::unitInjector::nParcelsToInject
183 fractionOfInjection(time1)
184 - fractionOfInjection(time0)
187 label nParcels = label(mInj/averageParcelMass_ + 0.49);
193 const Foam::vector Foam::unitInjector::position(const label n) const
199 Foam::vector Foam::unitInjector::position
204 const scalar angleOfWedge,
205 const vector& axisOfSymmetry,
206 const vector& axisOfWedge,
207 const vector& axisOfWedgeNormal,
213 scalar is = position_ & axisOfSymmetry;
214 scalar magInj = mag(position_ - is*axisOfSymmetry);
217 axisOfWedge*cos(0.5*angleOfWedge)
218 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
219 halfWedge /= mag(halfWedge);
221 return (is*axisOfSymmetry + magInj*halfWedge);
225 // otherwise, disc injection
226 scalar iRadius = d_*rndGen.scalar01();
227 scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
234 tangentialInjectionVector1_*cos(iAngle)
235 + tangentialInjectionVector2_*sin(iAngle)
245 Foam::label Foam::unitInjector::nHoles() const
251 Foam::scalar Foam::unitInjector::d() const
257 const Foam::vector& Foam::unitInjector::direction
267 Foam::scalar Foam::unitInjector::mass
272 const scalar angleOfWedge
275 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
277 // correct mass if calculation is 2D
280 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
287 Foam::scalar Foam::unitInjector::mass() const
293 const Foam::scalarField& Foam::unitInjector::X() const
299 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::T() const
305 Foam::scalar Foam::unitInjector::T(const scalar time) const
307 return getTableValue(TProfile_, time);
311 Foam::scalar Foam::unitInjector::tsoi() const
313 return massFlowRateProfile_[0][0];
317 Foam::scalar Foam::unitInjector::teoi() const
319 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
323 Foam::scalar Foam::unitInjector::massFlowRate(const scalar time) const
325 return getTableValue(massFlowRateProfile_, time);
329 Foam::scalar Foam::unitInjector::injectionPressure(const scalar time) const
331 return getTableValue(injectionPressureProfile_, time);
335 Foam::scalar Foam::unitInjector::velocity(const scalar time) const
337 return getTableValue(velocityProfile_, time);
341 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::CdProfile() const
347 Foam::scalar Foam::unitInjector::Cd(const scalar time) const
353 Foam::scalar Foam::unitInjector::fractionOfInjection(const scalar time) const
355 return integrateTable(massFlowRateProfile_, time)/mass_;
359 Foam::scalar Foam::unitInjector::injectedMass(const scalar t) const
361 return mass_*fractionOfInjection(t);
365 void Foam::unitInjector::correctProfiles
367 const liquidMixture& fuel,
368 const scalar referencePressure
371 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
372 scalar pDummy = 1.0e+5;
374 forAll (velocityProfile_, i)
376 scalar time = velocityProfile_[i][0];
377 scalar rho = fuel.rho(pDummy, T(time), X_);
378 scalar v = massFlowRateProfile_[i][1]/(Cd_*rho*A);
379 velocityProfile_[i][1] = v;
380 injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
385 Foam::vector Foam::unitInjector::tan1(const label) const
387 return tangentialInjectionVector1_;
391 Foam::vector Foam::unitInjector::tan2(const label) const
393 return tangentialInjectionVector2_;
397 // ************************************************************************* //