Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / lagrangian / dieselSpray / spraySubModels / injectorModel / constant / constInjector.C
blob2cf0097d6600a009c682c0a5c7f070f423c56748
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
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 "constInjector.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(constInjector, 0);
36     addToRunTimeSelectionTable
37     (
38         injectorModel,
39         constInjector,
40         dictionary
41     );
45 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
47 Foam::constInjector::constInjector
49     const dictionary& dict,
50     spray& sm
53     injectorModel(dict, sm),
54     specDict_(dict.subDict(typeName + "Coeffs")),
55     dropletNozzleDiameterRatio_(specDict_.lookup("dropletNozzleDiameterRatio")),
56     sprayAngle_(specDict_.lookup("sprayAngle"))
58     if (sm.injectors().size() != dropletNozzleDiameterRatio_.size())
59     {
60         FatalErrorIn
61         (
62             "constInjector::constInjector(const dictionary& dict, spray& sm)"
63         )   << "Wrong number of entries in dropletNozzleDiameterRatio" << nl
64             << abort(FatalError);
65     }
67     if (sm.injectors().size() != sprayAngle_.size())
68     {
69         FatalErrorIn
70         (
71             "constInjector::constInjector(const dictionary& dict, spray& sm)"
72         )   << "Wrong number of entries in sprayAngle" << nl
73             << abort(FatalError);
74     }
76     scalar referencePressure = sm.p().average().value();
78     // correct velocity and pressure profiles
79     forAll(sm.injectors(), i)
80     {
81         sm.injectors()[i].properties()->correctProfiles
82         (
83             sm.fuels(),
84             referencePressure
85         );
86     }
90 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
92 Foam::constInjector::~constInjector()
96 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
98 Foam::scalar Foam::constInjector::d0
100     const label n,
101     const scalar
102 ) const
104     return injectors_[n].properties()->d()*dropletNozzleDiameterRatio_[n];
108 Foam::vector Foam::constInjector::direction
110     const label n,
111     const label hole,
112     const scalar time,
113     const scalar d
114 ) const
117     /*
118         randomly distribute parcels in a solid cone
119         with angle = sprayAngle,
120         alpha = radius of the two normal vectors,
121         = maximum sin(sprayAngle/2)
122         beta = angle in the normal plane
124         o                  / (beta)
125         |\                /
126         | \              /)
127         |  \            o-----------> (x-axis)
128         |   \
129         v  (alpha)
130     */
132     scalar angle =
133         rndGen_.sample01<scalar>()*sprayAngle_[n]
134        *constant::mathematical::pi/360.0;
135     scalar alpha = sin(angle);
136     scalar dcorr = cos(angle);
138     scalar beta = constant::mathematical::twoPi*rndGen_.sample01<scalar>();
140     // randomly distributed vector normal to the injection vector
141     vector normal = vector::zero;
143     if (sm_.twoD())
144     {
145         scalar reduce = 0.01;
146         // correct beta if this is a 2D run
147         // map it onto the 'angleOfWedge'
148         beta *=
149             (1.0 - 2.0*reduce)
150            *0.5*sm_.angleOfWedge()
151            /constant::mathematical::pi;
152         beta += reduce*sm_.angleOfWedge();
154         normal =
155             alpha
156            *(
157                 sm_.axisOfWedge()*cos(beta)
158               + sm_.axisOfWedgeNormal()*sin(beta)
159             );
161     }
162     else
163     {
164         normal =
165             alpha
166            *(
167                 injectors_[n].properties()->tan1(hole)*cos(beta)
168               + injectors_[n].properties()->tan2(hole)*sin(beta)
169             );
170     }
172     // set the direction of injection by adding the normal vector
173     vector dir = dcorr*injectors_[n].properties()->direction(n, time) + normal;
174     dir /= mag(dir);
176     return dir;
180 Foam::scalar Foam::constInjector::velocity
182     const label i,
183     const scalar time
184 ) const
186     const injectorType& it = sm_.injectors()[i].properties();
187     if (it.pressureIndependentVelocity())
188     {
189         return it.getTableValue(it.velocityProfile(), time);
190     }
191     else
192     {
193         scalar Pref = sm_.ambientPressure();
194         scalar Pinj = it.getTableValue(it.injectionPressureProfile(), time);
195         scalar rho = sm_.fuels().rho(Pinj, it.T(time), it.X());
196         scalar dp = max(0.0, Pinj - Pref);
197         return sqrt(2.0*dp/rho);
198     }
202 Foam::scalar Foam::constInjector::averageVelocity(const label i) const
204     const injectorType& it = sm_.injectors()[i].properties();
205     scalar dt = it.teoi() - it.tsoi();
207     return it.integrateTable(it.velocityProfile())/dt;
211 // ************************************************************************* //