Merge /u/wyldckat/foam-extend32/ branch master into master
[foam-extend-3.2.git] / src / lagrangian / dieselSpray / spraySubModels / injectorModel / definedHollowCone / definedHollowCone.C
blob51894863c02c563d44131d22ec7d81fe94839ef6
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 "definedHollowCone.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(definedHollowConeInjector, 0);
39 addToRunTimeSelectionTable
41     injectorModel,
42     definedHollowConeInjector,
43     dictionary
47 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
49 // Construct from components
50 definedHollowConeInjector::definedHollowConeInjector
52     const dictionary& dict,
53     spray& sm
56     injectorModel(dict, sm),
57     definedHollowConeDict_(dict.subDict(typeName + "Coeffs")),
58     dropletPDF_
59     (
60         pdf::New
61         (
62             definedHollowConeDict_.subDict("dropletPDF"),
63             sm.rndGen()
64         )
65     ),
66     innerConeAngle_(definedHollowConeDict_.lookup("innerConeAngle")),
67     outerConeAngle_(definedHollowConeDict_.lookup("outerConeAngle"))
70     // convert CA to real time - inner cone angle
71     forAll(innerConeAngle_, i)
72     {
73         innerConeAngle_[i][0] = sm.runTime().userTimeToTime(innerConeAngle_[i][0]);
74     }
75     // convert CA to real time - outer cone angle
76     forAll(outerConeAngle_, i)
77     {
78         outerConeAngle_[i][0] = sm.runTime().userTimeToTime(outerConeAngle_[i][0]);
79     }
81     // check number of injectors
82     if (sm.injectors().size() != 1)
83     {
84         Info << "Warning!!!\n"
85              << "definedHollowConeInjector::definedHollowConeInjector"
86              << "(const dictionary& dict, spray& sm)\n"
87              << "Same inner/outer cone angle profiles applied to each injector"
88              << endl;
89     }
91     // check number of entries in innerConeAngle list
92     if (innerConeAngle_.empty())
93     {
94         FatalError << "definedHollowConeInjector::definedHollowConeInjector"
95              << "(const dictionary& dict, spray& sm)\n"
96              << "Number of entries in innerConeAngle must be greater than zero"
97              << abort(FatalError);
98     }
100     // check number of entries in outerConeAngle list
101     if (outerConeAngle_.empty())
102     {
103         FatalError << "definedHollowConeInjector::definedHollowConeInjector"
104              << "(const dictionary& dict, spray& sm)\n"
105              << "Number of entries in outerConeAngle must be greater than zero"
106              << abort(FatalError);
107     }
109     scalar referencePressure = sm.p().average().value();
110     // correct pressureProfile
111     forAll(sm.injectors(), i)
112     {
113         sm.injectors()[i].properties()->correctProfiles(sm.fuels(), referencePressure);
114     }
119 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
121 definedHollowConeInjector::~definedHollowConeInjector()
125 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
127 scalar definedHollowConeInjector::d0
129     const label n,
130     const scalar t
131 ) const
133     // swallow function arguments - not used
134     // return value sampled from PDF
135     return dropletPDF_->sample();
139 vector definedHollowConeInjector::direction
141     const label n,
142     const label hole,
143     const scalar t,
144     const scalar d
145 ) const
148     const injectorType& it = injectors_[n].properties();
150     // interpolate to find inner and outer angles at time, t
151     scalar angleInner = it.getTableValue(innerConeAngle_, t);
152     scalar angleOuter = it.getTableValue(outerConeAngle_, t);
154     // use random number to generate angle between inner/outer cone angles
155     scalar angle = angleInner + rndGen_.scalar01()*(angleOuter-angleInner);
157     scalar alpha = sin(angle*mathematicalConstant::pi/360.0);
158     scalar dcorr = cos(angle*mathematicalConstant::pi/360.0);
159     scalar beta = 2.0*mathematicalConstant::pi*rndGen_.scalar01();
161     // randomly distributed vector normal to the injection vector
162     vector normal = vector::zero;
164     if (sm_.twoD())
165     {
166         scalar reduce = 0.01;
167         // correct beta if this is a 2D run
168         // map it onto the 'angleOfWedge'
170         beta *= (1.0-2.0*reduce)*sm_.angleOfWedge()/(2.0*mathematicalConstant::pi);
171         beta += reduce*sm_.angleOfWedge();
172         normal = alpha*
173         (
174             sm_.axisOfWedge()*cos(beta) +
175             sm_.axisOfWedgeNormal()*sin(beta)
176         );
177     }
178     else
179     {
180         normal = alpha*
181         (
182             injectors_[n].properties()->tan1(hole)*cos(beta) +
183             injectors_[n].properties()->tan2(hole)*sin(beta)
184         );
185     }
187     // set the direction of injection by adding the normal vector
188     vector dir = dcorr*injectors_[n].properties()->direction(hole, t) + normal;
189     // normailse direction vector
190     dir /= mag(dir);
192     return dir;
196 scalar definedHollowConeInjector::velocity
198     const label i,
199     const scalar time
200 ) const
202     const injectorType& it = sm_.injectors()[i].properties();
203     if (it.pressureIndependentVelocity())
204     {
205         return it.getTableValue(it.velocityProfile(), time);
206     }
207     else
208     {
209         scalar Pref = sm_.ambientPressure();
210         scalar Pinj = it.getTableValue(it.injectionPressureProfile(), time);
211         scalar rho = sm_.fuels().rho(Pinj, it.T(time), it.X());
212         scalar dp = max(0.0, Pinj - Pref);
213         return sqrt(2.0*dp/rho);
214     }
217 scalar definedHollowConeInjector::averageVelocity
219     const label i
220 ) const
222     const injectorType& it = sm_.injectors()[i].properties();
223     scalar dt = it.teoi() - it.tsoi();
224     return it.integrateTable(it.velocityProfile())/dt;
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 } // End namespace Foam
231 // ************************************************************************* //