Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / lagrangian / dieselSpray / injector / commonRailInjector / commonRailInjector.C
blob1f6d583c4582c542d6ac64c1ba525b612f92fa7a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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 "commonRailInjector.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "Random.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
35 defineTypeNameAndDebug(commonRailInjector, 0);
37 addToRunTimeSelectionTable
39     injectorType,
40     commonRailInjector,
41     dictionary
44 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
46 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
48 // Construct from components
49 Foam::commonRailInjector::commonRailInjector
51     const Foam::Time& t,
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     mass_(readScalar(propsDict_.lookup("mass"))),
61     injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
62     T_(readScalar(propsDict_.lookup("temperature"))),
63     nParcels_(readLabel(propsDict_.lookup("nParcels"))),
64     X_(propsDict_.lookup("X")),
65     massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
66     velocityProfile_(massFlowRateProfile_),
67     injectionPressureProfile_(propsDict_.lookup("injectionPressureProfile")),
68     CdProfile_(massFlowRateProfile_),
69     TProfile_(massFlowRateProfile_),
70     averageParcelMass_(mass_/nParcels_),
71     pressureIndependentVelocity_(false)
74     // convert CA to real time
75     forAll(massFlowRateProfile_, i)
76     {
77         massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
78         velocityProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
79     }
81     forAll(injectionPressureProfile_, i)
82     {
83         injectionPressureProfile_[i][0] = t.userTimeToTime(injectionPressureProfile_[i][0]);
84     }
86     if (mag(injectionPressureProfile_[0][0]-massFlowRateProfile_[0][0]) > SMALL)
87     {
88         FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
89                 << " start-time entries for injectionPressureProfile and massFlowRateProfile do no match"
90                 << abort(FatalError);
91     }
92     Info << "injectionPressureProfile_.size() = " << injectionPressureProfile_.size()
93         << ", massFlowRateProfile_.size() = " << massFlowRateProfile_.size()
94         << endl;
96     if (mag(injectionPressureProfile_[injectionPressureProfile_.size()-1][0]-massFlowRateProfile_[massFlowRateProfile_.size()-1][0]) > SMALL)
97     {
98         FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
99                 << " end-time entries for injectionPressureProfile and massFlowRateProfile do no match"
100                 << abort(FatalError);
101     }
103     scalar integratedMFR = integrateTable(massFlowRateProfile_);
104     scalar integratedP = integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
106     forAll(massFlowRateProfile_, i)
107     {
108         // correct the massFlowRateProfile to match the injected mass
109         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
111         TProfile_[i][0] = massFlowRateProfile_[i][0];
112         TProfile_[i][1] = T_;
114         CdProfile_[i][0] = massFlowRateProfile_[i][0];
116     }
118     forAll(injectionPressureProfile_, i)
119     {
120         injectionPressureProfile_[i][1] *= injectionPressure_/integratedP;
121     }
122     // Normalize the direction vector
123     direction_ /= mag(direction_);
125     setTangentialVectors();
127     // check molar fractions
128     scalar Xsum = 0.0;
129     forAll(X_, i)
130     {
131         Xsum += X_[i];
132     }
134     if (mag(Xsum - 1.0) > SMALL)
135     {
136         Info << "Warning!!!\n commonRailInjector::commonRailInjector(const time& t, Istream& is)"
137             << "X does not add up to 1.0, correcting molar fractions."
138             << endl;
139         forAll(X_, i)
140         {
141             X_[i] /= Xsum;
142         }
143     }
144     Info << "end constructor. in commonRail" << endl;
148 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
150 Foam::commonRailInjector::~commonRailInjector()
154 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
156 void Foam::commonRailInjector::setTangentialVectors()
158     Random rndGen(label(0));
159     scalar magV = 0.0;
160     vector tangent;
162     while (magV < SMALL)
163     {
164         vector testThis = rndGen.vector01();
166         tangent = testThis - (testThis & direction_)*direction_;
167         magV = mag(tangent);
168     }
170     tangentialInjectionVector1_ = tangent/magV;
171     tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
176 Foam::label Foam::commonRailInjector::nParcelsToInject
178     const scalar time0,
179     const scalar time1
180 ) const
183     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
184     label nParcels = label(mInj/averageParcelMass_ + 0.49);
186     return nParcels;
189 const Foam::vector Foam::commonRailInjector::position(const label n) const
191     return position_;
194 Foam::vector Foam::commonRailInjector::position
196     const label n,
197     const scalar time,
198     const bool twoD,
199     const scalar angleOfWedge,
200     const vector& axisOfSymmetry,
201     const vector& axisOfWedge,
202     const vector& axisOfWedgeNormal,
203     Random& rndGen
204 ) const
206     if (twoD)
207     {
208         scalar is = position_ & axisOfSymmetry;
209         scalar magInj = mag(position_ - is*axisOfSymmetry);
211         vector halfWedge =
212             axisOfWedge*cos(0.5*angleOfWedge)
213           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
214         halfWedge /= mag(halfWedge);
216         return (is*axisOfSymmetry + magInj*halfWedge);
217     }
218     else
219     {
220         // otherwise, disc injection
221         scalar iRadius = d_*rndGen.scalar01();
222         scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
224         return
225         (
226             position_
227           + iRadius
228           * (
229               tangentialInjectionVector1_*cos(iAngle)
230             + tangentialInjectionVector2_*sin(iAngle)
231           )
232         );
234     }
236     return position_;
239 Foam::label Foam::commonRailInjector::nHoles() const
241     return 1;
244 Foam::scalar Foam::commonRailInjector::d() const
246     return d_;
249 const Foam::vector& Foam::commonRailInjector::direction
251     const label i,
252     const scalar time
253 ) const
255     return direction_;
258 Foam::scalar Foam::commonRailInjector::mass
260     const scalar time0,
261     const scalar time1,
262     const bool twoD,
263     const scalar angleOfWedge
264 ) const
266     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
268     // correct mass if calculation is 2D
269     if (twoD)
270     {
271         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
272     }
274     return mInj;
277 Foam::scalar Foam::commonRailInjector::mass() const
279     return mass_;
282 const Foam::scalarField& Foam::commonRailInjector::X() const
284     return X_;
287 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::T() const
289     return TProfile_;
292 Foam::scalar Foam::commonRailInjector::T(const scalar time) const
294     return T_;
297 Foam::scalar Foam::commonRailInjector::tsoi() const
299     return massFlowRateProfile_[0][0];
302 Foam::scalar Foam::commonRailInjector::teoi() const
304     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
307 Foam::scalar Foam::commonRailInjector::massFlowRate
309     const scalar time
310 ) const
312     return getTableValue(massFlowRateProfile_, time);
315 Foam::scalar Foam::commonRailInjector::injectionPressure
317     const scalar time
318 ) const
320     return getTableValue(injectionPressureProfile_, time);
323 Foam::scalar Foam::commonRailInjector::velocity
325     const scalar time
326 ) const
328     return getTableValue(velocityProfile_, time);
331 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::CdProfile() const
333     return CdProfile_;
336 Foam::scalar Foam::commonRailInjector::Cd
338     const scalar time
339 ) const
341     return getTableValue(CdProfile_, time);
344 Foam::scalar Foam::commonRailInjector::fractionOfInjection(const scalar time) const
346     return integrateTable(massFlowRateProfile_, time)/mass_;
349 Foam::scalar Foam::commonRailInjector::injectedMass
351     const scalar t
352 ) const
354     return mass_*fractionOfInjection(t);
358 void Foam::commonRailInjector::correctProfiles
360     const liquidMixture& fuel,
361     const scalar referencePressure
364     scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
365     scalar pDummy = 1.0e+5;
366     scalar rho = fuel.rho(pDummy, T_, X_);
368     forAll(velocityProfile_, i)
369     {
370         scalar Pinj = getTableValue(injectionPressureProfile_, velocityProfile_[i][0]);
371         scalar Vinj = sqrt(2.0*(Pinj - referencePressure)/rho);
372         scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
373         scalar Cd = mfr/Vinj;
374         velocityProfile_[i][1] = Vinj;
375         CdProfile_[i][1] = Cd;
376     }
379 Foam::vector Foam::commonRailInjector::tan1(const label n) const
381     return tangentialInjectionVector1_;
384 Foam::vector Foam::commonRailInjector::tan2(const label n) const
386     return tangentialInjectionVector2_;
389 // ************************************************************************* //