BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / lagrangian / dieselSpray / injector / definedInjector / definedInjector.C
blob05cc63881992aaa99dd07c93c1ac2ce2f9237554
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "definedInjector.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 namespace Foam
33     defineTypeNameAndDebug(definedInjector, 0);
35     addToRunTimeSelectionTable
36     (
37         injectorType,
38         definedInjector,
39         dictionary
40     );
44 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
46 Foam::definedInjector::definedInjector
48     const Time& t,
49     const dictionary& dict
52     injectorType(t, dict),
53     propsDict_(dict.subDict(typeName + "Props")),
54     position_(propsDict_.lookup("position")),
55     direction_(propsDict_.lookup("direction")),
56     d_(readScalar(propsDict_.lookup("diameter"))),
57     mass_(readScalar(propsDict_.lookup("mass"))),
58     T_(readScalar(propsDict_.lookup("temperature"))),
59     nParcels_(readLabel(propsDict_.lookup("nParcels"))),
60     X_(propsDict_.lookup("X")),
61     massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
62     velocityProfile_(propsDict_.lookup("velocityProfile")),
63     injectionPressureProfile_(massFlowRateProfile_),
64     CdProfile_(massFlowRateProfile_),
65     averageParcelMass_(mass_/nParcels_),
66     pressureIndependentVelocity_(true)
68     // convert CA to real time - mass flow rate profile
69     forAll(massFlowRateProfile_, i)
70     {
71         massFlowRateProfile_[i][0] =
72             t.userTimeToTime(massFlowRateProfile_[i][0]);
73         // dummy
74         injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
75         injectionPressureProfile_[i][1] = 0.0;
76         CdProfile_[i][0] = massFlowRateProfile_[i][0];
77         CdProfile_[i][1] = 1.0;
78     }
80     forAll(velocityProfile_, i)
81     {
82         velocityProfile_[i][0] = t.userTimeToTime(velocityProfile_[i][0]);
83     }
85     // check if time entries match
86     if (mag(massFlowRateProfile_[0][0]-velocityProfile_[0][0]) > SMALL)
87     {
88         FatalErrorIn
89         (
90             "definedInjector::definedInjector"
91             "(const time& t, const dictionary dict)"
92         )   << "Start-times do not match for velocityProfile and "
93             << "massFlowRateProfile." << nl
94             << abort(FatalError);
95     }
97     if
98     (
99         mag(massFlowRateProfile_.last()[0] - velocityProfile_.last()[0])
100       > SMALL
101     )
102     {
103         FatalErrorIn
104         (
105             "definedInjector::definedInjector"
106             "(const time& t, const dictionary dict)"
107         )   << "End-times do not match for velocityProfile and "
108             << "massFlowRateProfile."
109             << abort(FatalError);
110     }
112     // calculate integral of mass flow rate profile
113     scalar integratedMFR = integrateTable(massFlowRateProfile_);
115     // correct the massFlowRate profile to match the injector
116     forAll(massFlowRateProfile_, i)
117     {
118         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
119     }
121     // Normalize the direction vector
122     direction_ /= mag(direction_);
124     setTangentialVectors();
126     // check molar fractions
127     scalar Xsum = 0.0;
128     forAll(X_, i)
129     {
130         Xsum += X_[i];
131     }
133     if (mag(Xsum - 1.0) > SMALL)
134     {
135         WarningIn
136         (
137             "definedInjector::definedInjector"
138             "(const time& t, const dictionary dict)"
139         )   << "X does not add up to 1.0, correcting molar fractions."
140             << endl;
142         forAll(X_, i)
143         {
144             X_[i] /= Xsum;
145         }
146     }
150 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
152 Foam::definedInjector::~definedInjector()
156 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
158 void Foam::definedInjector::setTangentialVectors()
160     cachedRandom rndGen(label(0), -1);
161     scalar magV = 0.0;
162     vector tangent;
164     while (magV < SMALL)
165     {
166         vector testThis = rndGen.sample01<vector>();
168         tangent = testThis - (testThis & direction_)*direction_;
169         magV = mag(tangent);
170     }
172     tangentialInjectionVector1_ = tangent/magV;
173     tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
177 Foam::label Foam::definedInjector::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);
187     return nParcels;
191 const Foam::vector Foam::definedInjector::position(const label n) const
193     return position_;
197 Foam::vector Foam::definedInjector::position
199     const label n,
200     const scalar time,
201     const bool twoD,
202     const scalar angleOfWedge,
203     const vector& axisOfSymmetry,
204     const vector& axisOfWedge,
205     const vector& axisOfWedgeNormal,
206     cachedRandom& rndGen
207 ) const
209     if (twoD)
210     {
211         scalar is = position_ & axisOfSymmetry;
212         scalar magInj = mag(position_ - is*axisOfSymmetry);
214         vector halfWedge =
215             axisOfWedge*cos(0.5*angleOfWedge)
216           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
217         halfWedge /= mag(halfWedge);
219         return (is*axisOfSymmetry + magInj*halfWedge);
220     }
221     else
222     {
223         // otherwise, disc injection
224         scalar iRadius = d_*rndGen.sample01<scalar>();
225         scalar iAngle = constant::mathematical::twoPi*rndGen.sample01<scalar>();
227         return
228         (
229             position_
230           + iRadius
231           * (
232               tangentialInjectionVector1_*cos(iAngle)
233             + tangentialInjectionVector2_*sin(iAngle)
234           )
235         );
237     }
239     return position_;
243 Foam::label Foam::definedInjector::nHoles() const
245     return 1;
249 Foam::scalar Foam::definedInjector::d() const
251     return d_;
255 const Foam::vector& Foam::definedInjector::direction
257     const label i,
258     const scalar time
259 ) const
261     return direction_;
265 Foam::scalar Foam::definedInjector::mass
267     const scalar time0,
268     const scalar time1,
269     const bool twoD,
270     const scalar angleOfWedge
271 ) const
273     scalar mInj =
274         mass_*(fractionOfInjection(time1) - fractionOfInjection(time0));
276     // correct mass if calculation is 2D
277     if (twoD)
278     {
279         mInj *= 0.5*angleOfWedge/constant::mathematical::pi;
280     }
282     return mInj;
286 Foam::scalar Foam::definedInjector::mass() const
288     return mass_;
292 Foam::scalar Foam::definedInjector::massFlowRate(const scalar time) const
294     return getTableValue(massFlowRateProfile_, time);
298 Foam::scalar Foam::definedInjector::injectionPressure(const scalar time) const
300     return getTableValue(injectionPressureProfile_, time);
304 Foam::scalar Foam::definedInjector::Cd(const scalar time) const
306     return getTableValue(CdProfile_, time);
310 const Foam::scalarField& Foam::definedInjector::X() const
312     return X_;
316 Foam::List<Foam::definedInjector::pair> Foam::definedInjector::T() const
318     return TProfile_;
322 Foam::scalar Foam::definedInjector::T(const scalar time) const
324     return T_;
328 Foam::scalar Foam::definedInjector::tsoi() const
330     return massFlowRateProfile_.first()[0];
334 Foam::scalar Foam::definedInjector::teoi() const
336     return massFlowRateProfile_.last()[0];
340 Foam::scalar Foam::definedInjector::fractionOfInjection
342     const scalar time
343 ) const
345     return integrateTable(massFlowRateProfile_, time)/mass_;
349 Foam::scalar Foam::definedInjector::velocity
351     const scalar time
352 ) const
354     return getTableValue(velocityProfile_, time);
358 Foam::scalar Foam::definedInjector::injectedMass
360     const scalar t
361 ) const
363     return mass_*fractionOfInjection(t);
367 void Foam::definedInjector::correctProfiles
369     const liquidMixtureProperties& fuel,
370     const scalar referencePressure
373     scalar A = 0.25*constant::mathematical::pi*sqr(d_);
374     scalar pDummy = 1.0e+5;
375     scalar rho = fuel.rho(pDummy, T_, X_);
377     forAll(velocityProfile_, i)
378     {
379         scalar mfr = massFlowRateProfile_[i][1];
380         scalar v = velocityProfile_[i][1];
381         injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
382         CdProfile_[i][1] = mfr/(v*rho*A);
383     }
387 Foam::vector Foam::definedInjector::tan1(const label n) const
389     return tangentialInjectionVector1_;
393 Foam::vector Foam::definedInjector::tan2(const label n) const
395     return tangentialInjectionVector2_;
399 // ************************************************************************* //