18 #include "libmesh/elem.h" 19 #include "libmesh/vector_value.h" 20 #include "libmesh/point.h" 66 std::vector<Point> & x_neighbor)
const;
89 std::vector<GenericReal<is_ad>>
94 std::vector<Point> x_neighbor,
108 std::vector<GenericReal<is_ad>>
110 const Point & x_elem,
113 const std::vector<Point> & x_neighbor)
const;
122 virtual std::vector<GenericReal<is_ad>>
145 stringToEnum<SlopeReconstruction1DInterface<true>::ESlopeReconstructionType>(
const std::string & s);
149 stringToEnum<SlopeReconstruction1DInterface<false>::ESlopeReconstructionType>(
150 const std::string & s);
153 template <
bool is_ad>
154 const std::map<std::string,
157 {
"NONE",
None}, {
"FULL", Full}, {
"MINMOD", Minmod}, {
"MC", MC}, {
"SUPERBEE", Superbee}};
159 template <
bool is_ad>
163 return THM::getMooseEnum<SlopeReconstruction1DInterface<is_ad>::ESlopeReconstructionType>(
164 name, _slope_reconstruction_type_to_enum);
167 template <
bool is_ad>
170 template <
bool is_ad>
173 template <
bool is_ad>
182 "Slope reconstruction scheme");
187 template <
bool is_ad>
190 : _moose_object(moose_object),
196 template <
bool is_ad>
201 std::vector<Point> & x_neighbor)
const 205 for (
unsigned int i_side = 0; i_side < _n_side; i_side++)
207 auto neighbor = elem->neighbor_ptr(i_side);
208 if (neighbor && (neighbor->processor_id() == _moose_object->processor_id()))
210 x_neighbor.push_back(neighbor->vertex_average());
211 W_neighbor.push_back(computeElementPrimitiveVariables(neighbor));
216 template <
bool is_ad>
217 std::vector<GenericReal<is_ad>>
220 mooseAssert(elem,
"The supplied element is a nullptr.");
222 const auto W_elem = computeElementPrimitiveVariables(elem);
223 const Point x_elem = elem->vertex_average();
224 const RealVectorValue dir = (elem->node_ref(1) - elem->node_ref(0)).unit();
226 std::vector<Point> x_neighbor;
227 std::vector<std::vector<GenericReal<is_ad>>> W_neighbor;
228 getNeighborPrimitiveVariables(elem, W_neighbor, x_neighbor);
230 return getElementSlopes(W_elem, x_elem, dir, W_neighbor, x_neighbor);
233 template <
bool is_ad>
234 std::vector<GenericReal<is_ad>>
237 const Point & x_elem,
240 std::vector<Point> x_neighbor,
243 if (W_neighbor.size() == 1)
245 W_neighbor.push_back(W_boundary);
248 const Point dx = x_elem - x_neighbor[0];
249 const Point x_boundary = x_elem + dx;
250 x_neighbor.push_back(x_boundary);
253 return getElementSlopes(W_elem, x_elem, dir, W_neighbor, x_neighbor);
256 template <
bool is_ad>
257 std::vector<GenericReal<is_ad>>
260 const Point & x_elem,
263 const std::vector<Point> & x_neighbor)
const 265 mooseAssert(x_neighbor.size() == W_neighbor.size(),
266 "Neighbor positions size must equal neighbor solutions size.");
269 const unsigned int n_slopes = W_elem.size();
272 std::vector<std::vector<GenericReal<is_ad>>> slopes_one_sided;
273 for (
unsigned int i = 0; i < W_neighbor.size(); i++)
275 const Real dx = (x_elem - x_neighbor[i]) * dir;
277 std::vector<GenericReal<is_ad>> slopes(n_slopes, 0.0);
278 for (
unsigned int m = 0; m < n_slopes; m++)
279 slopes[m] = (W_elem[m] - W_neighbor[i][m]) / dx;
281 slopes_one_sided.push_back(slopes);
285 std::vector<GenericReal<is_ad>> slopes_central(n_slopes, 0.0);
286 if (W_neighbor.size() == 2)
288 const Real dx = (x_neighbor[0] - x_neighbor[1]) * dir;
289 for (
unsigned int m = 0; m < n_slopes; m++)
290 slopes_central[m] = (W_neighbor[0][m] - W_neighbor[1][m]) / dx;
292 else if (W_neighbor.size() == 1)
294 slopes_one_sided.push_back(slopes_one_sided[0]);
295 slopes_central = slopes_one_sided[0];
299 slopes_one_sided.push_back(slopes_central);
300 slopes_one_sided.push_back(slopes_central);
304 std::vector<GenericReal<is_ad>> slopes_limited(n_slopes, 0.0);
316 slopes_limited = slopes_central;
322 for (
unsigned int m = 0; m < n_slopes; m++)
324 if ((slopes_one_sided[0][m] * slopes_one_sided[1][m]) > 0.0)
326 if (std::abs(slopes_one_sided[0][m]) < std::abs(slopes_one_sided[1][m]))
327 slopes_limited[m] = slopes_one_sided[0][m];
329 slopes_limited[m] = slopes_one_sided[1][m];
337 for (
unsigned int m = 0; m < n_slopes; m++)
339 if (slopes_central[m] > 0.0 && slopes_one_sided[0][m] > 0.0 && slopes_one_sided[1][m] > 0.0)
340 slopes_limited[m] = std::min(
341 slopes_central[m], 2.0 * std::min(slopes_one_sided[0][m], slopes_one_sided[1][m]));
342 else if (slopes_central[m] < 0.0 && slopes_one_sided[0][m] < 0.0 &&
343 slopes_one_sided[1][m] < 0.0)
344 slopes_limited[m] = std::max(
345 slopes_central[m], 2.0 * std::max(slopes_one_sided[0][m], slopes_one_sided[1][m]));
352 for (
unsigned int m = 0; m < n_slopes; m++)
358 if (slopes_one_sided[1][m] > 0.0 && slopes_one_sided[0][m] > 0.0)
359 slope1 = std::min(slopes_one_sided[1][m], 2.0 * slopes_one_sided[0][m]);
360 else if (slopes_one_sided[1][m] < 0.0 && slopes_one_sided[0][m] < 0.0)
361 slope1 = std::max(slopes_one_sided[1][m], 2.0 * slopes_one_sided[0][m]);
364 if (slopes_one_sided[1][m] > 0.0 && slopes_one_sided[0][m] > 0.0)
365 slope2 = std::min(2.0 * slopes_one_sided[1][m], slopes_one_sided[0][m]);
366 else if (slopes_one_sided[1][m] < 0.0 && slopes_one_sided[0][m] < 0.0)
367 slope2 = std::max(2.0 * slopes_one_sided[1][m], slopes_one_sided[0][m]);
370 if (slope1 > 0.0 && slope2 > 0.0)
371 slopes_limited[m] = std::max(slope1, slope2);
372 else if (slope1 < 0.0 && slope2 < 0.0)
373 slopes_limited[m] = std::min(slope1, slope2);
378 mooseError(
"Unknown slope reconstruction scheme");
381 return slopes_limited;
SlopeReconstruction1DInterface(const MooseObject *moose_object)
Moose::GenericType< Real, is_ad > GenericReal
const MooseObject *const _moose_object
MooseObject this interface is extending.
virtual void getNeighborPrimitiveVariables(const Elem *elem, std::vector< std::vector< GenericReal< is_ad >>> &W_neighbor, std::vector< Point > &x_neighbor) const
Gets the primitive solution vector and position of neighbor(s)
Monotonized Central-Difference slope limiter.
static const unsigned int _n_sten
Number of elemental values in stencil for computing slopes.
void mooseError(Args &&... args)
Full reconstruction; no limitation.
T stringToEnum(const std::string &s)
Converts a string to an enum.
static InputParameters validParams()
static const std::map< std::string, ESlopeReconstructionType > _slope_reconstruction_type_to_enum
Map of slope reconstruction type string to enum.
const ESlopeReconstructionType _scheme
Slope reconstruction scheme.
No reconstruction; Godunov scheme.
std::vector< GenericReal< is_ad > > getBoundaryElementSlopes(const std::vector< GenericReal< is_ad >> &W_elem, const Point &x_elem, const RealVectorValue &dir, std::vector< std::vector< GenericReal< is_ad >>> W_neighbor, std::vector< Point > x_neighbor, const std::vector< GenericReal< is_ad >> &W_boundary) const
Gets limited slopes for the primitive variables in the 1-D direction for boundary element...
static const unsigned int _n_side
Number of sides.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface class for 1-D slope reconstruction.
virtual std::vector< GenericReal< is_ad > > computeElementPrimitiveVariables(const Elem *elem) const =0
Computes the cell-average primitive variable values for an element.
std::vector< GenericReal< is_ad > > getElementSlopes(const Elem *elem) const
Gets limited slopes for the primitive variables in the 1-D direction.
ESlopeReconstructionType
Slope reconstruction type.
const Elem & get(const ElemType type_in)
static MooseEnum getSlopeReconstructionMooseEnum(const std::string &name="")
Gets a MooseEnum for slope reconstruction type.