Line data Source code
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,
30 : CentralDifference,
31 : MinMod,
32 : SOU,
33 : QUICK,
34 : Venkatakrishnan
35 : };
36 : extern const MooseEnum moose_limiter_type;
37 :
38 : template <typename T, typename Enable = void>
39 : struct LimiterValueType;
40 :
41 : template <>
42 : struct LimiterValueType<Real>
43 : {
44 : typedef Real value_type;
45 : };
46 : template <>
47 : struct LimiterValueType<ADReal>
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 :
57 : /**
58 : * Base class for defining slope limiters for finite volume or potentially reconstructed
59 : * Discontinuous-Galerkin applications
60 : */
61 : template <typename T>
62 : class Limiter
63 : {
64 : public:
65 : /**
66 : * This method computes the flux limiting ratio based on the provided scalar values,
67 : * gradient vectors, direction vector, maximum and minimum allowable values, and
68 : * geometric information from the face and cell centroids. It must be overridden
69 : * by any derived class implementing a specific limiting strategy.
70 : *
71 : * @tparam T The data type of the field values and the return type.
72 : * @param phi_upwind The field value at the upwind location.
73 : * @param phi_downwind The field value at the downwind location.
74 : * @param grad_phi_upwind Pointer to the gradient of the field at the upwind location.
75 : * @param grad_phi_downwind Pointer to the gradient of the field at the downwind location.
76 : * @param dCD A constant direction vector representing the direction of the cell face.
77 : * @param max_value The maximum allowable value.
78 : * @param min_value The minimum allowable value.
79 : * @param fi FaceInfo object containing geometric details such as face centroid and cell
80 : * centroids.
81 : * @param fi_elem_is_upwind Boolean indicating if the face info element is upwind.
82 : * @return The computed flux limiting ratio.
83 : *
84 : * This pure virtual function is intended to be defined in derived classes, which will implement
85 : * the specific limiting algorithm. Derived classes will provide the actual logic for computing
86 : * the flux limiting ratio, ensuring that the result adheres to the constraints and properties
87 : * required by the specific limiting method.
88 : */
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 :
101 : /**
102 : * @tparam T The data type of the field values and the return type.
103 : * @param phi_upwind The field value at the upwind location.
104 : * @param phi_downwind The field value at the downwind location.
105 : * @param grad_phi_upwind Pointer to the gradient of the field value at the upwind location.
106 : * @param dCD A constant direction vector representing the direction of the cell face.
107 : * @return The computed limited value, ensuring it is within the range [0, 2].
108 : */
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 :
127 : /**
128 : * @tparam T The data type of the field values and the return type.
129 : * @param phi_upwind The field value at the upwind location.
130 : * @param phi_downwind The field value at the downwind location.
131 : * @param grad_phi_upwind Pointer to the gradient at the upwind location.
132 : * @param grad_phi_downwind Pointer to the gradient at the downwind location.
133 : * @param dCD A constant direction vector representing the direction of the cell face.
134 : * @param max_value The maximum allowable value.
135 : * @param min_value The minimum allowable value.
136 : * @param fi FaceInfo object containing geometric details such as face centroid and cell
137 : * centroids.
138 : * @param fi_elem_is_upwind Boolean indicating if the face info element is upwind.
139 : * @return The result of the `limit` function applied to the provided parameters.
140 : */
141 11146539 : 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 11146539 : 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 11146539 : fi_elem_is_upwind);
160 : }
161 :
162 : /**
163 : * @tparam T The data type of the gradient values and the return type.
164 : * @param grad_phi_upwind Pointer to the gradient at the upwind location.
165 : * @param grad_phi_downwind Pointer to the gradient at the downwind location.
166 : * @param dCD A constant direction vector representing the direction of the cell face.
167 : * @return The computed flux limiting ratio.
168 : */
169 2141594 : T rf_grad(const VectorValue<T> * grad_phi_upwind,
170 : const VectorValue<T> * grad_phi_downwind,
171 : const RealVectorValue & dCD) const
172 : {
173 2141594 : const auto grad_elem = (*grad_phi_upwind) * dCD;
174 2141594 : const auto grad_face = (*grad_phi_downwind) * dCD;
175 2141594 : const auto grad_ratio = grad_elem / (grad_face + 1e-10);
176 4283188 : return std::max(2.0 * grad_ratio - 1.0, 0.0);
177 2141594 : };
178 :
179 : /**
180 : * @tparam T The data type of the field values and the return type.
181 : * @param phi_upwind The field value at the upwind location.
182 : * @param grad_phi_upwind Pointer to the gradient at the upwind location.
183 : * @param max_value The maximum allowable value.
184 : * @param min_value The minimum allowable value.
185 : * @param fi FaceInfo object containing geometric details such as face centroid and cell
186 : * centroids.
187 : * @param fi_elem_is_upwind Boolean indicating if the face info element is upwind.
188 : * @return The computed flux limiting ratio.
189 : */
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 5575531 : Limiter() = default;
208 :
209 5575532 : virtual ~Limiter() = default;
210 :
211 : static std::unique_ptr<Limiter> build(LimiterType limiter);
212 : };
213 :
214 : /**
215 : * Return the limiter type associated with the supplied interpolation method
216 : */
217 : LimiterType limiterType(InterpMethod interp_method);
218 : }
219 : }
|