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 "definedInjector.H"
27 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(definedInjector, 0);
37 addToRunTimeSelectionTable
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 // Construct from components
50 Foam::definedInjector::definedInjector
53 const 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 mass_(readScalar(propsDict_.lookup("mass"))),
62 T_(readScalar(propsDict_.lookup("temperature"))),
63 nParcels_(readLabel(propsDict_.lookup("nParcels"))),
64 X_(propsDict_.lookup("X")),
65 massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
66 velocityProfile_(propsDict_.lookup("velocityProfile")),
67 injectionPressureProfile_(massFlowRateProfile_),
68 CdProfile_(massFlowRateProfile_),
69 averageParcelMass_(mass_/nParcels_),
70 pressureIndependentVelocity_(true)
72 // convert CA to real time - mass flow rate profile
73 forAll(massFlowRateProfile_, i)
75 massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
77 injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
78 injectionPressureProfile_[i][1] = 0.0;
79 CdProfile_[i][0] = massFlowRateProfile_[i][0];
80 CdProfile_[i][1] = 1.0;
83 forAll(velocityProfile_, i)
85 velocityProfile_[i][0] = t.userTimeToTime(velocityProfile_[i][0]);
88 // check if time entries match
89 if (mag(massFlowRateProfile_[0][0]-velocityProfile_[0][0]) > SMALL)
91 FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
92 << " start-times do not match for velocityProfile and massFlowRateProfile."
96 if (mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]-velocityProfile_[velocityProfile_.size()-1][0]) > SMALL)
98 FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
99 << " end-times do not match for velocityProfile and massFlowRateProfile."
100 << abort(FatalError);
103 // calculate integral of mass flow rate profile
104 scalar integratedMFR = integrateTable(massFlowRateProfile_);
106 // correct the massFlowRate profile to match the injector
107 forAll(massFlowRateProfile_, i)
109 massFlowRateProfile_[i][1] *= mass_/integratedMFR;
112 // Normalize the direction vector
113 direction_ /= mag(direction_);
115 setTangentialVectors();
117 // check molar fractions
124 if (mag(Xsum - 1.0) > SMALL)
128 "definedInjector::definedInjector(const time& t, Istream& is)"
129 ) << "X does not add up to 1.0, correcting molar fractions."
140 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
142 Foam::definedInjector::~definedInjector()
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
148 void Foam::definedInjector::setTangentialVectors()
150 Random rndGen(label(0));
156 vector testThis = rndGen.vector01();
158 tangent = testThis - (testThis & direction_)*direction_;
162 tangentialInjectionVector1_ = tangent/magV;
163 tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
167 Foam::label Foam::definedInjector::nParcelsToInject
174 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
175 label nParcels = label(mInj/averageParcelMass_ + 0.49);
180 const Foam::vector Foam::definedInjector::position(const label n) const
185 Foam::vector Foam::definedInjector::position
190 const scalar angleOfWedge,
191 const vector& axisOfSymmetry,
192 const vector& axisOfWedge,
193 const vector& axisOfWedgeNormal,
199 scalar is = position_ & axisOfSymmetry;
200 scalar magInj = mag(position_ - is*axisOfSymmetry);
203 axisOfWedge*cos(0.5*angleOfWedge)
204 + axisOfWedgeNormal*sin(0.5*angleOfWedge);
205 halfWedge /= mag(halfWedge);
207 return (is*axisOfSymmetry + magInj*halfWedge);
211 // otherwise, disc injection
212 scalar iRadius = d_*rndGen.scalar01();
213 scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
220 tangentialInjectionVector1_*cos(iAngle)
221 + tangentialInjectionVector2_*sin(iAngle)
230 Foam::label Foam::definedInjector::nHoles() const
235 Foam::scalar Foam::definedInjector::d() const
240 const Foam::vector& Foam::definedInjector::direction
249 Foam::scalar Foam::definedInjector::mass
254 const scalar angleOfWedge
257 scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
259 // correct mass if calculation is 2D
262 mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
268 Foam::scalar Foam::definedInjector::mass() const
273 Foam::scalar Foam::definedInjector::massFlowRate(const scalar time) const
275 return getTableValue(massFlowRateProfile_, time);
278 Foam::scalar Foam::definedInjector::injectionPressure(const scalar time) const
280 return getTableValue(injectionPressureProfile_, time);
283 Foam::scalar Foam::definedInjector::Cd(const scalar time) const
285 return getTableValue(CdProfile_, time);
288 const Foam::scalarField& Foam::definedInjector::X() const
293 Foam::List<Foam::definedInjector::pair> Foam::definedInjector::T() const
298 Foam::scalar Foam::definedInjector::T(const scalar time) const
303 Foam::scalar Foam::definedInjector::tsoi() const
305 return massFlowRateProfile_[0][0];
308 Foam::scalar Foam::definedInjector::teoi() const
310 return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
313 Foam::scalar Foam::definedInjector::fractionOfInjection
318 return integrateTable(massFlowRateProfile_, time)/mass_;
321 Foam::scalar Foam::definedInjector::velocity
326 return getTableValue(velocityProfile_, time);
329 Foam::scalar Foam::definedInjector::injectedMass
334 return mass_*fractionOfInjection(t);
337 void Foam::definedInjector::correctProfiles
339 const liquidMixture& fuel,
340 const scalar referencePressure
343 scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
344 scalar pDummy = 1.0e+5;
345 scalar rho = fuel.rho(pDummy, T_, X_);
347 forAll(velocityProfile_, i)
349 scalar mfr = massFlowRateProfile_[i][1];
350 scalar v = velocityProfile_[i][1];
351 injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
352 CdProfile_[i][1] = mfr/(v*rho*A);
356 Foam::vector Foam::definedInjector::tan1(const label n) const
358 return tangentialInjectionVector1_;
361 Foam::vector Foam::definedInjector::tan2(const label n) const
363 return tangentialInjectionVector2_;
366 // ************************************************************************* //