limitedCubicV.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::limitedCubicVLimiter
28 
29 Description
30  Class with limiter function which returns the limiter for the
31  limitedCubicV differencing scheme based on r obtained from the LimiterFunc
32  class.
33 
34  Used in conjunction with the template class LimitedScheme.
35 
36 SourceFiles
37  limitedCubicV.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef limitedCubicV_H
42 #define limitedCubicV_H
43 
44 #include "vector.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class limitedCubicVLimiter Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 template<class LimiterFunc>
57 :
58  public LimiterFunc
59 {
60  scalar k_;
61  scalar twoByk_;
62 
63 public:
64 
66  :
67  k_(readScalar(is))
68  {
69  if (k_ < 0 || k_ > 1)
70  {
72  << "coefficient = " << k_
73  << " should be >= 0 and <= 1"
74  << exit(FatalIOError);
75  }
76 
77  // Avoid the /0 when k_ = 0
78  twoByk_ = 2.0/max(k_, SMALL);
79  }
80 
81  scalar limiter
82  (
83  const scalar cdWeight,
84  const scalar faceFlux,
85  const typename LimiterFunc::phiType& phiP,
86  const typename LimiterFunc::phiType& phiN,
87  const typename LimiterFunc::gradPhiType& gradcP,
88  const typename LimiterFunc::gradPhiType& gradcN,
89  const vector& d
90  ) const
91  {
92  scalar twor = twoByk_*LimiterFunc::r
93  (
94  faceFlux, phiP, phiN, gradcP, gradcN, d
95  );
96 
97  vector fV = cdWeight*phiP + (1.0 - cdWeight)*phiN;
98 
99  scalar fVphiP = fV & phiP;
100  scalar fVphiN = fV & phiN;
101 
102  scalar fVphiU;
103 
104  if (faceFlux > 0)
105  {
106  fVphiU = fVphiP;
107  }
108  else
109  {
110  fVphiU = fVphiN;
111  }
112 
113  // Calculate the face value using cubic interpolation
114  scalar fVphif =
115  cdWeight*(fVphiP - 0.25*(fV & (d & gradcN)))
116  + (1 - cdWeight)*(fVphiN + 0.25*(fV & (d & gradcP)));
117 
118  scalar fVphiCD = cdWeight*fVphiP + (1 - cdWeight)*fVphiN;
119 
120  // Calculate the effective limiter for the cubic interpolation
121  scalar cubicLimiter =
122  (fVphif - fVphiU)/stabilise(fVphiCD - fVphiU, SMALL);
123 
124  // Limit the limiter to obey the TVD constraint
125  return max(min(min(twor, cubicLimiter), 2), 0);
126  }
127 };
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 } // End namespace Foam
133 
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 
136 #endif
137 
138 // ************************************************************************* //
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
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::limitedCubicVLimiter::limitedCubicVLimiter
limitedCubicVLimiter(Istream &is)
Definition: limitedCubicV.H:64
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::limitedCubicVLimiter
Class with limiter function which returns the limiter for the limitedCubicV differencing scheme based...
Definition: limitedCubicV.H:55
vector.H
Foam::limitedCubicVLimiter::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: limitedCubicV.H:81
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473