OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

GradientDispersionRAS.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "GradientDispersionRAS.H"
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 template<class CloudType>
00032 Foam::GradientDispersionRAS<CloudType>::GradientDispersionRAS
00033 (
00034     const dictionary& dict,
00035     CloudType& owner
00036 )
00037 :
00038     DispersionRASModel<CloudType>(dict, owner),
00039     gradkPtr_(NULL)
00040 {}
00041 
00042 
00043 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00044 
00045 template<class CloudType>
00046 Foam::GradientDispersionRAS<CloudType>::~GradientDispersionRAS()
00047 {
00048     cacheFields(false);
00049 }
00050 
00051 
00052 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00053 
00054 template<class CloudType>
00055 bool Foam::GradientDispersionRAS<CloudType>::active() const
00056 {
00057     return true;
00058 }
00059 
00060 
00061 template<class CloudType>
00062 void Foam::GradientDispersionRAS<CloudType>::cacheFields(const bool store)
00063 {
00064     DispersionRASModel<CloudType>::cacheFields(store);
00065 
00066     if (store)
00067     {
00068         gradkPtr_ = fvc::grad(*this->kPtr_).ptr();
00069     }
00070     else
00071     {
00072         if (gradkPtr_)
00073         {
00074             delete gradkPtr_;
00075         }
00076     }
00077 }
00078 
00079 
00080 template<class CloudType>
00081 Foam::vector Foam::GradientDispersionRAS<CloudType>::update
00082 (
00083     const scalar dt,
00084     const label celli,
00085     const vector& U,
00086     const vector& Uc,
00087     vector& UTurb,
00088     scalar& tTurb
00089 )
00090 {
00091     const scalar cps = 0.16432;
00092 
00093     const volScalarField& k = *this->kPtr_;
00094     const volScalarField& epsilon = *this->epsilonPtr_;
00095     const volVectorField& gradk = *this->gradkPtr_;
00096 
00097     const scalar UrelMag = mag(U - Uc - UTurb);
00098 
00099     const scalar tTurbLoc = min
00100     (
00101         k[celli]/epsilon[celli],
00102         cps*pow(k[celli], 1.5)/epsilon[celli]/(UrelMag + SMALL)
00103     );
00104 
00105     // Parcel is perturbed by the turbulence
00106     if (dt < tTurbLoc)
00107     {
00108         tTurb += dt;
00109 
00110         if (tTurb > tTurbLoc)
00111         {
00112             tTurb = 0.0;
00113 
00114             scalar sigma = sqrt(2.0*k[celli]/3.0);
00115             vector dir = -gradk[celli]/(mag(gradk[celli]) + SMALL);
00116 
00117             // Numerical Recipes... Ch. 7. Random Numbers...
00118             scalar x1 = 0.0;
00119             scalar x2 = 0.0;
00120             scalar rsq = 10.0;
00121             while ((rsq > 1.0) || (rsq == 0.0))
00122             {
00123                 x1 = 2.0*this->owner().rndGen().scalar01() - 1.0;
00124                 x2 = 2.0*this->owner().rndGen().scalar01() - 1.0;
00125                 rsq = x1*x1 + x2*x2;
00126             }
00127 
00128             scalar fac = sqrt(-2.0*log(rsq)/rsq);
00129 
00130             // In 2D calculations the -grad(k) is always
00131             // away from the axis of symmetry
00132             // This creates a 'hole' in the spray and to
00133             // prevent this we let x1 be both negative/positive
00134             if (this->owner().mesh().nSolutionD() == 2)
00135             {
00136                 fac *= x1;
00137             }
00138             else
00139             {
00140                 fac *= mag(x1);
00141             }
00142 
00143             UTurb = sigma*fac*dir;
00144         }
00145     }
00146     else
00147     {
00148         tTurb = GREAT;
00149         UTurb = vector::zero;
00150     }
00151 
00152     return Uc + UTurb;
00153 }
00154 
00155 
00156 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd