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

cellMDLimitedGrad.H

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 Class
00026     Foam::fv::cellMDLimitedGrad
00027 
00028 Description
00029     cellMDLimitedGrad gradient scheme applied to a runTime selected base
00030     gradient scheme.
00031 
00032     The scalar limiter based on limiting the extrapolated face values
00033     between the maximum and minimum cell and cell neighbour values and is
00034     applied to the gradient in each face direction separately.
00035 
00036 SourceFiles
00037     cellMDLimitedGrad.C
00038 
00039 \*---------------------------------------------------------------------------*/
00040 
00041 #ifndef cellMDLimitedGrad_H
00042 #define cellMDLimitedGrad_H
00043 
00044 #include "gradScheme.H"
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053 namespace fv
00054 {
00055 
00056 /*---------------------------------------------------------------------------*\
00057                        Class cellMDLimitedGrad Declaration
00058 \*---------------------------------------------------------------------------*/
00059 
00060 template<class Type>
00061 class cellMDLimitedGrad
00062 :
00063     public fv::gradScheme<Type>
00064 {
00065     // Private Data
00066 
00067         tmp<fv::gradScheme<Type> > basicGradScheme_;
00068 
00069         //- Limiter coefficient
00070         const scalar k_;
00071 
00072 
00073     // Private Member Functions
00074 
00075         //- Disallow default bitwise copy construct
00076         cellMDLimitedGrad(const cellMDLimitedGrad&);
00077 
00078         //- Disallow default bitwise assignment
00079         void operator=(const cellMDLimitedGrad&);
00080 
00081 
00082 public:
00083 
00084     //- RunTime type information
00085     TypeName("cellMDLimited");
00086 
00087 
00088     // Constructors
00089 
00090         //- Construct from mesh and schemeData
00091         cellMDLimitedGrad(const fvMesh& mesh, Istream& schemeData)
00092         :
00093             gradScheme<Type>(mesh),
00094             basicGradScheme_(fv::gradScheme<Type>::New(mesh, schemeData)),
00095             k_(readScalar(schemeData))
00096         {
00097             if (k_ < 0 || k_ > 1)
00098             {
00099                 FatalIOErrorIn
00100                 (
00101                     "cellMDLimitedGrad(const fvMesh&, Istream& schemeData)",
00102                     schemeData
00103                 )   << "coefficient = " << k_
00104                     << " should be >= 0 and <= 1"
00105                     << exit(FatalIOError);
00106             }
00107         }
00108 
00109 
00110     // Member Functions
00111 
00112         static inline void limitFace
00113         (
00114             typename outerProduct<vector, Type>::type& g,
00115             const Type& maxDelta,
00116             const Type& minDelta,
00117             const vector& dcf
00118         );
00119 
00120         tmp
00121         <
00122             GeometricField
00123             <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
00124         > grad
00125         (
00126             const GeometricField<Type, fvPatchField, volMesh>&
00127         ) const;
00128 };
00129 
00130 
00131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00132 
00133 template<>
00134 inline void cellMDLimitedGrad<scalar>::limitFace
00135 (
00136     vector& g,
00137     const scalar& maxDelta,
00138     const scalar& minDelta,
00139     const vector& dcf
00140 )
00141 {
00142     scalar extrapolate = dcf & g;
00143 
00144     if (extrapolate > maxDelta)
00145     {
00146         g = g + dcf*(maxDelta - extrapolate)/magSqr(dcf);
00147     }
00148     else if (extrapolate < minDelta)
00149     {
00150         g = g + dcf*(minDelta - extrapolate)/magSqr(dcf);
00151     }
00152 }
00153 
00154 
00155 template<class Type>
00156 inline void cellMDLimitedGrad<Type>::limitFace
00157 (
00158     typename outerProduct<vector, Type>::type& g,
00159     const Type& maxDelta,
00160     const Type& minDelta,
00161     const vector& dcf
00162 )
00163 {
00164     for(direction cmpt=0; cmpt<Type::nComponents; cmpt++)
00165     {
00166         vector gi(g[cmpt], g[cmpt+3], g[cmpt+6]);
00167         cellMDLimitedGrad<scalar>::limitFace
00168         (
00169             gi,
00170             maxDelta.component(cmpt),
00171             minDelta.component(cmpt),
00172             dcf
00173         );
00174         g[cmpt] = gi.x();
00175         g[cmpt+3] = gi.y();
00176         g[cmpt+6] = gi.z();
00177     }
00178 }
00179 
00180 
00181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00182 
00183 } // End namespace fv
00184 
00185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00186 
00187 } // End namespace Foam
00188 
00189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00190 
00191 #endif
00192 
00193 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd