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