initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / lagrangian / dieselSpray / spraySubModels / injectorModel / definedHollowCone / definedHollowCone.C
blob6f06bb17528c7806a5fcfb30eb079244eb0e1711
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "definedHollowCone.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(definedHollowConeInjector, 0);
40 addToRunTimeSelectionTable
42     injectorModel,
43     definedHollowConeInjector,
44     dictionary
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 // Construct from components
51 definedHollowConeInjector::definedHollowConeInjector
53     const dictionary& dict,
54     spray& sm
57     injectorModel(dict, sm),
58     definedHollowConeDict_(dict.subDict(typeName + "Coeffs")),
59     dropletPDF_
60     (
61         pdf::New
62         (
63             definedHollowConeDict_.subDict("dropletPDF"),
64             sm.rndGen()
65         )
66     ),
67     innerConeAngle_(definedHollowConeDict_.lookup("innerConeAngle")),
68     outerConeAngle_(definedHollowConeDict_.lookup("outerConeAngle")),
69     tan1_(sm.injectors().size()),
70     tan2_(sm.injectors().size())
73     // convert CA to real time - inner cone angle
74     forAll(innerConeAngle_, i)
75     {
76         innerConeAngle_[i][0] = sm.runTime().userTimeToTime(innerConeAngle_[i][0]);
77     }
78     // convert CA to real time - outer cone angle
79     forAll(outerConeAngle_, i)
80     {
81         outerConeAngle_[i][0] = sm.runTime().userTimeToTime(outerConeAngle_[i][0]);
82     }
84     // check number of injectors
85     if (sm.injectors().size() != 1)
86     {
87         Info << "Warning!!!\n"
88              << "definedHollowConeInjector::definedHollowConeInjector"
89              << "(const dictionary& dict, spray& sm)\n"
90              << "Same inner/outer cone angle profiles applied to each injector"
91              << endl;
92     }
94     // check number of entries in innerConeAngle list
95     if (innerConeAngle_.size() < 1)
96     {
97         FatalError << "definedHollowConeInjector::definedHollowConeInjector"
98              << "(const dictionary& dict, spray& sm)\n"
99              << "Number of entries in innerConeAngle must be greater than zero"
100              << abort(FatalError);
101     }
103     // check number of entries in outerConeAngle list
104     if (outerConeAngle_.size() < 1)
105     {
106         FatalError << "definedHollowConeInjector::definedHollowConeInjector"
107              << "(const dictionary& dict, spray& sm)\n"
108              << "Number of entries in outerConeAngle must be greater than zero"
109              << abort(FatalError);
110     }
112     // initialise injectors
113     forAll(sm.injectors(), i)
114     {
115         Random rndGen(label(0));
116         vector dir = sm.injectors()[i].properties()->direction();
117         scalar magV = 0.0;
118         vector tangent;
119         
120         while (magV < SMALL)
121         {
122             vector testThis = rndGen.vector01();
123             
124             tangent = testThis - (testThis & dir)*dir;
125             magV = mag(tangent);
126         }
127         
128         tan1_[i] = tangent/magV;
129         tan2_[i] = dir ^ tan1_[i];
130     }
132     scalar referencePressure = sm.p().average().value();
133     // correct pressureProfile
134     forAll(sm.injectors(), i)
135     {
136         sm.injectors()[i].properties()->correctProfiles(sm.fuels(), referencePressure);
137     }
142 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
144 definedHollowConeInjector::~definedHollowConeInjector()
148 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
150 scalar definedHollowConeInjector::d0
152     const label n, 
153     const scalar t
154 ) const
156     // swallow function arguments - not used
157     // return value sampled from PDF
158     return dropletPDF_->sample();
162 vector definedHollowConeInjector::direction
164     const label n,
165     const scalar t,
166     const scalar d
167 ) const
170     const injectorType& it = injectors_[n].properties();
172     // interpolate to find inner and outer angles at time, t
173     scalar angleInner = it.getTableValue(innerConeAngle_, t);
174     scalar angleOuter = it.getTableValue(outerConeAngle_, t);
176     // use random number to generate angle between inner/outer cone angles
177     scalar angle = angleInner + rndGen_.scalar01()*(angleOuter-angleInner);
179     scalar alpha = sin(angle*mathematicalConstant::pi/360.0);
180     scalar dcorr = cos(angle*mathematicalConstant::pi/360.0);
181     scalar beta = 2.0*mathematicalConstant::pi*rndGen_.scalar01();
183     // randomly distributed vector normal to the injection vector
184     vector normal = vector::zero;
185     
186     if (sm_.twoD())
187     {
188         scalar reduce = 0.01;
189         // correct beta if this is a 2D run
190         // map it onto the 'angleOfWedge'
192         beta *= (1.0-2.0*reduce)*sm_.angleOfWedge()/(2.0*mathematicalConstant::pi);
193         beta += reduce*sm_.angleOfWedge();
194         normal = alpha*
195         (
196             sm_.axisOfWedge()*cos(beta) +
197             sm_.axisOfWedgeNormal()*sin(beta)
198         );
199     }
200     else
201     {
202         normal = alpha*
203         (
204             tan1_[n]*cos(beta) +
205             tan2_[n]*sin(beta)
206         );
207     }
208     
209     // set the direction of injection by adding the normal vector
210     vector dir = dcorr*injectors_[n].properties()->direction() + normal;
211     // normailse direction vector
212     dir /= mag(dir);
214     return dir;
218 scalar definedHollowConeInjector::velocity
220     const label i,
221     const scalar time
222 ) const
224     const injectorType& it = sm_.injectors()[i].properties();
225     if (it.pressureIndependentVelocity())
226     {
227         return it.getTableValue(it.velocityProfile(), time);
228     }
229     else
230     {
231         scalar Pref = sm_.ambientPressure();
232         scalar Pinj = it.getTableValue(it.injectionPressureProfile(), time);
233         scalar rho = sm_.fuels().rho(Pinj, it.T(time), it.X());
234         scalar dp = max(0.0, Pinj - Pref);
235         return sqrt(2.0*dp/rho);
236     }
239 scalar definedHollowConeInjector::averageVelocity
241     const label i
242 ) const
243 {    
244     const injectorType& it = sm_.injectors()[i].properties();
245     scalar dt = it.teoi() - it.tsoi();
246     return it.integrateTable(it.velocityProfile())/dt;
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 } // End namespace Foam
253 // ************************************************************************* //