All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
filteredLinear2.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::filteredLinear2Limiter
26 
27 Description
28  Class to generate weighting factors for the filteredLinear2
29  differencing scheme.
30 
31  The aim is to remove high-frequency modes with "staggering"
32  characteristics by comparing the face gradient with both neighbouring
33  cell gradients and introduce small amounts of upwind in order to damp
34  these modes.
35 
36  Used in conjunction with the template class LimitedScheme.
37 
38 SourceFiles
39  filteredLinear2.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef filteredLinear2_H
44 #define filteredLinear2_H
45 
46 #include "vector.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class filteredLinear2Limiter Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class LimiterFunc>
59 :
60  public LimiterFunc
61 {
62  // Private Data
63 
64  // Scaling coefficient for the gradient ratio,
65  // 0 = linear
66  // 1 = fully limited
67  scalar k_;
68 
69  // Maximum allowed overshoot/undershoot relative to the difference
70  // across the face.
71  // On input:
72  // 0 = no overshoot/undershoot
73  // 1 = overshoot/undershoot equal to the difference across the face
74  // Note: After input 1 is added to l_
75  scalar l_;
76 
77 
78 public:
79 
81  :
82  k_(readScalar(is)),
83  l_(readScalar(is))
84  {
85  if (k_ < 0 || k_ > 1)
86  {
88  << "coefficient = " << k_
89  << " should be >= 0 and <= 1"
90  << exit(FatalIOError);
91  }
92 
93  if (l_ < 0 || l_ > 1)
94  {
96  << "coefficient = " << l_
97  << " should be >= 0 and <= 1"
98  << exit(FatalIOError);
99  }
100 
101  l_ += 1.0;
102  }
103 
104  scalar limiter
105  (
106  const scalar cdWeight,
107  const scalar faceFlux,
108  const typename LimiterFunc::phiType& phiP,
109  const typename LimiterFunc::phiType& phiN,
110  const typename LimiterFunc::gradPhiType& gradcP,
111  const typename LimiterFunc::gradPhiType& gradcN,
112  const vector& d
113  ) const
114  {
115  // Difference across face
116  scalar df = phiN - phiP;
117 
118  // Twice the differences across face-neighbour cells
119  scalar tdcP = 2*(d & gradcP);
120  scalar tdcN = 2*(d & gradcN);
121 
122  // Calculate the limiter according to the sign of the face difference
123  scalar limiter;
124 
125  if (df > 0)
126  {
127  limiter = l_
128  - k_*min(max(df - tdcP, 0), max(df - tdcN, 0))
129  /(max(mag(df), max(mag(tdcP), mag(tdcN))) + small);
130  }
131  else
132  {
133  limiter = l_
134  - k_*min(max(tdcP - df, 0), max(tdcN - df, 0))
135  /(max(mag(df), max(mag(tdcP), mag(tdcN))) + small);
136  }
137 
138  // Limit the limiter between linear and upwind
139  return max(min(limiter, 1), 0);
140  }
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #endif
151 
152 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
Class to generate weighting factors for the filteredLinear2 differencing scheme.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
dimensioned< scalar > mag(const dimensioned< Type > &)
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
Namespace for OpenFOAM.
IOerror FatalIOError