filteredLinear3V.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::filteredLinear3VLimiter
28 
29 Description
30  Class to generate weighting factors for the filteredLinear3V
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  filteredLinear3V.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef filteredLinear3V_H
46 #define filteredLinear3V_H
47 
48 #include "vector.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class filteredLinear3VLimiter 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 public:
72 
74  :
75  k_(readScalar(is))
76  {
77  if (k_ < 0 || k_ > 1)
78  {
80  << "coefficient = " << k_
81  << " should be >= 0 and <= 1"
82  << exit(FatalIOError);
83  }
84  }
85 
86  scalar limiter
87  (
88  const scalar cdWeight,
89  const scalar faceFlux,
90  const typename LimiterFunc::phiType& phiP,
91  const typename LimiterFunc::phiType& phiN,
92  const typename LimiterFunc::gradPhiType& gradcP,
93  const typename LimiterFunc::gradPhiType& gradcN,
94  const vector& d
95  ) const
96  {
97  // Difference across face
98  vector dfV = phiN - phiP;
99 
100  // Scalar difference across the face
101  // in the direction in which the difference is largest
102  scalar df = dfV & dfV;
103 
104  // Twice differences across face-neighbour cells
105  // in the direction in which the face-difference is largest
106  scalar dP = 2*(dfV & (d & gradcP));
107  scalar dN = 2*(dfV & (d & gradcN));
108 
109  // Calculate the limiter
110  scalar limiter = 1 - k_*(dN - df)*(dP - df)/max(sqr(dN + dP), SMALL);
111 
112  // Limit the limiter between linear and upwind
113  return max(min(limiter, 1), 0);
114  }
115 };
116 
117 
118 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
119 
120 } // End namespace Foam
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 
124 #endif
125 
126 // ************************************************************************* //
Foam::filteredLinear3VLimiter::filteredLinear3VLimiter
filteredLinear3VLimiter(Istream &is)
Definition: filteredLinear3V.H:72
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::filteredLinear3VLimiter::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: filteredLinear3V.H:86
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::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::Vector< scalar >
Foam::filteredLinear3VLimiter
Class to generate weighting factors for the filteredLinear3V differencing scheme.
Definition: filteredLinear3V.H:59
vector.H
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473