Gamma.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) 2016-2017 Wikki Ltd
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::GammaWeight
28 
29 Description
30  Class with operator() which returns the weighting factors for the
31  Gamma differencing scheme. Used in conjunction with the template class
32  NVDscheme.
33 
34 SourceFiles
35  GammaMake.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Gamma_H
40 #define Gamma_H
41 
42 #include "scalar.H"
43 #include "vector.H"
44 #include "Istream.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class GammaWeight Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class GammaWeight
56 {
57  scalar k_;
58 
59 public:
60 
61  GammaWeight(Istream& is)
62  :
63  k_(readScalar(is))
64  {
65  if (k_ < 0 || k_ > 1)
66  {
68  << "coefficient = " << k_
69  << " should be >= 0 and <= 1"
70  << exit(FatalIOError);
71  }
72 
73  // Rescale k_ to be >= 0 and <= 0.5 (TVD conformant)
74  // and avoid the /0 when k_ = 0
75  k_ = max(k_/2.0, SMALL);
76  }
77 
78 
79  scalar weight
80  (
81  scalar cdWeight,
82  scalar faceFlux,
83  scalar phiP,
84  scalar phiN,
85  const vector& gradcP,
86  const vector& gradcN,
87  const vector& d
88  ) const
89  {
90  scalar magd = mag(d);
91  vector dHat = d/mag(d);
92 
93  scalar gradf = (phiN - phiP)/magd;
94 
95  scalar gradcf;
96  scalar udWeight;
97 
98  if (faceFlux > 0)
99  {
100  gradcf = dHat & gradcP;
101  udWeight = 1;
102  }
103  else
104  {
105  gradcf = dHat & gradcN;
106  udWeight = 0;
107  }
108 
109  // Stabilise for division
110  gradcf = stabilise(gradcf, SMALL);
111 
112  scalar phict = 1 - 0.5*gradf/gradcf;
113  scalar limiter = min(max(phict/k_, 0), 1);
114 
115  return limiter*cdWeight + (1 - limiter)*udWeight;
116  }
117 };
118 
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 } // End namespace Foam
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 #endif
127 
128 // ************************************************************************* //
Foam::GammaWeight
Class with operator() which returns the weighting factors for the Gamma differencing scheme....
Definition: Gamma.H:54
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::stabilise
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
Definition: DimensionedScalarField.C:43
Istream.H
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
scalar.H
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::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::GammaWeight::weight
scalar weight(scalar cdWeight, scalar faceFlux, scalar phiP, scalar phiN, const vector &gradcP, const vector &gradcN, const vector &d) const
Definition: Gamma.H:79
vector.H
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::limiter
tmp< areaScalarField > limiter(const areaScalarField &phi)
Definition: faNVDscheme.C:37
Foam::GammaWeight::GammaWeight
GammaWeight(Istream &is)
Definition: Gamma.H:60