initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / dieselSpray / injector / unitInjector / unitInjector.C
blob6b1b07dc7a349c1123d120c26b38b7d01ec37b9d
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 "unitInjector.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "Random.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(unitInjector, 0);
38     addToRunTimeSelectionTable
39     (
40         injectorType,
41         unitInjector,
42         dictionary
43     );
47 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
49 // Construct from components
50 Foam::unitInjector::unitInjector
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     Cd_(readScalar(propsDict_.lookup("Cd"))),
62     mass_(readScalar(propsDict_.lookup("mass"))),
63     nParcels_(readLabel(propsDict_.lookup("nParcels"))),
64     X_(propsDict_.lookup("X")),
65     massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
66     velocityProfile_(massFlowRateProfile_),
67     injectionPressureProfile_(massFlowRateProfile_),
68     CdProfile_(massFlowRateProfile_),
69     TProfile_(propsDict_.lookup("temperatureProfile")),
70     averageParcelMass_(mass_/nParcels_),
71     pressureIndependentVelocity_(true)
74     // check if time entries for soi and eoi match
75     if (mag(massFlowRateProfile_[0][0]-TProfile_[0][0]) > SMALL)
76     {
77         FatalErrorIn
78         (
79             "unitInjector::unitInjector(const time& t, const dictionary dict)"
80         )<< "start-times do not match for TemperatureProfile and "
81          << " massFlowRateProfile." << nl << exit (FatalError);
82     }
84     if
85     (
86         mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]
87       - TProfile_[TProfile_.size()-1][0])
88       > SMALL
89     )
90     {
91         FatalErrorIn
92         (
93             "unitInjector::unitInjector(const time& t, const dictionary dict)"
94         )<< "end-times do not match for TemperatureProfile and "
95          << "massFlowRateProfile." << nl << exit(FatalError);
96     }
98     // convert CA to real time
99     forAll(massFlowRateProfile_, i)
100     {
101         massFlowRateProfile_[i][0] =
102             t.userTimeToTime(massFlowRateProfile_[i][0]);
103         velocityProfile_[i][0] = massFlowRateProfile_[i][0];
104         injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
105     }
107     forAll(TProfile_, i)
108     {
109         TProfile_[i][0] = t.userTimeToTime(TProfile_[i][0]);
110     }
112     scalar integratedMFR = integrateTable(massFlowRateProfile_);
114     forAll(massFlowRateProfile_, i)
115     {
116         // correct the massFlowRateProfile to match the injected mass
117         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
119         CdProfile_[i][0] = massFlowRateProfile_[i][0];
120         CdProfile_[i][1] = Cd_;
121     }
123     // Normalize the direction vector
124     direction_ /= mag(direction_);
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         WarningIn("unitInjector::unitInjector(const time& t, Istream& is)")
138             << "X does not sum to 1.0, correcting molar fractions."
139             << nl << endl;
140         forAll(X_, i)
141         {
142             X_[i] /= Xsum;
143         }
144     }
148 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
150 Foam::unitInjector::~unitInjector()
154 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
156 void Foam::unitInjector::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::unitInjector::nParcelsToInject
178     const scalar time0,
179     const scalar time1
180 ) const
182     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
183     label nParcels = label(mInj/averageParcelMass_ + 0.49);
184     return nParcels;
188 const Foam::vector Foam::unitInjector::position(const label n) const
190     return position_;
194 Foam::vector Foam::unitInjector::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_;
240 Foam::label Foam::unitInjector::nHoles() const
242     return 1;
246 Foam::scalar Foam::unitInjector::d() const
248     return d_;
252 const Foam::vector& Foam::unitInjector::direction
254     const label i,
255     const scalar time
256 ) const
258     return direction_;
262 Foam::scalar Foam::unitInjector::mass
264     const scalar time0,
265     const scalar time1,
266     const bool twoD,
267     const scalar angleOfWedge
268 ) const
270     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
272     // correct mass if calculation is 2D
273     if (twoD)
274     {
275         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
276     }
278     return mInj;
282 Foam::scalar Foam::unitInjector::mass() const
284     return mass_;
288 const Foam::scalarField& Foam::unitInjector::X() const
290     return X_;
294 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::T() const
296     return TProfile_;
300 Foam::scalar Foam::unitInjector::T(const scalar time) const
302     return getTableValue(TProfile_, time);
306 Foam::scalar Foam::unitInjector::tsoi() const
308     return massFlowRateProfile_[0][0];
312 Foam::scalar Foam::unitInjector::teoi() const
314     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
318 Foam::scalar Foam::unitInjector::massFlowRate(const scalar time) const
320     return getTableValue(massFlowRateProfile_, time);
324 Foam::scalar Foam::unitInjector::injectionPressure(const scalar time) const
326     return getTableValue(injectionPressureProfile_, time);
330 Foam::scalar Foam::unitInjector::velocity(const scalar time) const
332     return getTableValue(velocityProfile_, time);
336 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::CdProfile() const
338     return CdProfile_;
342 Foam::scalar Foam::unitInjector::Cd(const scalar time) const
344     return Cd_;
348 Foam::scalar Foam::unitInjector::fractionOfInjection(const scalar time) const
350     return integrateTable(massFlowRateProfile_, time)/mass_;
354 Foam::scalar Foam::unitInjector::injectedMass(const scalar t) const
356     return mass_*fractionOfInjection(t);
360 void Foam::unitInjector::correctProfiles
362     const liquidMixture& fuel,
363     const scalar referencePressure
366     scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
367     scalar pDummy = 1.0e+5;
369     forAll(velocityProfile_, i)
370     {
371         scalar time = velocityProfile_[i][0];
372         scalar rho = fuel.rho(pDummy, T(time), X_);
373         scalar v = massFlowRateProfile_[i][1]/(Cd_*rho*A);
374         velocityProfile_[i][1] = v;
375         injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
376     }
380 Foam::vector Foam::unitInjector::tan1(const label) const
382     return tangentialInjectionVector1_;
386 Foam::vector Foam::unitInjector::tan2(const label) const
388     return tangentialInjectionVector2_;
392 // ************************************************************************* //