initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / interpolation / surfaceInterpolation / limitedSchemes / filteredLinear2 / filteredLinear2.H
blob90503633e1504619c7ab24576cb11b5df0d1a755
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::filteredLinear2Limiter
28 Description
29     Class to generate weighting factors for the filteredLinear2
30     differencing scheme.
32     The aim is to remove high-frequency modes with "staggering"
33     characteristics by comparing the face gradient with both neighbouring
34     cell gradients and introduce small amounts of upwind in order to damp
35     these modes.
37     Used in conjunction with the template class LimitedScheme.
39 SourceFiles
40     filteredLinear2.C
42 \*---------------------------------------------------------------------------*/
44 #ifndef filteredLinear2_H
45 #define filteredLinear2_H
47 #include "vector.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 namespace Foam
54 /*---------------------------------------------------------------------------*\
55                      Class filteredLinear2Limiter Declaration
56 \*---------------------------------------------------------------------------*/
58 template<class LimiterFunc>
59 class filteredLinear2Limiter
61     public LimiterFunc
63     // Private data
65         // Scaling corefficient for the gradient ratio,
66         // 0 = linear
67         // 1 = fully limited
68         scalar k_;
70         // Maximum allowed overshoot/undershoot relative to the difference
71         // across the face.
72         // On input:
73         //     0 = no overshoot/undershoot
74         //     1 = overshoot/undershoot equal to the difference across the face
75         // Note: After input 1 is added to l_
76         scalar l_;
79 public:
81     filteredLinear2Limiter(Istream& is)
82     :
83         k_(readScalar(is)),
84         l_(readScalar(is))
85     {
86         if (k_ < 0 || k_ > 1)
87         {
88             FatalIOErrorIn("filteredLinearV2Limiter(Istream& is)", is)
89                 << "coefficient = " << k_
90                 << " should be >= 0 and <= 1"
91                 << exit(FatalIOError);
92         }
94         if (l_ < 0 || l_ > 1)
95         {
96             FatalIOErrorIn("filteredLinearV2Limiter(Istream& is)", is)
97                 << "coefficient = " << l_
98                 << " should be >= 0 and <= 1"
99                 << exit(FatalIOError);
100         }
102         l_ += 1.0;
103     }
105     scalar limiter
106     (
107         const scalar cdWeight,
108         const scalar faceFlux,
109         const typename LimiterFunc::phiType& phiP,
110         const typename LimiterFunc::phiType& phiN,
111         const typename LimiterFunc::gradPhiType& gradcP,
112         const typename LimiterFunc::gradPhiType& gradcN,
113         const vector& d
114     ) const
115     {
116         // Difference across face
117         scalar df = phiN - phiP;
119         // Twice the differences across face-neighbour cells
120         scalar tdcP = 2*(d & gradcP);
121         scalar tdcN = 2*(d & gradcN);
123         // Calculate the limiter according to the sign of the face difference
124         scalar limiter;
126         if (df > 0)
127         {
128             limiter = l_
129                 - k_*min(max(df - tdcP, 0), max(df - tdcN, 0))
130                 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + SMALL);
131         }
132         else
133         {
134             limiter = l_
135                 - k_*min(max(tdcP - df, 0), max(tdcN - df, 0))
136                 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + SMALL);
137         }
139         // Limit the limiter between linear and upwind
140         return max(min(limiter, 1), 0);
141     }
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 } // End namespace Foam
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 #endif
153 // ************************************************************************* //