filteredLinear2.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2015 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::filteredLinear2Limiter
28
29Group
30 grpFvLimitedSurfaceInterpolationSchemes
31
32Description
33 Class to generate weighting factors for the filteredLinear2
34 differencing scheme.
35
36 The aim is to remove high-frequency modes with "staggering"
37 characteristics by comparing the face gradient with both neighbouring
38 cell gradients and introduce small amounts of upwind in order to damp
39 these modes.
40
41 Used in conjunction with the template class LimitedScheme.
42
43SourceFiles
44 filteredLinear2.C
45
46\*---------------------------------------------------------------------------*/
47
48#ifndef filteredLinear2_H
49#define filteredLinear2_H
50
51#include "vector.H"
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55namespace Foam
56{
57
58/*---------------------------------------------------------------------------*\
59 Class filteredLinear2Limiter Declaration
60\*---------------------------------------------------------------------------*/
61
62template<class LimiterFunc>
64:
65 public LimiterFunc
66{
67 // Private data
68
69 // Scaling coefficient for the gradient ratio,
70 // 0 = linear
71 // 1 = fully limited
72 scalar k_;
73
74 // Maximum allowed overshoot/undershoot relative to the difference
75 // across the face.
76 // On input:
77 // 0 = no overshoot/undershoot
78 // 1 = overshoot/undershoot equal to the difference across the face
79 // Note: After input 1 is added to l_
80 scalar l_;
81
82
83public:
86 :
87 k_(readScalar(is)),
88 l_(readScalar(is))
89 {
90 if (k_ < 0 || k_ > 1)
91 {
93 << "coefficient = " << k_
94 << " should be >= 0 and <= 1"
96 }
97
98 if (l_ < 0 || l_ > 1)
99 {
101 << "coefficient = " << l_
102 << " should be >= 0 and <= 1"
103 << exit(FatalIOError);
104 }
105
106 l_ += 1.0;
107 }
109 scalar limiter
110 (
111 const scalar cdWeight,
112 const scalar faceFlux,
113 const typename LimiterFunc::phiType& phiP,
114 const typename LimiterFunc::phiType& phiN,
115 const typename LimiterFunc::gradPhiType& gradcP,
116 const typename LimiterFunc::gradPhiType& gradcN,
117 const vector& d
118 ) const
119 {
120 // Difference across face
121 scalar df = phiN - phiP;
122
123 // Twice the differences across face-neighbour cells
124 scalar tdcP = 2*(d & gradcP);
125 scalar tdcN = 2*(d & gradcN);
126
127 // Calculate the limiter according to the sign of the face difference
128 scalar limiter;
129
130 if (df > 0)
131 {
132 limiter = l_
133 - k_*min(max(df - tdcP, 0), max(df - tdcN, 0))
134 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + SMALL);
135 }
136 else
137 {
138 limiter = l_
139 - k_*min(max(tdcP - df, 0), max(tdcN - df, 0))
140 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + SMALL);
141 }
142
143 // Limit the limiter between linear and upwind
144 return max(min(limiter, 1), 0);
145 }
146};
147
148
149// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
151} // End namespace Foam
152
153// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154
155#endif
156
157// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Class to generate weighting factors for the filteredLinear2 differencing scheme.
scalar limiter(const scalar cdWeight, const scalar faceFlux, const typename LimiterFunc::phiType &phiP, const typename LimiterFunc::phiType &phiN, const typename LimiterFunc::gradPhiType &gradcP, const typename LimiterFunc::gradPhiType &gradcN, const vector &d) const
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130