filteredLinear2V.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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::filteredLinear2VLimiter
28 
29 Description
30  Class to generate weighting factors for the filteredLinear2V
31  differencing scheme.
32 
33  The aim is to remove high-frequency modes with "staggering"
34  characteristics from vector fields by comparing the face gradient in
35  the direction of maximum gradient with both neighbouring cell gradients
36  and introduce small amounts of upwind in order to damp these modes.
37 
38  Used in conjunction with the template class LimitedScheme.
39 
40 SourceFiles
41  filteredLinear2V.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef filteredLinear2V_H
46 #define filteredLinear2V_H
47 
48 #include "vector.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class filteredLinear2VLimiter Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class LimiterFunc>
61 :
62  public LimiterFunc
63 {
64  // Private data
65 
66  // Scaling coefficient for the gradient ratio,
67  // 0 = linear
68  // 1 = fully limited
69  scalar k_;
70 
71  // Maximum allowed overshoot/undershoot relative to the difference
72  // across the face.
73  // On input:
74  // 0 = no overshoot/undershoot
75  // 1 = overshoot/undershoot equal to the difference across the face
76  // Note: After input 1 is added to l_
77  scalar l_;
78 
79 
80 public:
81 
83  :
84  k_(readScalar(is)),
85  l_(readScalar(is))
86  {
87  if (k_ < 0 || k_ > 1)
88  {
90  << "coefficient = " << k_
91  << " should be >= 0 and <= 1"
92  << exit(FatalIOError);
93  }
94 
95  if (l_ < 0 || l_ > 1)
96  {
98  << "coefficient = " << l_
99  << " should be >= 0 and <= 1"
100  << exit(FatalIOError);
101  }
102 
103  l_ += 1.0;
104  }
105 
106  scalar limiter
107  (
108  const scalar cdWeight,
109  const scalar faceFlux,
110  const typename LimiterFunc::phiType& phiP,
111  const typename LimiterFunc::phiType& phiN,
112  const typename LimiterFunc::gradPhiType& gradcP,
113  const typename LimiterFunc::gradPhiType& gradcN,
114  const vector& d
115  ) const
116  {
117  // Difference across face
118  vector dfV = phiN - phiP;
119 
120  // Scalar difference across the face
121  // in the direction in which the difference is largest
122  scalar df = dfV & dfV;
123 
124  // Twice differences across face-neighbour cells
125  // in the direction in which the face-difference is largest
126  scalar tdcP = 2*(dfV & (d & gradcP));
127  scalar tdcN = 2*(dfV & (d & gradcN));
128 
129  // Calculate the limiter according to the sign of the face difference
130  scalar limiter;
131 
132  if (df > 0)
133  {
134  limiter = l_
135  - k_*min(max(df - tdcP, 0), max(df - tdcN, 0))
136  /(max(mag(df), max(mag(tdcP), mag(tdcN))) + VSMALL);
137  }
138  else
139  {
140  limiter = l_
141  - k_*min(max(tdcP - df, 0), max(tdcN - df, 0))
142  /(max(mag(df), max(mag(tdcP), mag(tdcN))) + VSMALL);
143  }
144 
145  // Limit the limiter between linear and upwind
146  return max(min(limiter, 1), 0);
147  }
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Foam
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #endif
158 
159 // ************************************************************************* //
Foam::FatalIOError
IOerror FatalIOError
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::filteredLinear2VLimiter::limiter
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
Definition: filteredLinear2V.H:106
Foam::Vector< scalar >
Foam::filteredLinear2VLimiter
Class to generate weighting factors for the filteredLinear2V differencing scheme.
Definition: filteredLinear2V.H:59
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::filteredLinear2VLimiter::filteredLinear2VLimiter
filteredLinear2VLimiter(Istream &is)
Definition: filteredLinear2V.H:81
vector.H
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473