1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "definedInjector.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(definedInjector, 0);
35 addToRunTimeSelectionTable
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 Foam::definedInjector::definedInjector
49 const dictionary& dict
52 injectorType(t, dict),
53 propsDict_(dict.subDict(typeName + "Props")),
54 position_(propsDict_.lookup("position")),
55 direction_(propsDict_.lookup("direction")),
56 d_(readScalar(propsDict_.lookup("diameter"))),
57 mass_(readScalar(propsDict_.lookup("mass"))),
58 T_(readScalar(propsDict_.lookup("temperature"))),
59 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
60 X_(propsDict_.lookup("X")),
61 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
62 velocityProfile_(propsDict_.lookup("velocityProfile")),
63 injectionPressureProfile_(massFlowRateProfile_),
64 CdProfile_(massFlowRateProfile_),
65 averageParcelMass_(mass_/nParcels_),
66 pressureIndependentVelocity_(true)
68 // convert CA to real time - mass flow rate profile
69 forAll(massFlowRateProfile_, i)
71 massFlowRateProfile_[i][0] =
72 t.userTimeToTime(massFlowRateProfile_[i][0]);
74 injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
75 injectionPressureProfile_[i][1] = 0.0;
76 CdProfile_[i][0] = massFlowRateProfile_[i][0];
77 CdProfile_[i][1] = 1.0;
80 forAll(velocityProfile_, i)
82 velocityProfile_[i][0] = t.userTimeToTime(velocityProfile_[i][0]);
85 // check if time entries match
86 if (mag(massFlowRateProfile_[0][0]-velocityProfile_[0][0]) > SMALL)
90 "definedInjector::definedInjector"
91 "(const time& t, const dictionary dict)"
92 ) << "Start-times do not match for velocityProfile and "
93 << "massFlowRateProfile." << nl
99 mag(massFlowRateProfile_.last()[0] - velocityProfile_.last()[0])
105 "definedInjector::definedInjector"
106 "(const time& t, const dictionary dict)"
107 ) << "End-times do not match for velocityProfile and "
108 << "massFlowRateProfile."
109 << abort(FatalError);
112 // calculate integral of mass flow rate profile
113 scalar integratedMFR = integrateTable(massFlowRateProfile_);
115 // correct the massFlowRate profile to match the injector
116 forAll(massFlowRateProfile_, i)
118 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
121 // Normalize the direction vector
122 direction_ /= mag(direction_);
124 setTangentialVectors();
126 // check molar fractions
133 if (mag(Xsum - 1.0) > SMALL)
137 "definedInjector::definedInjector"
138 "(const time& t, const dictionary dict)"
139 ) << "X does not add up to 1.0, correcting molar fractions."
150 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
152 Foam::definedInjector::~definedInjector()
156 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
158 void Foam::definedInjector::setTangentialVectors()
160 cachedRandom rndGen(label(0), -1);
166 vector testThis = rndGen.sample01<vector>();
168 tangent = testThis - (testThis & direction_)*direction_;
172 tangentialInjectionVector1_ = tangent/magV;
173 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
177 Foam::label Foam::definedInjector::nParcelsToInject
184 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
185 label nParcels = label(mInj/averageParcelMass_ + 0.49);
191 const Foam::vector Foam::definedInjector::position(const label n) const
197 Foam::vector Foam::definedInjector::position
202 const scalar angleOfWedge,
203 const vector& axisOfSymmetry,
204 const vector& axisOfWedge,
205 const vector& axisOfWedgeNormal,
211 scalar is = position_ & axisOfSymmetry;
212 scalar magInj = mag(position_ - is*axisOfSymmetry);
215 axisOfWedge*cos(0.5*angleOfWedge)
216 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
217 halfWedge /= mag(halfWedge);
219 return (is*axisOfSymmetry + magInj*halfWedge);
223 // otherwise, disc injection
224 scalar iRadius = d_*rndGen.sample01<scalar>();
225 scalar iAngle = constant::mathematical::twoPi*rndGen.sample01<scalar>();
232 tangentialInjectionVector1_*cos(iAngle)
233 + tangentialInjectionVector2_*sin(iAngle)
243 Foam::label Foam::definedInjector::nHoles() const
249 Foam::scalar Foam::definedInjector::d() const
255 const Foam::vector& Foam::definedInjector::direction
265 Foam::scalar Foam::definedInjector::mass
270 const scalar angleOfWedge
274 mass_*(fractionOfInjection(time1) - fractionOfInjection(time0));
276 // correct mass if calculation is 2D
279 mInj *= 0.5*angleOfWedge/constant::mathematical::pi;
286 Foam::scalar Foam::definedInjector::mass() const
292 Foam::scalar Foam::definedInjector::massFlowRate(const scalar time) const
294 return getTableValue(massFlowRateProfile_, time);
298 Foam::scalar Foam::definedInjector::injectionPressure(const scalar time) const
300 return getTableValue(injectionPressureProfile_, time);
304 Foam::scalar Foam::definedInjector::Cd(const scalar time) const
306 return getTableValue(CdProfile_, time);
310 const Foam::scalarField& Foam::definedInjector::X() const
316 Foam::List<Foam::definedInjector::pair> Foam::definedInjector::T() const
322 Foam::scalar Foam::definedInjector::T(const scalar time) const
328 Foam::scalar Foam::definedInjector::tsoi() const
330 return massFlowRateProfile_.first()[0];
334 Foam::scalar Foam::definedInjector::teoi() const
336 return massFlowRateProfile_.last()[0];
340 Foam::scalar Foam::definedInjector::fractionOfInjection
345 return integrateTable(massFlowRateProfile_, time)/mass_;
349 Foam::scalar Foam::definedInjector::velocity
354 return getTableValue(velocityProfile_, time);
358 Foam::scalar Foam::definedInjector::injectedMass
363 return mass_*fractionOfInjection(t);
367 void Foam::definedInjector::correctProfiles
369 const liquidMixtureProperties& fuel,
370 const scalar referencePressure
373 scalar A = 0.25*constant::mathematical::pi*sqr(d_);
374 scalar pDummy = 1.0e+5;
375 scalar rho = fuel.rho(pDummy, T_, X_);
377 forAll(velocityProfile_, i)
379 scalar mfr = massFlowRateProfile_[i][1];
380 scalar v = velocityProfile_[i][1];
381 injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
382 CdProfile_[i][1] = mfr/(v*rho*A);
387 Foam::vector Foam::definedInjector::tan1(const label n) const
389 return tangentialInjectionVector1_;
393 Foam::vector Foam::definedInjector::tan2(const label n) const
395 return tangentialInjectionVector2_;
399 // ************************************************************************* //