initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / dieselSpray / injector / definedInjector / definedInjector.C
blobb483a3bdf396ba880026dbdcca59c3e1fc270262
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 "definedInjector.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "Random.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
36 defineTypeNameAndDebug(definedInjector, 0);
38 addToRunTimeSelectionTable
40     injectorType,
41     definedInjector,
42     dictionary
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 // Construct from components
51 Foam::definedInjector::definedInjector
53     const Time& t,
54     const dictionary& dict
57     injectorType(t, dict),
58     propsDict_(dict.subDict(typeName + "Props")),
59     position_(propsDict_.lookup("position")),
60     direction_(propsDict_.lookup("direction")),
61     d_(readScalar(propsDict_.lookup("diameter"))),
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_(propsDict_.lookup("velocityProfile")),
68     injectionPressureProfile_(massFlowRateProfile_),
69     CdProfile_(massFlowRateProfile_),
70     averageParcelMass_(mass_/nParcels_),
71     pressureIndependentVelocity_(true)
73     // convert CA to real time - mass flow rate profile
74     forAll(massFlowRateProfile_, i)
75     {
76         massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
77             // dummy
78             injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
79             injectionPressureProfile_[i][1] = 0.0;
80             CdProfile_[i][0] = massFlowRateProfile_[i][0];
81             CdProfile_[i][1] = 1.0;
82     }
84     forAll(velocityProfile_, i)
85     {
86         velocityProfile_[i][0] = t.userTimeToTime(velocityProfile_[i][0]);
87     }
89     // check if time entries match
90     if (mag(massFlowRateProfile_[0][0]-velocityProfile_[0][0]) > SMALL)
91     {
92         FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
93             << " start-times do not match for velocityProfile and massFlowRateProfile."
94             << abort(FatalError);
95     }
97     if (mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]-velocityProfile_[velocityProfile_.size()-1][0]) > SMALL)
98     {
99         FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
100             << " end-times do not match for velocityProfile and massFlowRateProfile."
101             << abort(FatalError);
102     }
104     // calculate integral of mass flow rate profile
105     scalar integratedMFR = integrateTable(massFlowRateProfile_);
107     // correct the massFlowRate profile to match the injector
108     forAll(massFlowRateProfile_, i)
109     {
110         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
111     }
113     // Normalize the direction vector
114     direction_ /= mag(direction_);
115     
116     setTangentialVectors();
118     // check molar fractions
119     scalar Xsum = 0.0;
120     forAll(X_, i)
121     {
122         Xsum += X_[i];
123     }
125     if (mag(Xsum - 1.0) > SMALL)
126     {
127         WarningIn
128         (
129             "definedInjector::definedInjector(const time& t, Istream& is)"
130         )   << "X does not add up to 1.0, correcting molar fractions."
131             << endl;
133         forAll(X_, i)
134         {
135             X_[i] /= Xsum;
136         }
137     }
141 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
143 Foam::definedInjector::~definedInjector()
147 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
149 void Foam::definedInjector::setTangentialVectors()
151     Random rndGen(label(0));
152     scalar magV = 0.0;
153     vector tangent;
155     while (magV < SMALL)
156     {
157         vector testThis = rndGen.vector01();
159         tangent = testThis - (testThis & direction_)*direction_;
160         magV = mag(tangent);
161     }
163     tangentialInjectionVector1_ = tangent/magV;
164     tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
168 Foam::label Foam::definedInjector::nParcelsToInject
170     const scalar time0,
171     const scalar time1
172 ) const
175     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
176     label nParcels = label(mInj/averageParcelMass_ + 0.49);
177     
178     return nParcels;
181 const Foam::vector Foam::definedInjector::position(const label n) const
183     return position_;
186 Foam::vector Foam::definedInjector::position
188     const label n,
189     const scalar time,
190     const bool twoD,
191     const scalar angleOfWedge,
192     const vector& axisOfSymmetry,
193     const vector& axisOfWedge,
194     const vector& axisOfWedgeNormal,
195     Random& rndGen
196 ) const
198     if (twoD)
199     {
200         scalar is = position_ & axisOfSymmetry;
201         scalar magInj = mag(position_ - is*axisOfSymmetry);
203         vector halfWedge =
204             axisOfWedge*cos(0.5*angleOfWedge)
205           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
206         halfWedge /= mag(halfWedge);
208         return (is*axisOfSymmetry + magInj*halfWedge);
209     }
210     else
211     {
212         // otherwise, disc injection
213         scalar iRadius = d_*rndGen.scalar01();
214         scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
216         return
217         ( 
218             position_
219           + iRadius
220           * (
221               tangentialInjectionVector1_*cos(iAngle)
222             + tangentialInjectionVector2_*sin(iAngle)
223           )
224         );
225         
226     }
228     return position_;
231 Foam::label Foam::definedInjector::nHoles() const
233     return 1;
236 Foam::scalar Foam::definedInjector::d() const
238     return d_;
241 const Foam::vector& Foam::definedInjector::direction
243     const label i,
244     const scalar time
245 ) const
247     return direction_;
250 Foam::scalar Foam::definedInjector::mass
252     const scalar time0,
253     const scalar time1,
254     const bool twoD,
255     const scalar angleOfWedge
256 ) const
258     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
260     // correct mass if calculation is 2D 
261     if (twoD)
262     {
263         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
264     }
266     return mInj;
269 Foam::scalar Foam::definedInjector::mass() const
271     return mass_;
274 Foam::scalar Foam::definedInjector::massFlowRate(const scalar time) const
276     return getTableValue(massFlowRateProfile_, time);
279 Foam::scalar Foam::definedInjector::injectionPressure(const scalar time) const
281     return getTableValue(injectionPressureProfile_, time);
284 Foam::scalar Foam::definedInjector::Cd(const scalar time) const
286     return getTableValue(CdProfile_, time);
289 const Foam::scalarField& Foam::definedInjector::X() const
291     return X_;
294 Foam::List<Foam::definedInjector::pair> Foam::definedInjector::T() const
296     return TProfile_;
299 Foam::scalar Foam::definedInjector::T(const scalar time) const
301     return T_;
304 Foam::scalar Foam::definedInjector::tsoi() const
306     return massFlowRateProfile_[0][0];
309 Foam::scalar Foam::definedInjector::teoi() const
311     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
314 Foam::scalar Foam::definedInjector::fractionOfInjection
316     const scalar time
317 ) const
319     return integrateTable(massFlowRateProfile_, time)/mass_;
322 Foam::scalar Foam::definedInjector::velocity
324     const scalar time
325 ) const
327     return getTableValue(velocityProfile_, time);
330 Foam::scalar Foam::definedInjector::injectedMass
332     const scalar t
333 ) const
335     return mass_*fractionOfInjection(t);
338 void Foam::definedInjector::correctProfiles
340     const liquidMixture& fuel,
341     const scalar referencePressure
344     scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
345     scalar pDummy = 1.0e+5;
346     scalar rho = fuel.rho(pDummy, T_, X_);
348     forAll(velocityProfile_, i)
349     {
350         scalar mfr = massFlowRateProfile_[i][1];
351         scalar v = velocityProfile_[i][1];
352         injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
353         CdProfile_[i][1] = mfr/(v*rho*A);
354     }
357 Foam::vector Foam::definedInjector::tan1(const label n) const
359     return tangentialInjectionVector1_;
362 Foam::vector Foam::definedInjector::tan2(const label n) const
364     return tangentialInjectionVector2_;
367 // ************************************************************************* //