https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Limiter.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "ADReal.h"
13#include "MooseTypes.h"
14#include "HasMembers.h"
15#include "FaceInfo.h"
16#include <memory>
17
18class MooseEnum;
19
20namespace Moose
21{
22namespace FV
23{
24enum class InterpMethod;
25
26enum class LimiterType : int
27{
28 VanLeer = 0,
29 Upwind,
31 MinMod,
32 SOU,
33 QUICK,
35};
36extern const MooseEnum moose_limiter_type;
37
38template <typename T, typename Enable = void>
40
41template <>
42struct LimiterValueType<Real>
43{
44 typedef Real value_type;
45};
46template <>
48{
50};
51template <typename T>
52struct LimiterValueType<T, typename std::enable_if<HasMemberType_value_type<T>::value>::type>
53{
54 typedef typename T::value_type value_type;
55};
56
61template <typename T>
63{
64public:
89 virtual T limit(const T & phi_upwind,
90 const T & phi_downwind,
91 const libMesh::VectorValue<T> * grad_phi_upwind,
92 const libMesh::VectorValue<T> * grad_phi_downwind,
93 const RealVectorValue & dCD,
94 const Real & max_value,
95 const Real & min_value,
96 const FaceInfo * fi,
97 const bool & fi_elem_is_upwind) const = 0;
98 virtual bool constant() const = 0;
99 virtual InterpMethod interpMethod() const = 0;
100
109 T operator()(const T & phi_upwind,
110 const T & phi_downwind,
111 const libMesh::VectorValue<T> * grad_phi_upwind,
112 const RealVectorValue & dCD) const
113 {
114 return std::max(T(0),
115 std::min(T(2),
116 limit(phi_upwind,
117 phi_downwind,
118 grad_phi_upwind,
119 nullptr,
120 dCD,
121 T(0),
122 T(0),
123 nullptr,
124 false)));
125 }
126
141 T operator()(const T & phi_upwind,
142 const T & phi_downwind,
143 const VectorValue<T> * grad_phi_upwind,
144 const VectorValue<T> * grad_phi_downwind,
145 const RealVectorValue & dCD,
146 const Real & max_value,
147 const Real & min_value,
148 const FaceInfo * fi,
149 const bool & fi_elem_is_upwind) const
150 {
151 return limit(phi_upwind,
152 phi_downwind,
153 grad_phi_upwind,
154 grad_phi_downwind,
155 dCD,
156 max_value,
157 min_value,
158 fi,
159 fi_elem_is_upwind);
160 }
161
169 T rf_grad(const VectorValue<T> * grad_phi_upwind,
170 const VectorValue<T> * grad_phi_downwind,
171 const RealVectorValue & dCD) const
172 {
173 using std::max;
174 const auto grad_elem = (*grad_phi_upwind) * dCD;
175 const auto grad_face = (*grad_phi_downwind) * dCD;
176 const auto grad_ratio = grad_elem / (grad_face + 1e-10);
177 return max(2.0 * grad_ratio - 1.0, 0.0);
178 };
179
191 T rf_minmax(const T & phi_upwind,
192 const VectorValue<T> * grad_phi_upwind,
193 const Real & max_value,
194 const Real & min_value,
195 const FaceInfo * fi,
196 const bool & fi_elem_is_upwind) const
197 {
198 const auto face_centroid = fi->faceCentroid();
199 const auto cell_centroid = fi_elem_is_upwind ? fi->elemCentroid() : fi->neighborCentroid();
200
201 const auto delta_face = (*grad_phi_upwind) * (face_centroid - cell_centroid);
202 const auto delta_max = max_value - phi_upwind + 1e-10;
203 const auto delta_min = min_value - phi_upwind + 1e-10;
204
205 return delta_face >= 0 ? delta_face / delta_max : delta_face / delta_min;
206 };
207
208 Limiter() = default;
209
210 virtual ~Limiter() = default;
211
212 static std::unique_ptr<Limiter> build(LimiterType limiter);
213};
214
219}
220}
DualNumber< Real, DNDerivativeType, true > ADReal
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
const Point & neighborCentroid() const
Definition FaceInfo.h:247
const Point & elemCentroid() const
Returns the element centroids of the elements on the elem and neighbor sides of the face.
Definition FaceInfo.h:99
const Point & faceCentroid() const
Returns the coordinates of the face centroid.
Definition FaceInfo.h:75
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Base class for defining slope limiters for finite volume or potentially reconstructed Discontinuous-G...
Definition Limiter.h:63
T operator()(const T &phi_upwind, const T &phi_downwind, const VectorValue< T > *grad_phi_upwind, const VectorValue< T > *grad_phi_downwind, const RealVectorValue &dCD, const Real &max_value, const Real &min_value, const FaceInfo *fi, const bool &fi_elem_is_upwind) const
Definition Limiter.h:141
T operator()(const T &phi_upwind, const T &phi_downwind, const libMesh::VectorValue< T > *grad_phi_upwind, const RealVectorValue &dCD) const
Definition Limiter.h:109
static std::unique_ptr< Limiter > build(LimiterType limiter)
Definition Limiter.C:32
virtual ~Limiter()=default
virtual bool constant() const =0
T rf_grad(const VectorValue< T > *grad_phi_upwind, const VectorValue< T > *grad_phi_downwind, const RealVectorValue &dCD) const
Definition Limiter.h:169
virtual InterpMethod interpMethod() const =0
T rf_minmax(const T &phi_upwind, const VectorValue< T > *grad_phi_upwind, const Real &max_value, const Real &min_value, const FaceInfo *fi, const bool &fi_elem_is_upwind) const
Definition Limiter.h:191
virtual T limit(const T &phi_upwind, const T &phi_downwind, const libMesh::VectorValue< T > *grad_phi_upwind, const libMesh::VectorValue< T > *grad_phi_downwind, const RealVectorValue &dCD, const Real &max_value, const Real &min_value, const FaceInfo *fi, const bool &fi_elem_is_upwind) const =0
This method computes the flux limiting ratio based on the provided scalar values, gradient vectors,...
LimiterType limiterType(InterpMethod interp_method)
Return the limiter type associated with the supplied interpolation method.
Definition Limiter.C:63
const MooseEnum moose_limiter_type
@ Venkatakrishnan
Venkatakrishnan limiter (smooth, multidimensional).
InterpMethod
This codifies a set of available ways to interpolate with elem+neighbor solution information to calcu...
Definition MathFVUtils.h:39
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...