limitedCubic.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  Copyright (C) 2026 Keysight Technologies
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::limitedCubicLimiter
29 
30 Group
31  grpFvLimitedSurfaceInterpolationSchemes
32 
33 Description
34  Class with limiter function which returns the limiter for the
35  TVD limited centred-cubic differencing scheme based on r obtained from
36  the LimiterFunc class.
37 
38  Used in conjunction with the template class LimitedScheme.
39 
40 SourceFiles
41  limitedCubic.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef limitedCubic_H
46 #define limitedCubic_H
47 
48 #include "vector.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class limitedCubicLimiter Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class LimiterFunc>
61 :
62  public LimiterFunc
63 {
64  scalar k_;
65  scalar twoByk_;
66 
67 public:
68 
70  :
71  k_(readScalar(is))
72  {
73  if (k_ < 0 || k_ > 1)
74  {
76  << "coefficient = " << k_
77  << " should be >= 0 and <= 1"
78  << exit(FatalIOError);
79  }
80 
81  // Avoid the /0 when k_ = 0
82  twoByk_ = 2.0/max(k_, SMALL);
83  }
84 
85  scalar limiter
86  (
87  const scalar cdWeight,
88  const scalar faceFlux,
89  const typename LimiterFunc::phiType& phiP,
90  const typename LimiterFunc::phiType& phiN,
91  const typename LimiterFunc::gradPhiType& gradcP,
92  const typename LimiterFunc::gradPhiType& gradcN,
93  const vector& d
94  ) const
95  {
96  scalar twor = twoByk_*LimiterFunc::r
97  (
98  faceFlux, phiP, phiN, gradcP, gradcN, d
99  );
100 
101  scalar phiU;
102 
103  if (faceFlux > 0)
104  {
105  phiU = phiP;
106  }
107  else
108  {
109  phiU = phiN;
110  }
111 
112  // Calculate the face value using cubic interpolation
113  scalar phif =
114  cdWeight*phiP
115  + (1 - cdWeight)*phiN
116  + cdWeight*(1 - cdWeight)
117  *(
118  (1 - 2*cdWeight)*(phiN - phiP)
119  + cdWeight*(d & gradcP)
120  - (1 - cdWeight)*(d & gradcN)
121  );
122 
123  scalar phiCD = cdWeight*phiP + (1 - cdWeight)*phiN;
124 
125  // Calculate the effective limiter for the cubic interpolation
126  scalar cubicLimiter = (phif - phiU)/stabilise(phiCD - phiU, SMALL);
127 
128  /*
129  if (twor < 0.05)
130  {
131  cubicLimiter = twor;
132  }
133 
134  return clamp(cubicLimiter, 0, 2);
135  */
136 
137  // Limit the limiter to obey the TVD constraint
138  return clamp(min(twor, cubicLimiter), 0, 2);
139  }
140 };
141 
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 } // End namespace Foam
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 #endif
150 
151 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
dimensionedScalar stabilise(const dimensionedScalar &x, const dimensionedScalar &y)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Class with limiter function which returns the limiter for the TVD limited centred-cubic differencing ...
Definition: limitedCubic.H:55
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:681
limitedCubicLimiter(Istream &is)
Definition: limitedCubic.H:64
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: limitedCubic.H:81
Namespace for OpenFOAM.
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
Definition: dimensionSet.C:271
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...