https://mooseframework.inl.gov
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 
18 class MooseEnum;
19 
20 namespace Moose
21 {
22 namespace FV
23 {
24 enum class InterpMethod;
25 
26 enum class LimiterType : int
27 {
28  VanLeer = 0,
29  Upwind,
31  MinMod,
32  SOU,
33  QUICK,
35 };
36 extern const MooseEnum moose_limiter_type;
37 
38 template <typename T, typename Enable = void>
40 
41 template <>
43 {
44  typedef Real value_type;
45 };
46 template <>
48 {
49  typedef ADReal value_type;
50 };
51 template <typename T>
52 struct LimiterValueType<T, typename std::enable_if<HasMemberType_value_type<T>::value>::type>
53 {
54  typedef typename T::value_type value_type;
55 };
56 
61 template <typename T>
62 class Limiter
63 {
64 public:
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  const auto grad_elem = (*grad_phi_upwind) * dCD;
174  const auto grad_face = (*grad_phi_downwind) * dCD;
175  const auto grad_ratio = grad_elem / (grad_face + 1e-10);
176  return std::max(2.0 * grad_ratio - 1.0, 0.0);
177  };
178 
190  T rf_minmax(const T & phi_upwind,
191  const VectorValue<T> * grad_phi_upwind,
192  const Real & max_value,
193  const Real & min_value,
194  const FaceInfo * fi,
195  const bool & fi_elem_is_upwind) const
196  {
197  const auto face_centroid = fi->faceCentroid();
198  const auto cell_centroid = fi_elem_is_upwind ? fi->elemCentroid() : fi->neighborCentroid();
199 
200  const auto delta_face = (*grad_phi_upwind) * (face_centroid - cell_centroid);
201  const auto delta_max = max_value - phi_upwind + 1e-10;
202  const auto delta_min = min_value - phi_upwind + 1e-10;
203 
204  return delta_face >= 0 ? delta_face / delta_max : delta_face / delta_min;
205  };
206 
207  Limiter() = default;
208 
209  virtual ~Limiter() = default;
210 
211  static std::unique_ptr<Limiter> build(LimiterType limiter);
212 };
213 
217 LimiterType limiterType(InterpMethod interp_method);
218 }
219 }
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...
Base class for defining slope limiters for finite volume or potentially reconstructed Discontinuous-G...
Definition: Limiter.h:62
virtual ~Limiter()=default
const Point & faceCentroid() const
Returns the coordinates of the face centroid.
Definition: FaceInfo.h:71
const Point & neighborCentroid() const
Definition: FaceInfo.h:243
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:47
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:190
auto max(const L &left, const R &right)
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:36
LimiterType limiterType(InterpMethod interp_method)
Return the limiter type associated with the supplied interpolation method.
Definition: Limiter.C:63
virtual bool constant() const =0
const Point & elemCentroid() const
Returns the element centroids of the elements on the elem and neighbor sides of the face...
Definition: FaceInfo.h:95
const MooseEnum moose_limiter_type
LimiterType
Definition: Limiter.h:26
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
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
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
InterpMethod
This codifies a set of available ways to interpolate with elem+neighbor solution information to calcu...
Definition: MathFVUtils.h:35
auto min(const L &left, const R &right)
static std::unique_ptr< Limiter > build(LimiterType limiter)
Definition: Limiter.C:32
void ErrorVector unsigned int
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