initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / finiteVolume / gradSchemes / limitedGradSchemes / cellMDLimitedGrad / cellMDLimitedGrad.H
blob05953638b2ee7049f0ab93dc9f56c5b681a09978
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::fv::cellMDLimitedGrad
28 Description
29     cellMDLimitedGrad gradient scheme applied to a runTime selected base
30     gradient scheme.
32     The scalar limiter based on limiting the extrapolated face values
33     between the maximum and minimum cell and cell neighbour values and is
34     applied to the gradient in each face direction separately.
36 SourceFiles
37     cellMDLimitedGrad.C
39 \*---------------------------------------------------------------------------*/
41 #ifndef cellMDLimitedGrad_H
42 #define cellMDLimitedGrad_H
44 #include "gradScheme.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 namespace Foam
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 namespace fv
56 /*---------------------------------------------------------------------------*\
57                        Class cellMDLimitedGrad Declaration
58 \*---------------------------------------------------------------------------*/
60 template<class Type>
61 class cellMDLimitedGrad
63     public fv::gradScheme<Type>
65     // Private Data
67         tmp<fv::gradScheme<Type> > basicGradScheme_;
69         //- Limiter coefficient
70         const scalar k_;
73     // Private Member Functions
75         //- Disallow default bitwise copy construct
76         cellMDLimitedGrad(const cellMDLimitedGrad&);
78         //- Disallow default bitwise assignment
79         void operator=(const cellMDLimitedGrad&);
82 public:
84     //- RunTime type information
85     TypeName("cellMDLimited");
88     // Constructors
90         //- Construct from mesh and schemeData
91         cellMDLimitedGrad(const fvMesh& mesh, Istream& schemeData)
92         :
93             gradScheme<Type>(mesh),
94             basicGradScheme_(fv::gradScheme<Type>::New(mesh, schemeData)),
95             k_(readScalar(schemeData))
96         {
97             if (k_ < 0 || k_ > 1)
98             {
99                 FatalIOErrorIn
100                 (
101                     "cellMDLimitedGrad(const fvMesh&, Istream& schemeData)",
102                     schemeData
103                 )   << "coefficient = " << k_
104                     << " should be >= 0 and <= 1"
105                     << exit(FatalIOError);
106             }
107         }
110     // Member Functions
112         static inline void limitFace
113         (
114             typename outerProduct<vector, Type>::type& g,
115             const Type& maxDelta,
116             const Type& minDelta,
117             const vector& dcf
118         );
120         tmp
121         <
122             GeometricField
123             <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
124         > grad
125         (
126             const GeometricField<Type, fvPatchField, volMesh>&
127         ) const;
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 template<>
134 inline void cellMDLimitedGrad<scalar>::limitFace
136     vector& g,
137     const scalar& maxDelta,
138     const scalar& minDelta,
139     const vector& dcf
142     scalar extrapolate = dcf & g;
144     if (extrapolate > maxDelta)
145     {
146         g = g + dcf*(maxDelta - extrapolate)/magSqr(dcf);
147     }
148     else if (extrapolate < minDelta)
149     {
150         g = g + dcf*(minDelta - extrapolate)/magSqr(dcf);
151     }
155 template<class Type>
156 inline void cellMDLimitedGrad<Type>::limitFace
158     typename outerProduct<vector, Type>::type& g,
159     const Type& maxDelta,
160     const Type& minDelta,
161     const vector& dcf
164     for(direction cmpt=0; cmpt<Type::nComponents; cmpt++)
165     {
166         vector gi(g[cmpt], g[cmpt+3], g[cmpt+6]);
167         cellMDLimitedGrad<scalar>::limitFace
168         (
169             gi,
170             maxDelta.component(cmpt),
171             minDelta.component(cmpt),
172             dcf
173         );
174         g[cmpt] = gi.x();
175         g[cmpt+3] = gi.y();
176         g[cmpt+6] = gi.z();
177     }
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 } // End namespace fv
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 } // End namespace Foam
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 #endif
193 // ************************************************************************* //