1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 "definedInjector.H"
28 #include "addToRunTimeSelectionTable.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(definedInjector, 0);
38 addToRunTimeSelectionTable
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 // Construct from components
51 Foam::definedInjector::definedInjector
54 const 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 T_(readScalar(propsDict_.lookup("temperature"))),
64 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
65 X_(propsDict_.lookup("X")),
66 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
67 velocityProfile_(propsDict_.lookup("velocityProfile")),
68 injectionPressureProfile_(massFlowRateProfile_),
69 CdProfile_(massFlowRateProfile_),
70 averageParcelMass_(mass_/nParcels_),
71 pressureIndependentVelocity_(true)
73 // convert CA to real time - mass flow rate profile
74 forAll(massFlowRateProfile_, i)
76 massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
78 injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
79 injectionPressureProfile_[i][1] = 0.0;
80 CdProfile_[i][0] = massFlowRateProfile_[i][0];
81 CdProfile_[i][1] = 1.0;
84 forAll(velocityProfile_, i)
86 velocityProfile_[i][0] = t.userTimeToTime(velocityProfile_[i][0]);
89 // check if time entries match
90 if (mag(massFlowRateProfile_[0][0]-velocityProfile_[0][0]) > SMALL)
92 FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
93 << " start-times do not match for velocityProfile and massFlowRateProfile."
97 if (mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]-velocityProfile_[velocityProfile_.size()-1][0]) > SMALL)
99 FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
100 << " end-times do not match for velocityProfile and massFlowRateProfile."
101 << abort(FatalError);
104 // calculate integral of mass flow rate profile
105 scalar integratedMFR = integrateTable(massFlowRateProfile_);
107 // correct the massFlowRate profile to match the injector
108 forAll(massFlowRateProfile_, i)
110 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
113 // Normalize the direction vector
114 direction_ /= mag(direction_);
116 setTangentialVectors();
118 // check molar fractions
125 if (mag(Xsum - 1.0) > SMALL)
129 "definedInjector::definedInjector(const time& t, Istream& is)"
130 ) << "X does not add up to 1.0, correcting molar fractions."
141 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
143 Foam::definedInjector::~definedInjector()
147 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149 void Foam::definedInjector::setTangentialVectors()
151 Random rndGen(label(0));
157 vector testThis = rndGen.vector01();
159 tangent = testThis - (testThis & direction_)*direction_;
163 tangentialInjectionVector1_ = tangent/magV;
164 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
168 Foam::label Foam::definedInjector::nParcelsToInject
175 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
176 label nParcels = label(mInj/averageParcelMass_ + 0.49);
181 const Foam::vector Foam::definedInjector::position(const label n) const
186 Foam::vector Foam::definedInjector::position
191 const scalar angleOfWedge,
192 const vector& axisOfSymmetry,
193 const vector& axisOfWedge,
194 const vector& axisOfWedgeNormal,
200 scalar is = position_ & axisOfSymmetry;
201 scalar magInj = mag(position_ - is*axisOfSymmetry);
204 axisOfWedge*cos(0.5*angleOfWedge)
205 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
206 halfWedge /= mag(halfWedge);
208 return (is*axisOfSymmetry + magInj*halfWedge);
212 // otherwise, disc injection
213 scalar iRadius = d_*rndGen.scalar01();
214 scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
221 tangentialInjectionVector1_*cos(iAngle)
222 + tangentialInjectionVector2_*sin(iAngle)
231 Foam::label Foam::definedInjector::nHoles() const
236 Foam::scalar Foam::definedInjector::d() const
241 const Foam::vector& Foam::definedInjector::direction
250 Foam::scalar Foam::definedInjector::mass
255 const scalar angleOfWedge
258 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
260 // correct mass if calculation is 2D
263 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
269 Foam::scalar Foam::definedInjector::mass() const
274 Foam::scalar Foam::definedInjector::massFlowRate(const scalar time) const
276 return getTableValue(massFlowRateProfile_, time);
279 Foam::scalar Foam::definedInjector::injectionPressure(const scalar time) const
281 return getTableValue(injectionPressureProfile_, time);
284 Foam::scalar Foam::definedInjector::Cd(const scalar time) const
286 return getTableValue(CdProfile_, time);
289 const Foam::scalarField& Foam::definedInjector::X() const
294 Foam::List<Foam::definedInjector::pair> Foam::definedInjector::T() const
299 Foam::scalar Foam::definedInjector::T(const scalar time) const
304 Foam::scalar Foam::definedInjector::tsoi() const
306 return massFlowRateProfile_[0][0];
309 Foam::scalar Foam::definedInjector::teoi() const
311 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
314 Foam::scalar Foam::definedInjector::fractionOfInjection
319 return integrateTable(massFlowRateProfile_, time)/mass_;
322 Foam::scalar Foam::definedInjector::velocity
327 return getTableValue(velocityProfile_, time);
330 Foam::scalar Foam::definedInjector::injectedMass
335 return mass_*fractionOfInjection(t);
338 void Foam::definedInjector::correctProfiles
340 const liquidMixture& fuel,
341 const scalar referencePressure
344 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
345 scalar pDummy = 1.0e+5;
346 scalar rho = fuel.rho(pDummy, T_, X_);
348 forAll(velocityProfile_, i)
350 scalar mfr = massFlowRateProfile_[i][1];
351 scalar v = velocityProfile_[i][1];
352 injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
353 CdProfile_[i][1] = mfr/(v*rho*A);
357 Foam::vector Foam::definedInjector::tan1(const label n) const
359 return tangentialInjectionVector1_;
362 Foam::vector Foam::definedInjector::tan2(const label n) const
364 return tangentialInjectionVector2_;
367 // ************************************************************************* //