Merge /u/wyldckat/foam-extend32/ branch master into master
[foam-extend-3.2.git] / src / lagrangian / dieselSpray / injector / definedInjector / definedInjector.C
blob22b09bdff6c32f3a59aad8f2d0dfc8d0659dc1ea
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 "definedInjector.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "Random.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
35 defineTypeNameAndDebug(definedInjector, 0);
37 addToRunTimeSelectionTable
39     injectorType,
40     definedInjector,
41     dictionary
47 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
49 // Construct from components
50 Foam::definedInjector::definedInjector
52     const Time& t,
53     const 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     mass_(readScalar(propsDict_.lookup("mass"))),
62     T_(readScalar(propsDict_.lookup("temperature"))),
63     nParcels_(readLabel(propsDict_.lookup("nParcels"))),
64     X_(propsDict_.lookup("X")),
65     massFlowRateProfile_(propsDict_.lookup("massFlowRateProfile")),
66     velocityProfile_(propsDict_.lookup("velocityProfile")),
67     injectionPressureProfile_(massFlowRateProfile_),
68     CdProfile_(massFlowRateProfile_),
69     averageParcelMass_(mass_/nParcels_),
70     pressureIndependentVelocity_(true)
72     // convert CA to real time - mass flow rate profile
73     forAll(massFlowRateProfile_, i)
74     {
75         massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
76         // dummy
77         injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
78         injectionPressureProfile_[i][1] = 0.0;
79         CdProfile_[i][0] = massFlowRateProfile_[i][0];
80         CdProfile_[i][1] = 1.0;
81     }
83     forAll(velocityProfile_, i)
84     {
85         velocityProfile_[i][0] = t.userTimeToTime(velocityProfile_[i][0]);
86     }
88     // check if time entries match
89     if (mag(massFlowRateProfile_[0][0]-velocityProfile_[0][0]) > SMALL)
90     {
91         FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
92             << " start-times do not match for velocityProfile and massFlowRateProfile."
93             << abort(FatalError);
94     }
96     if (mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]-velocityProfile_[velocityProfile_.size()-1][0]) > SMALL)
97     {
98         FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
99             << " end-times do not match for velocityProfile and massFlowRateProfile."
100             << abort(FatalError);
101     }
103     // calculate integral of mass flow rate profile
104     scalar integratedMFR = integrateTable(massFlowRateProfile_);
106     // correct the massFlowRate profile to match the injector
107     forAll(massFlowRateProfile_, i)
108     {
109         massFlowRateProfile_[i][1] *= mass_/integratedMFR;
110     }
112     // Normalize the direction vector
113     direction_ /= mag(direction_);
115     setTangentialVectors();
117     // check molar fractions
118     scalar Xsum = 0.0;
119     forAll(X_, i)
120     {
121         Xsum += X_[i];
122     }
124     if (mag(Xsum - 1.0) > SMALL)
125     {
126         WarningIn
127         (
128             "definedInjector::definedInjector(const time& t, Istream& is)"
129         )   << "X does not add up to 1.0, correcting molar fractions."
130             << endl;
132         forAll(X_, i)
133         {
134             X_[i] /= Xsum;
135         }
136     }
140 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
142 Foam::definedInjector::~definedInjector()
146 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
148 void Foam::definedInjector::setTangentialVectors()
150     Random rndGen(label(0));
151     scalar magV = 0.0;
152     vector tangent;
154     while (magV < SMALL)
155     {
156         vector testThis = rndGen.vector01();
158         tangent = testThis - (testThis & direction_)*direction_;
159         magV = mag(tangent);
160     }
162     tangentialInjectionVector1_ = tangent/magV;
163     tangentialInjectionVector2_ = direction_ ^ tangentialInjectionVector1_;
167 Foam::label Foam::definedInjector::nParcelsToInject
169     const scalar time0,
170     const scalar time1
171 ) const
174     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
175     label nParcels = label(mInj/averageParcelMass_ + 0.49);
177     return nParcels;
180 const Foam::vector Foam::definedInjector::position(const label n) const
182     return position_;
185 Foam::vector Foam::definedInjector::position
187     const label n,
188     const scalar time,
189     const bool twoD,
190     const scalar angleOfWedge,
191     const vector& axisOfSymmetry,
192     const vector& axisOfWedge,
193     const vector& axisOfWedgeNormal,
194     Random& rndGen
195 ) const
197     if (twoD)
198     {
199         scalar is = position_ & axisOfSymmetry;
200         scalar magInj = mag(position_ - is*axisOfSymmetry);
202         vector halfWedge =
203             axisOfWedge*cos(0.5*angleOfWedge)
204           + axisOfWedgeNormal*sin(0.5*angleOfWedge);
205         halfWedge /= mag(halfWedge);
207         return (is*axisOfSymmetry + magInj*halfWedge);
208     }
209     else
210     {
211         // otherwise, disc injection
212         scalar iRadius = d_*rndGen.scalar01();
213         scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
215         return
216         (
217             position_
218           + iRadius
219           * (
220               tangentialInjectionVector1_*cos(iAngle)
221             + tangentialInjectionVector2_*sin(iAngle)
222           )
223         );
225     }
227     return position_;
230 Foam::label Foam::definedInjector::nHoles() const
232     return 1;
235 Foam::scalar Foam::definedInjector::d() const
237     return d_;
240 const Foam::vector& Foam::definedInjector::direction
242     const label i,
243     const scalar time
244 ) const
246     return direction_;
249 Foam::scalar Foam::definedInjector::mass
251     const scalar time0,
252     const scalar time1,
253     const bool twoD,
254     const scalar angleOfWedge
255 ) const
257     scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
259     // correct mass if calculation is 2D
260     if (twoD)
261     {
262         mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
263     }
265     return mInj;
268 Foam::scalar Foam::definedInjector::mass() const
270     return mass_;
273 Foam::scalar Foam::definedInjector::massFlowRate(const scalar time) const
275     return getTableValue(massFlowRateProfile_, time);
278 Foam::scalar Foam::definedInjector::injectionPressure(const scalar time) const
280     return getTableValue(injectionPressureProfile_, time);
283 Foam::scalar Foam::definedInjector::Cd(const scalar time) const
285     return getTableValue(CdProfile_, time);
288 const Foam::scalarField& Foam::definedInjector::X() const
290     return X_;
293 Foam::List<Foam::definedInjector::pair> Foam::definedInjector::T() const
295     return TProfile_;
298 Foam::scalar Foam::definedInjector::T(const scalar time) const
300     return T_;
303 Foam::scalar Foam::definedInjector::tsoi() const
305     return massFlowRateProfile_[0][0];
308 Foam::scalar Foam::definedInjector::teoi() const
310     return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
313 Foam::scalar Foam::definedInjector::fractionOfInjection
315     const scalar time
316 ) const
318     return integrateTable(massFlowRateProfile_, time)/mass_;
321 Foam::scalar Foam::definedInjector::velocity
323     const scalar time
324 ) const
326     return getTableValue(velocityProfile_, time);
329 Foam::scalar Foam::definedInjector::injectedMass
331     const scalar t
332 ) const
334     return mass_*fractionOfInjection(t);
337 void Foam::definedInjector::correctProfiles
339     const liquidMixture& fuel,
340     const scalar referencePressure
343     scalar A = 0.25*mathematicalConstant::pi*pow(d_, 2.0);
344     scalar pDummy = 1.0e+5;
345     scalar rho = fuel.rho(pDummy, T_, X_);
347     forAll(velocityProfile_, i)
348     {
349         scalar mfr = massFlowRateProfile_[i][1];
350         scalar v = velocityProfile_[i][1];
351         injectionPressureProfile_[i][1] = referencePressure + 0.5*rho*v*v;
352         CdProfile_[i][1] = mfr/(v*rho*A);
353     }
356 Foam::vector Foam::definedInjector::tan1(const label n) const
358     return tangentialInjectionVector1_;
361 Foam::vector Foam::definedInjector::tan2(const label n) const
363     return tangentialInjectionVector2_;
366 // ************************************************************************* //