1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 "unitInjector.H"
28 #include "addToRunTimeSelectionTable.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(unitInjector, 0);
38 addToRunTimeSelectionTable
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 // Construct from components
50 Foam::unitInjector::unitInjector
53 const Foam::dictionary& dict
56 injectorType(t, dict),
57 propsDict_(dict.subDict(typeName + "Props")),
58 position_(propsDict_.lookup("position")),
59 direction_(propsDict_.lookup("direction")),
60 d_(readScalar(propsDict_.lookup("diameter"))),
61 Cd_(readScalar(propsDict_.lookup("Cd"))),
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_(massFlowRateProfile_),
68 injectionPressureProfile_(massFlowRateProfile_),
69 CdProfile_(massFlowRateProfile_),
70 TProfile_(massFlowRateProfile_),
71 averageParcelMass_(mass_/nParcels_),
72 pressureIndependentVelocity_(true)
74 // convert CA to real time
75 forAll(massFlowRateProfile_, i)
77 massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
78 velocityProfile_[i][0] = massFlowRateProfile_[i][0];
79 injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
82 scalar integratedMFR = integrateTable(massFlowRateProfile_);
84 forAll(massFlowRateProfile_, i)
86 // correct the massFlowRateProfile to match the injected mass
87 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
89 TProfile_[i][0] = massFlowRateProfile_[i][0];
92 CdProfile_[i][0] = massFlowRateProfile_[i][0];
93 CdProfile_[i][1] = Cd_;
96 // Normalize the direction vector
97 direction_ /= mag(direction_);
99 setTangentialVectors();
101 // check molar fractions
108 if (mag(Xsum - 1.0) > SMALL)
110 Info << "Warning!!!\n unitInjector::unitInjector(const time& t, Istream& is)"
111 << "X does not add up to 1.0, correcting molar fractions."
121 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 Foam::unitInjector::~unitInjector()
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 void Foam::unitInjector::setTangentialVectors()
131 Random rndGen(label(0));
137 vector testThis = rndGen.vector01();
139 tangent = testThis - (testThis & direction_)*direction_;
143 tangentialInjectionVector1_ = tangent/magV;
144 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
149 Foam::label Foam::unitInjector::nParcelsToInject
156 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
157 label nParcels = label(mInj/averageParcelMass_ + 0.49);
162 const Foam::vector Foam::unitInjector::position() const
167 Foam::vector Foam::unitInjector::position
171 const scalar angleOfWedge,
172 const vector& axisOfSymmetry,
173 const vector& axisOfWedge,
174 const vector& axisOfWedgeNormal,
180 scalar is = position_ & axisOfSymmetry;
181 scalar magInj = mag(position_ - is*axisOfSymmetry);
184 axisOfWedge*cos(0.5*angleOfWedge)
185 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
186 halfWedge /= mag(halfWedge);
188 return (is*axisOfSymmetry + magInj*halfWedge);
192 // otherwise, disc injection
193 scalar iRadius = d_*rndGen.scalar01();
194 scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
201 tangentialInjectionVector1_*cos(iAngle)
202 + tangentialInjectionVector2_*sin(iAngle)
211 Foam::scalar Foam::unitInjector::d() const
216 const Foam::vector& Foam::unitInjector::direction() const
221 Foam::scalar Foam::unitInjector::mass
226 const scalar angleOfWedge
229 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
231 // correct mass if calculation is 2D
234 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
240 Foam::scalar Foam::unitInjector::mass() const
245 const Foam::scalarField& Foam::unitInjector::X() const
250 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::T() const
255 Foam::scalar Foam::unitInjector::T(const scalar time) const
260 Foam::scalar Foam::unitInjector::tsoi() const
262 return massFlowRateProfile_[0][0];
265 Foam::scalar Foam::unitInjector::teoi() const
267 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
270 Foam::scalar Foam::unitInjector::massFlowRate
275 return getTableValue(massFlowRateProfile_, time);
278 Foam::scalar Foam::unitInjector::injectionPressure
283 return getTableValue(injectionPressureProfile_, time);
286 Foam::scalar Foam::unitInjector::velocity
291 return getTableValue(velocityProfile_, time);
294 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::CdProfile() const
299 Foam::scalar Foam::unitInjector::Cd
307 Foam::scalar Foam::unitInjector::fractionOfInjection(const scalar time) const
309 return integrateTable(massFlowRateProfile_, time)/mass_;
312 Foam::scalar Foam::unitInjector::injectedMass
317 return mass_*fractionOfInjection(t);
321 void Foam::unitInjector::correctProfiles
323 const liquidMixture& fuel,
324 const scalar referencePressure
328 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
329 scalar pDummy = 1.0e+5;
331 scalar rho = fuel.rho(pDummy, T_, X_);
333 forAll(velocityProfile_, i)
335 scalar v = massFlowRateProfile_[i][1]/(Cd_*rho*A);
336 velocityProfile_[i][1] = v;
337 injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
341 // ************************************************************************* //