initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / dieselSpray / injector / commonRailInjector / commonRailInjector.C
blob49b5b4ad3af1f538686da9b6deabfde93144c03e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "commonRailInjector.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "Random.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
36 defineTypeNameAndDebug(commonRailInjector, 0);
38 addToRunTimeSelectionTable
40     injectorType,
41     commonRailInjector,
42     dictionary
45 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
47 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
49 // Construct from components
50 Foam::commonRailInjector::commonRailInjector
52     const Foam::Time& t,
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     mass_(readScalar(propsDict_.lookup("mass"))),
62     injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
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_(propsDict_.lookup("injectionPressureProfile")),
69     CdProfile_(massFlowRateProfile_),
70     TProfile_(massFlowRateProfile_),
71     averageParcelMass_(mass_/nParcels_),
72     pressureIndependentVelocity_(false)
75     // convert CA to real time
76     forAll(massFlowRateProfile_, i)
77     {
78         massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
79         velocityProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
80     }
82     forAll(injectionPressureProfile_, i)
83     {
84         injectionPressureProfile_[i][0] = t.userTimeToTime(injectionPressureProfile_[i][0]);
85     }
87     if (mag(injectionPressureProfile_[0][0]-massFlowRateProfile_[0][0]) > SMALL)
88     {
89         FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
90                 << " start-time entries for injectionPressureProfile and massFlowRateProfile do no match"
91                 << abort(FatalError);
92     }
93     Info << "injectionPressureProfile_.size() = " << injectionPressureProfile_.size()
94         << ", massFlowRateProfile_.size() = " << massFlowRateProfile_.size()
95         << endl;
97     if (mag(injectionPressureProfile_[injectionPressureProfile_.size()-1][0]-massFlowRateProfile_[massFlowRateProfile_.size()-1][0]) > SMALL)
98     {
99         FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
100                 << " end-time entries for injectionPressureProfile and massFlowRateProfile do no match"
101                 << abort(FatalError);
102     }
104     scalar integratedMFR = integrateTable(massFlowRateProfile_);
105     scalar integratedP = integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
107     forAll(massFlowRateProfile_, i)
108     {
109         // correct the massFlowRateProfile to match the injected mass
110         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
112         TProfile_[i][0] = massFlowRateProfile_[i][0];
113         TProfile_[i][1] = T_;
115         CdProfile_[i][0] = massFlowRateProfile_[i][0];
117     }
119     forAll(injectionPressureProfile_, i)
120     {
121         injectionPressureProfile_[i][1] *= injectionPressure_/integratedP;
122     }
123     // Normalize the direction vector
124     direction_ /= mag(direction_);
125     
126     setTangentialVectors();
128     // check molar fractions
129     scalar Xsum = 0.0;
130     forAll(X_, i)
131     {
132         Xsum += X_[i];
133     }
135     if (mag(Xsum - 1.0) > SMALL)
136     {
137         Info << "Warning!!!\n commonRailInjector::commonRailInjector(const time& t, Istream& is)"
138             << "X does not add up to 1.0, correcting molar fractions."
139             << endl;
140         forAll(X_, i)
141         {
142             X_[i] /= Xsum;
143         }
144     }
145     Info << "end constructor. in commonRail" << endl;
149 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
151 Foam::commonRailInjector::~commonRailInjector()
155 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
157 void Foam::commonRailInjector::setTangentialVectors()
159     Random rndGen(label(0));
160     scalar magV = 0.0;
161     vector tangent;
163     while (magV < SMALL)
164     {
165         vector testThis = rndGen.vector01();
167         tangent = testThis - (testThis & direction_)*direction_;
168         magV = mag(tangent);
169     }
171     tangentialInjectionVector1_ = tangent/magV;
172     tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
177 Foam::label Foam::commonRailInjector::nParcelsToInject
179     const scalar time0,
180     const scalar time1
181 ) const
184     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
185     label nParcels = label(mInj/averageParcelMass_ + 0.49);
186     
187     return nParcels;
190 const Foam::vector Foam::commonRailInjector::position(const label n) const
192     return position_;
195 Foam::vector Foam::commonRailInjector::position
197     const label n,
198     const scalar time,
199     const bool twoD,
200     const scalar angleOfWedge,
201     const vector& axisOfSymmetry,
202     const vector& axisOfWedge,
203     const vector& axisOfWedgeNormal,
204     Random& rndGen
205 ) const
207     if (twoD)
208     {
209         scalar is = position_ & axisOfSymmetry;
210         scalar magInj = mag(position_ - is*axisOfSymmetry);
212         vector halfWedge =
213             axisOfWedge*cos(0.5*angleOfWedge)
214           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
215         halfWedge /= mag(halfWedge);
217         return (is*axisOfSymmetry + magInj*halfWedge);
218     }
219     else
220     {
221         // otherwise, disc injection
222         scalar iRadius = d_*rndGen.scalar01();
223         scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
225         return
226         ( 
227             position_
228           + iRadius
229           * (
230               tangentialInjectionVector1_*cos(iAngle)
231             + tangentialInjectionVector2_*sin(iAngle)
232           )
233         );
234         
235     }
237     return position_;
240 Foam::label Foam::commonRailInjector::nHoles() const
242     return 1;
245 Foam::scalar Foam::commonRailInjector::d() const
247     return d_;
250 const Foam::vector& Foam::commonRailInjector::direction
252     const label i,
253     const scalar time
254 ) const
256     return direction_;
259 Foam::scalar Foam::commonRailInjector::mass
261     const scalar time0,
262     const scalar time1,
263     const bool twoD,
264     const scalar angleOfWedge
265 ) const
267     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
269     // correct mass if calculation is 2D 
270     if (twoD)
271     {
272         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
273     }
275     return mInj;
278 Foam::scalar Foam::commonRailInjector::mass() const
280     return mass_;
283 const Foam::scalarField& Foam::commonRailInjector::X() const
285     return X_;
288 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::T() const
290     return TProfile_;
293 Foam::scalar Foam::commonRailInjector::T(const scalar time) const
295     return T_;
298 Foam::scalar Foam::commonRailInjector::tsoi() const
300     return massFlowRateProfile_[0][0];
303 Foam::scalar Foam::commonRailInjector::teoi() const
305     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
308 Foam::scalar Foam::commonRailInjector::massFlowRate
310     const scalar time
311 ) const
313     return getTableValue(massFlowRateProfile_, time);
316 Foam::scalar Foam::commonRailInjector::injectionPressure
318     const scalar time
319 ) const
321     return getTableValue(injectionPressureProfile_, time);
324 Foam::scalar Foam::commonRailInjector::velocity
326     const scalar time
327 ) const
329     return getTableValue(velocityProfile_, time);
332 Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::CdProfile() const
334     return CdProfile_;
337 Foam::scalar Foam::commonRailInjector::Cd
339     const scalar time
340 ) const
342     return getTableValue(CdProfile_, time);
345 Foam::scalar Foam::commonRailInjector::fractionOfInjection(const scalar time) const
347     return integrateTable(massFlowRateProfile_, time)/mass_;
350 Foam::scalar Foam::commonRailInjector::injectedMass
352     const scalar t
353 ) const
355     return mass_*fractionOfInjection(t);
359 void Foam::commonRailInjector::correctProfiles
361     const liquidMixture& fuel,
362     const scalar referencePressure
365     scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
366     scalar pDummy = 1.0e+5;
367     scalar rho = fuel.rho(pDummy, T_, X_);
369     forAll(velocityProfile_, i)
370     {
371         scalar Pinj = getTableValue(injectionPressureProfile_, velocityProfile_[i][0]);
372         scalar Vinj = sqrt(2.0*(Pinj - referencePressure)/rho);
373         scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
374         scalar Cd = mfr/Vinj;
375         velocityProfile_[i][1] = Vinj;
376         CdProfile_[i][1] = Cd;
377     }
380 Foam::vector Foam::commonRailInjector::tan1(const label n) const
382     return tangentialInjectionVector1_;
385 Foam::vector Foam::commonRailInjector::tan2(const label n) const
387     return tangentialInjectionVector2_;
390 // ************************************************************************* //