All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
filteredLinear3V.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::filteredLinear3VLimiter
26 
27 Description
28  Class to generate weighting factors for the filteredLinear3V
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  filteredLinear3V.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef filteredLinear3V_H
44 #define filteredLinear3V_H
45 
46 #include "vector.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class filteredLinear3VLimiter 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 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  vector dfV = phiN - phiP;
97 
98  // Scalar difference across the face
99  // in the direction in which the difference is largest
100  scalar df = dfV & dfV;
101 
102  // Twice differences across face-neighbour cells
103  // in the direction in which the face-difference is largest
104  scalar dP = 2*(dfV & (d & gradcP));
105  scalar dN = 2*(dfV & (d & gradcN));
106 
107  // Calculate the limiter
108  scalar limiter = 1 - k_*(dN - df)*(dP - df)/max(sqr(dN + dP), small);
109 
110  // Limit the limiter between linear and upwind
111  return max(min(limiter, 1), 0);
112  }
113 };
114 
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 } // End namespace Foam
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 #endif
123 
124 // ************************************************************************* //
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:75
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< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
Class to generate weighting factors for the filteredLinear3V differencing scheme. ...
Namespace for OpenFOAM.
IOerror FatalIOError