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 / unitInjector / unitInjector.C
blobeef245b77b161ff41fee616a78466dde59e8b328
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 "unitInjector.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "Random.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(unitInjector, 0);
37     addToRunTimeSelectionTable
38     (
39         injectorType,
40         unitInjector,
41         dictionary
42     );
46 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
48 // Construct from components
49 Foam::unitInjector::unitInjector
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     Cd_(readScalar(propsDict_.lookup("Cd"))),
61     mass_(readScalar(propsDict_.lookup("mass"))),
62     nParcels_(readLabel(propsDict_.lookup("nParcels"))),
63     X_(propsDict_.lookup("X")),
64     massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
65     velocityProfile_(massFlowRateProfile_),
66     injectionPressureProfile_(massFlowRateProfile_),
67     CdProfile_(massFlowRateProfile_),
68     TProfile_(propsDict_.lookup("temperatureProfile")),
69     averageParcelMass_(mass_/nParcels_),
70     pressureIndependentVelocity_(true)
73     // check if time entries for soi and eoi match
74     if (mag(massFlowRateProfile_[0][0]-TProfile_[0][0]) > SMALL)
75     {
76         FatalErrorIn
77         (
78             "unitInjector::unitInjector(const time& t, const dictionary dict)"
79         )<< "start-times do not match for TemperatureProfile and "
80          << " massFlowRateProfile." << nl << exit (FatalError);
81     }
83     if
84     (
85         mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]
86       - TProfile_[TProfile_.size()-1][0])
87       > SMALL
88     )
89     {
90         FatalErrorIn
91         (
92             "unitInjector::unitInjector(const time& t, const dictionary dict)"
93         )<< "end-times do not match for TemperatureProfile and "
94          << "massFlowRateProfile." << nl << exit(FatalError);
95     }
97     // convert CA to real time
98     forAll (massFlowRateProfile_, i)
99     {
100         massFlowRateProfile_[i][0] =
101             t.userTimeToTime(massFlowRateProfile_[i][0]);
102         velocityProfile_[i][0] = massFlowRateProfile_[i][0];
103         injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
104     }
106     forAll (TProfile_, i)
107     {
108         TProfile_[i][0] = t.userTimeToTime(TProfile_[i][0]);
109     }
111     scalar integratedMFR = integrateTable(massFlowRateProfile_);
113     forAll (massFlowRateProfile_, i)
114     {
115         // correct the massFlowRateProfile to match the injected mass
116         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
118         CdProfile_[i][0] = massFlowRateProfile_[i][0];
119         CdProfile_[i][1] = Cd_;
120     }
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         WarningIn("unitInjector::unitInjector(const time& t, Istream& is)")
137             << "X does not sum to 1.0, correcting molar fractions."
138             << nl << endl;
139         forAll (X_, i)
140         {
141             X_[i] /= Xsum;
142         }
143     }
147 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
149 Foam::unitInjector::~unitInjector()
153 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
155 void Foam::unitInjector::setTangentialVectors()
157     Random rndGen(label(0));
158     scalar magV = 0.0;
159     vector tangent;
161     while (magV < SMALL)
162     {
163         vector testThis = rndGen.vector01();
165         tangent = testThis - (testThis & direction_)*direction_;
166         magV = mag(tangent);
167     }
169     tangentialInjectionVector1_ = tangent/magV;
170     tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
175 Foam::label Foam::unitInjector::nParcelsToInject
177     const scalar time0,
178     const scalar time1
179 ) const
181     scalar mInj = mass_*
182     (
183         fractionOfInjection(time1)
184       - fractionOfInjection(time0)
185     );
187     label nParcels = label(mInj/averageParcelMass_ + 0.49);
189     return nParcels;
193 const Foam::vector Foam::unitInjector::position(const label n) const
195     return position_;
199 Foam::vector Foam::unitInjector::position
201     const label n,
202     const scalar time,
203     const bool twoD,
204     const scalar angleOfWedge,
205     const vector& axisOfSymmetry,
206     const vector& axisOfWedge,
207     const vector& axisOfWedgeNormal,
208     Random& rndGen
209 ) const
211     if (twoD)
212     {
213         scalar is = position_ & axisOfSymmetry;
214         scalar magInj = mag(position_ - is*axisOfSymmetry);
216         vector halfWedge =
217             axisOfWedge*cos(0.5*angleOfWedge)
218           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
219         halfWedge /= mag(halfWedge);
221         return (is*axisOfSymmetry + magInj*halfWedge);
222     }
223     else
224     {
225         // otherwise, disc injection
226         scalar iRadius = d_*rndGen.scalar01();
227         scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
229         return
230         (
231             position_
232           + iRadius
233           * (
234               tangentialInjectionVector1_*cos(iAngle)
235             + tangentialInjectionVector2_*sin(iAngle)
236           )
237         );
239     }
241     return position_;
245 Foam::label Foam::unitInjector::nHoles() const
247     return 1;
251 Foam::scalar Foam::unitInjector::d() const
253     return d_;
257 const Foam::vector& Foam::unitInjector::direction
259     const label i,
260     const scalar time
261 ) const
263     return direction_;
267 Foam::scalar Foam::unitInjector::mass
269     const scalar time0,
270     const scalar time1,
271     const bool twoD,
272     const scalar angleOfWedge
273 ) const
275     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
277     // correct mass if calculation is 2D
278     if (twoD)
279     {
280         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
281     }
283     return mInj;
287 Foam::scalar Foam::unitInjector::mass() const
289     return mass_;
293 const Foam::scalarField& Foam::unitInjector::X() const
295     return X_;
299 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::T() const
301     return TProfile_;
305 Foam::scalar Foam::unitInjector::T(const scalar time) const
307     return getTableValue(TProfile_, time);
311 Foam::scalar Foam::unitInjector::tsoi() const
313     return massFlowRateProfile_[0][0];
317 Foam::scalar Foam::unitInjector::teoi() const
319     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
323 Foam::scalar Foam::unitInjector::massFlowRate(const scalar time) const
325     return getTableValue(massFlowRateProfile_, time);
329 Foam::scalar Foam::unitInjector::injectionPressure(const scalar time) const
331     return getTableValue(injectionPressureProfile_, time);
335 Foam::scalar Foam::unitInjector::velocity(const scalar time) const
337     return getTableValue(velocityProfile_, time);
341 Foam::List<Foam::unitInjector::pair> Foam::unitInjector::CdProfile() const
343     return CdProfile_;
347 Foam::scalar Foam::unitInjector::Cd(const scalar time) const
349     return Cd_;
353 Foam::scalar Foam::unitInjector::fractionOfInjection(const scalar time) const
355     return integrateTable(massFlowRateProfile_, time)/mass_;
359 Foam::scalar Foam::unitInjector::injectedMass(const scalar t) const
361     return mass_*fractionOfInjection(t);
365 void Foam::unitInjector::correctProfiles
367     const liquidMixture& fuel,
368     const scalar referencePressure
371     scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
372     scalar pDummy = 1.0e+5;
374     forAll (velocityProfile_, i)
375     {
376         scalar time = velocityProfile_[i][0];
377         scalar rho = fuel.rho(pDummy, T(time), X_);
378         scalar v = massFlowRateProfile_[i][1]/(Cd_*rho*A);
379         velocityProfile_[i][1] = v;
380         injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
381     }
385 Foam::vector Foam::unitInjector::tan1(const label) const
387     return tangentialInjectionVector1_;
391 Foam::vector Foam::unitInjector::tan2(const label) const
393     return tangentialInjectionVector2_;
397 // ************************************************************************* //