Merge /u/wyldckat/foam-extend32/ branch master into master
[foam-extend-3.2.git] / src / lagrangian / dieselSpray / injector / swirlInjector / swirlInjector.C
blob650a18aaa10f36be5619505f8b7c493ed1c0dbf4
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 "swirlInjector.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "Random.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(swirlInjector, 0);
37     addToRunTimeSelectionTable
38     (
39         injectorType,
40         swirlInjector,
41         dictionary
42     );
46 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
48 Foam::swirlInjector::swirlInjector
50     const Foam::Time& t,
51     const Foam::dictionary& dict
54     injectorType(t, dict),
55     propsDict_(dict.subDict(typeName + "Props")),
56     position_(propsDict_.lookup("position")),
57     direction_(propsDict_.lookup("direction")),
58     d_(readScalar(propsDict_.lookup("diameter"))),
59     mass_(readScalar(propsDict_.lookup("mass"))),
60     injectionPressure_(readScalar(propsDict_.lookup("injectionPressure"))),
61     T_(readScalar(propsDict_.lookup("temperature"))),
62     nParcels_(readLabel(propsDict_.lookup("nParcels"))),
63     X_(propsDict_.lookup("X")),
64     massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
65     injectionPressureProfile_(propsDict_.lookup("injectionPressureProfile")),
66     velocityProfile_(massFlowRateProfile_),
67     CdProfile_(massFlowRateProfile_),
68     TProfile_(massFlowRateProfile_),
69     averageParcelMass_(mass_/nParcels_),
70     pressureIndependentVelocity_(false)
72     // convert CA to real time
73     forAll(massFlowRateProfile_, i)
74     {
75         massFlowRateProfile_[i][0] =
76             t.userTimeToTime(massFlowRateProfile_[i][0]);
77     }
78     forAll(injectionPressureProfile_, i)
79     {
80         injectionPressureProfile_[i][0] =
81             t.userTimeToTime(injectionPressureProfile_[i][0]);
82     }
84     // check if time entries match
85     if (mag(massFlowRateProfile_[0][0]-injectionPressureProfile_[0][0]) > SMALL)
86     {
87         FatalErrorIn
88         (
89             "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
90         )   << "Start-times do not match for "
91                "injectionPressureProfile and massFlowRateProfile."
92             << abort(FatalError);
93     }
95     // check if time entries match
96     if
97     (
98         mag
99         (
100             massFlowRateProfile_[massFlowRateProfile_.size() - 1][0]
101           - injectionPressureProfile_[injectionPressureProfile_.size() - 1][0]
102         ) > SMALL
103     )
104     {
105         FatalErrorIn
106         (
107             "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
108         )   << "End-times do not match for "
109                "injectionPressureProfile and massFlowRateProfile."
110             << abort(FatalError);
111     }
113     scalar integratedMFR = integrateTable(massFlowRateProfile_);
114     scalar integratedPressure =
115         integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
117     forAll(massFlowRateProfile_, i)
118     {
119         // correct the massFlowRateProfile to match the injected mass
120         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
122         velocityProfile_[i][0] = massFlowRateProfile_[i][0];
124         TProfile_[i][0] = massFlowRateProfile_[i][0];
125         TProfile_[i][1] = T_;
127         CdProfile_[i][0] = massFlowRateProfile_[i][0];
129     }
131     forAll(injectionPressureProfile_, i)
132     {
133         // correct the pressureProfile to match the injection pressure
134         injectionPressureProfile_[i][1] *=
135             injectionPressure_/integratedPressure;
136     }
138     // Normalize the direction vector
139     direction_ /= mag(direction_);
141     setTangentialVectors();
143     // check molar fractions
144     scalar Xsum = 0.0;
145     forAll(X_, i)
146     {
147         Xsum += X_[i];
148     }
150     if (mag(Xsum - 1.0) > SMALL)
151     {
152         WarningIn
153         (
154             "swirlInjector::swirlInjector(const time& t, const dictionary dict)"
155         )   << "X does not add up to 1.0, correcting molar fractions." << endl;
157         forAll(X_, i)
158         {
159             X_[i] /= Xsum;
160         }
161     }
165 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
167 Foam::swirlInjector::~swirlInjector()
171 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
173 void Foam::swirlInjector::setTangentialVectors()
175     Random rndGen(label(0));
176     scalar magV = 0.0;
177     vector tangent;
179     while (magV < SMALL)
180     {
181         vector testThis = rndGen.vector01();
183         tangent = testThis - (testThis & direction_)*direction_;
184         magV = mag(tangent);
185     }
187     tangentialInjectionVector1_ = tangent/magV;
188     tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
191 Foam::label Foam::swirlInjector::nParcelsToInject
193     const scalar time0,
194     const scalar time1
195 ) const
198     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
199     label nParcels = label(mInj/averageParcelMass_ + 0.49);
201     return nParcels;
204 const Foam::vector Foam::swirlInjector::position(const label n) const
206     return position_;
209 Foam::vector Foam::swirlInjector::position
211     const label n,
212     const scalar time,
213     const bool twoD,
214     const scalar angleOfWedge,
215     const vector& axisOfSymmetry,
216     const vector& axisOfWedge,
217     const vector& axisOfWedgeNormal,
218     Random& rndGen
219 ) const
221     if (twoD)
222     {
223         scalar is = position_ & axisOfSymmetry;
224         scalar magInj = mag(position_ - is*axisOfSymmetry);
226         vector halfWedge =
227             axisOfWedge*cos(0.5*angleOfWedge)
228           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
229         halfWedge /= mag(halfWedge);
231         return (is*axisOfSymmetry + magInj*halfWedge);
232     }
233     else
234     {
235         // otherwise, disc injection
236         scalar iRadius = d_*rndGen.scalar01();
237         scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
239         return
240         (
241             position_
242           + iRadius
243           * (
244               tangentialInjectionVector1_*cos(iAngle)
245             + tangentialInjectionVector2_*sin(iAngle)
246           )
247         );
249     }
251     return position_;
254 Foam::label Foam::swirlInjector::nHoles() const
256     return 1;
259 Foam::scalar Foam::swirlInjector::d() const
261     return d_;
264 const Foam::vector& Foam::swirlInjector::direction
266     const label i,
267     const scalar time
268 ) const
270     return direction_;
273 Foam::scalar Foam::swirlInjector::mass
275     const scalar time0,
276     const scalar time1,
277     const bool twoD,
278     const scalar angleOfWedge
279 ) const
281     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
283     // correct mass if calculation is 2D
284     if (twoD)
285     {
286         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
287     }
289     return mInj;
292 Foam::scalar Foam::swirlInjector::mass() const
294     return mass_;
297 Foam::List<Foam::swirlInjector::pair>
298 Foam::swirlInjector::massFlowRateProfile() const
300     return massFlowRateProfile_;
303 Foam::scalar Foam::swirlInjector::massFlowRate(const scalar time) const
305     return getTableValue(massFlowRateProfile_, time);
308 Foam::List<Foam::swirlInjector::pair>
309 Foam::swirlInjector::injectionPressureProfile() const
311     return injectionPressureProfile_;
314 Foam::scalar Foam::swirlInjector::injectionPressure(const scalar time) const
316     return getTableValue(injectionPressureProfile_, time);
319 Foam::List<Foam::swirlInjector::pair>
320 Foam::swirlInjector::velocityProfile() const
322     return velocityProfile_;
325 Foam::scalar Foam::swirlInjector::velocity(const scalar time) const
327     return getTableValue(velocityProfile_, time);
330 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::CdProfile() const
332     return CdProfile_;
335 Foam::scalar Foam::swirlInjector::Cd(const scalar time) const
337     return getTableValue(CdProfile_, time);
340 const Foam::scalarField& Foam::swirlInjector::X() const
342     return X_;
345 Foam::List<Foam::swirlInjector::pair> Foam::swirlInjector::T() const
347     return TProfile_;
350 Foam::scalar Foam::swirlInjector::T(const scalar time) const
352     return T_;
355 Foam::scalar Foam::swirlInjector::tsoi() const
357     return massFlowRateProfile_[0][0];
360 Foam::scalar Foam::swirlInjector::teoi() const
362     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
365 Foam::scalar Foam::swirlInjector::fractionOfInjection(const scalar time) const
367     return integrateTable(massFlowRateProfile_, time)/mass_;
370 Foam::scalar Foam::swirlInjector::injectedMass
372     const scalar t
373 ) const
375     return mass_*fractionOfInjection(t);
378 void Foam::swirlInjector::correctProfiles
380     const liquidMixture& fuel,
381     const scalar referencePressure
385     scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
386     scalar pDummy = 1.0e+5;
387     scalar rho = fuel.rho(pDummy, T_, X_);
389     forAll(velocityProfile_, i)
390     {
391         scalar Pinj = getTableValue
392         (
393             injectionPressureProfile_,
394             massFlowRateProfile_[i][0]
395         );
396         scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
397         scalar v = sqrt(2.0*(Pinj - referencePressure)/rho);
398         velocityProfile_[i][1] = v;
399         CdProfile_[i][1] = mfr/v;
400     }
403 Foam::vector Foam::swirlInjector::tan1(const label n) const
405     return tangentialInjectionVector1_;
408 Foam::vector Foam::swirlInjector::tan2(const label n) const
410     return tangentialInjectionVector2_;
414 // ************************************************************************* //