Transferred copyright to the OpenFOAM Foundation
[OpenFOAM-2.0.x.git] / src / lagrangian / dieselSpray / spraySubModels / dispersionModel / gradientDispersionRAS / gradientDispersionRAS.C
blobcaab9bf2cf029521d93be5c83c470090865a846f
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 "error.H"
28 #include "gradientDispersionRAS.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(gradientDispersionRAS, 0);
37     addToRunTimeSelectionTable
38     (
39         dispersionModel,
40         gradientDispersionRAS,
41         dictionary
42     );
46 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
48 Foam::gradientDispersionRAS::gradientDispersionRAS
50     const dictionary& dict,
51     spray& sm
54     dispersionRASModel(dict, sm)
58 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
60 Foam::gradientDispersionRAS::~gradientDispersionRAS()
64 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
66 void Foam::gradientDispersionRAS::disperseParcels() const
69     const scalar cps = 0.16432;
71     scalar dt = spray_.runTime().deltaTValue();
72     const volScalarField& k = turbulence().k();
73     const volVectorField gradk(fvc::grad(k));
74     const volScalarField& epsilon = turbulence().epsilon();
75     const volVectorField& U = spray_.U();
77     forAllIter(spray, spray_, elmnt)
78     {
79         const label cellI = elmnt().cell();
80         scalar UrelMag = mag(elmnt().U() - U[cellI] - elmnt().Uturb());
82         scalar Tturb = min
83         (
84             k[cellI]/epsilon[cellI],
85             cps*pow(k[cellI], 1.5)/epsilon[cellI]/(UrelMag + SMALL)
86         );
87         // parcel is perturbed by the turbulence
88         if (dt < Tturb)
89         {
90             elmnt().tTurb() += dt;
92             if (elmnt().tTurb() > Tturb)
93             {
94                 elmnt().tTurb() = 0.0;
96                 scalar sigma = sqrt(2.0*k[cellI]/3.0);
97                 vector dir = -gradk[cellI]/(mag(gradk[cellI]) + SMALL);
99                 // numerical recipes... Ch. 7. Random Numbers...
100                 scalar x1 = 0.0;
101                 scalar x2 = 0.0;
102                 scalar rsq = 10.0;
103                 while ((rsq > 1.0) || (rsq == 0.0))
104                 {
105                     x1 = 2.0*spray_.rndGen().sample01<scalar>() - 1.0;
106                     x2 = 2.0*spray_.rndGen().sample01<scalar>() - 1.0;
107                     rsq = x1*x1 + x2*x2;
108                 }
110                 scalar fac = sqrt(-2.0*log(rsq)/rsq);
112                 // in 2D calculations the -grad(k) is always
113                 // away from the axis of symmetry
114                 // This creates a 'hole' in the spray and to
115                 // prevent this we let x1 be both negative/positive
116                 if (spray_.twoD())
117                 {
118                     fac *= x1;
119                 }
120                 else
121                 {
122                     fac *= mag(x1);
123                 }
125                 elmnt().Uturb() = sigma*fac*dir;
126             }
127         }
128         else
129         {
130             elmnt().tTurb() = GREAT;
131             elmnt().Uturb() = vector::zero;
132         }
133     }
137 // ************************************************************************* //