FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <lagrangianIntermediate/GradientDispersionRAS.H>
00027 
00028 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00029 
00030 template<class CloudType>
00031 Foam::GradientDispersionRAS<CloudType>::GradientDispersionRAS
00032 (
00033     const dictionary& dict,
00034     CloudType& owner
00035 )
00036 :
00037     DispersionRASModel<CloudType>(dict, owner),
00038     gradkPtr_(NULL)
00039 {}
00040 
00041 
00042 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00043 
00044 template<class CloudType>
00045 Foam::GradientDispersionRAS<CloudType>::~GradientDispersionRAS()
00046 {
00047     cacheFields(false);
00048 }
00049 
00050 
00051 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00052 
00053 template<class CloudType>
00054 bool Foam::GradientDispersionRAS<CloudType>::active() const
00055 {
00056     return true;
00057 }
00058 
00059 
00060 template<class CloudType>
00061 void Foam::GradientDispersionRAS<CloudType>::cacheFields(const bool store)
00062 {
00063     DispersionRASModel<CloudType>::cacheFields(store);
00064 
00065     if (store)
00066     {
00067         gradkPtr_ = fvc::grad(*this->kPtr_).ptr();
00068     }
00069     else
00070     {
00071         if (gradkPtr_)
00072         {
00073             delete gradkPtr_;
00074             gradkPtr_ = NULL;
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 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines