filteredLinear3.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::filteredLinear3Limiter
26 
27 Description
28  Class to generate weighting factors for the filteredLinear
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  filteredLinear3.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef filteredLinear3_H
44 #define filteredLinear3_H
45 
46 #include "vector.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class filteredLinear3Limiter 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 public:
70 
72  :
73  k_(readScalar(is))
74  {
75  if (k_ < 0 || k_ > 1)
76  {
78  << "coefficient = " << k_
79  << " should be >= 0 and <= 1"
80  << exit(FatalIOError);
81  }
82  }
83 
84  scalar limiter
85  (
86  const scalar cdWeight,
87  const scalar faceFlux,
88  const typename LimiterFunc::phiType& phiP,
89  const typename LimiterFunc::phiType& phiN,
90  const typename LimiterFunc::gradPhiType& gradcP,
91  const typename LimiterFunc::gradPhiType& gradcN,
92  const vector& d
93  ) const
94  {
95  // Difference across face
96  scalar df = phiN - phiP;
97 
98  // Twice the differences across face-neighbour cells
99  scalar dP = 2*(d & gradcP);
100  scalar dN = 2*(d & gradcN);
101 
102  // Calculate the limiter
103  scalar limiter = 1 - k_*(dN - df)*(dP - df)/max(sqr(dN + dP), small);
104 
105  // Limit the limiter between linear and upwind
106  return max(min(limiter, 1), 0);
107  }
108 };
109 
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 
113 } // End namespace Foam
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 #endif
118 
119 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
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 > &)
Class to generate weighting factors for the filteredLinear 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:331
Namespace for OpenFOAM.
IOerror FatalIOError