filteredLinear2V.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-2018 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::filteredLinear2VLimiter
26 
27 Description
28  Class to generate weighting factors for the filteredLinear2V
29  differencing scheme.
30 
31  The aim is to remove high-frequency modes with "staggering"
32  characteristics from vector fields by comparing the face gradient in
33  the direction of maximum gradient with both neighbouring cell gradients
34  and introduce small amounts of upwind in order to damp these modes.
35 
36  Used in conjunction with the template class LimitedScheme.
37 
38 SourceFiles
39  filteredLinear2V.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef filteredLinear2V_H
44 #define filteredLinear2V_H
45 
46 #include "vector.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class filteredLinear2VLimiter Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class LimiterFunc>
59 :
60  public LimiterFunc
61 {
62  // Private data
63 
64  // Scaling corefficient 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  vector dfV = phiN - phiP;
117 
118  // Scalar difference across the face
119  // in the direction in which the difference is largest
120  scalar df = dfV & dfV;
121 
122  // Twice differences across face-neighbour cells
123  // in the direction in which the face-difference is largest
124  scalar tdcP = 2*(dfV & (d & gradcP));
125  scalar tdcN = 2*(dfV & (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))) + vSmall);
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))) + vSmall);
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 // ************************************************************************* //
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:68
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
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
dimensioned< scalar > mag(const dimensioned< Type > &)
Class to generate weighting factors for the filteredLinear2V differencing scheme. ...
Namespace for OpenFOAM.
IOerror FatalIOError