Skip to content

Commit

Permalink
Apply suggestions from code review peter Refs #28891
Browse files Browse the repository at this point in the history
Co-authored-by: Peter German <[email protected]>
  • Loading branch information
tanoret and grmnptr committed Nov 13, 2024
1 parent e028edb commit 8bb6863
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 384 deletions.
7 changes: 3 additions & 4 deletions framework/doc/content/syntax/Limiters/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TVD, and what the functional form of the flux limiting function $\beta(r)$ is.
| `SOU` | 2 | No | $r$ |
| `QUICK` | 2 | No | $\frac{3+r}{4}$ |

## Limiting Process for Incompressible and Weakly-Compressible flow Flow
## Limiting Process for Incompressible and Weakly-Compressible flow

A full second-order upwind reconstruction is used for incompressible and weakly-compressible solvers. In this reconstruction, the limited quantity at the face is expressed as follows:

Expand All @@ -112,7 +112,7 @@ where:

Two kinds of limiters are supported: slope-limited and face-value limited. These limiters are defined below.

For slope-limiting, the limiting function $r$ is defined as follows:
For slope-limiting, the approximate gradient ratio (or flux limiting ratio) $r$ is defined as follows:

\begin{equation}
r = 2 \frac{\bm{d}_{NC} \cdot (\nabla \bm{\Psi})_C}{\bm{d}_{NC} \cdot (\nabla \bm{\Psi})_f} - 1
Expand Down Expand Up @@ -153,8 +153,7 @@ Each of the limiters implemented along with the implementation reference, limiti
| `Venkatakrishnan` [!citep](venkatakrishnan1993) | Face-Value | No | $\frac{2r+1}{r(2r+1)+1}$ |


To illustrate the performance of the limiters, a dispersion analysis is developed.
The problem is illustrated in [dispersion].
To illustrate the performance of the limiters, a dispersion analysis is developedand presented in [dispersion].
This consists of the advection of a passive scalar in a Cartesian mesh at 45 degrees.
The exact solution, without numerical diffusion, is a straight line at 45 degrees
dividing the regions with a scalar concentration of 1 and 0.
Expand Down
159 changes: 19 additions & 140 deletions framework/include/limiters/Limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,16 @@ class Limiter
{
public:
/**
* @brief Pure virtual method for computing the flux limiting ratio.
*
* This method computes the flux limiting ratio based on the provided scalar values,
* gradient vectors, direction vector, maximum and minimum allowable values, and
* geometric information from the face and cell centroids. It must be overridden
* by any derived class implementing a specific limiting strategy.
*
* @tparam T The data type of the scalar values and the return type.
* @param phi_upwind The scalar value at the upwind location.
* @param phi_downwind The scalar value at the downwind location.
* @param grad_phi_upwind Pointer to the gradient vector at the upwind location.
* @param grad_phi_downwind Pointer to the gradient vector at the downwind location.
* @tparam T The data type of the field values and the return type.
* @param phi_upwind The field value at the upwind location.
* @param phi_downwind The field value at the downwind location.
* @param grad_phi_upwind Pointer to the gradient of the field at the upwind location.
* @param grad_phi_downwind Pointer to the gradient of the field at the downwind location.
* @param dCD A constant direction vector representing the direction of the cell face.
* @param max_value The maximum allowable value.
* @param min_value The minimum allowable value.
Expand All @@ -87,30 +85,6 @@ class Limiter
* the specific limiting algorithm. Derived classes will provide the actual logic for computing
* the flux limiting ratio, ensuring that the result adheres to the constraints and properties
* required by the specific limiting method.
*
* Here is an example of how a derived class might implement this method:
*
* @example
* @code
* class MyLimiter : public Limiter<Real>
* {
* public:
* Real limit(const Real & phi_upwind,
* const Real & phi_downwind,
* const VectorValue<Real> * grad_phi_upwind,
* const VectorValue<Real> * grad_phi_downwind,
* const RealVectorValue & dCD,
* const Real & max_value,
* const Real & min_value,
* const FaceInfo * fi,
* const bool & fi_elem_is_upwind) const override
* {
* // Implementation of the specific limiting algorithm.
* Real ratio = ... // Compute the ratio.
* return ratio; // Return the computed ratio.
* }
* };
* @endcode
*/
virtual T limit(const T & phi_upwind,
const T & phi_downwind,
Expand All @@ -125,35 +99,12 @@ class Limiter
virtual InterpMethod interpMethod() const = 0;

/**
* @brief Functor for applying simplified slope limiting.
*
* This function applies the limiter by invoking the `limit` method with the provided parameters.
* It acts as a functor, enabling objects of the derived `Limiter` class to be used as if they
* were functions.
*
* @tparam T The data type of the scalar values and the return type.
* @param phi_upwind The scalar value at the upwind location.
* @param phi_downwind The scalar value at the downwind location.
* @param grad_phi_upwind Pointer to the gradient vector at the upwind location.
* @tparam T The data type of the field values and the return type.
* @param phi_upwind The field value at the upwind location.
* @param phi_downwind The field value at the downwind location.
* @param grad_phi_upwind Pointer to the gradient of the field value at the upwind location.
* @param dCD A constant direction vector representing the direction of the cell face.
* @return The computed limited value, ensuring it is within the range [0, 2].
*
* This method performs the following steps:
* 1. Calls the `limit` method with the provided scalar values, the upwind gradient vector, and
* the direction vector.
* 2. Ensures the result is within the range [0, 2] by using `std::max` and `std::min`.
* 3. Returns the computed limited value.
*
* @example
* @code
* Limiter<Real> * myLimiter = ... // Assume this is properly initialized
* Real phi_upwind = 2.0;
* Real phi_downwind = 1.5;
* VectorValue<Real> grad_upwind(0.1, 0.2, 0.3);
* RealVectorValue dCD(1.0, 0.0, 0.0);
* FaceInfo * fi = ... // Assume this is properly initialized
* Real result = (*myLimiter)(phi_upwind, phi_downwind, &grad_upwind, dCD);
* @endcode
*/
T operator()(const T & phi_upwind,
const T & phi_downwind,
Expand All @@ -174,48 +125,18 @@ class Limiter
}

/**
* @brief Functor for applying general slope limiter.
*
* This function applies the slope limiter by invoking the `limit` method with the provided
* parameters. It acts as a functor, enabling objects of the `Limiter` class to be used as if they
* were functions.
*
* @tparam T The data type of the scalar values and the return type.
* @param phi_upwind The scalar value at the upwind location.
* @param phi_downwind The scalar value at the downwind location.
* @param grad_phi_upwind Pointer to the gradient vector at the upwind location.
* @param grad_phi_downwind Pointer to the gradient vector at the downwind location.
* @tparam T The data type of the field values and the return type.
* @param phi_upwind The field value at the upwind location.
* @param phi_downwind The field value at the downwind location.
* @param grad_phi_upwind Pointer to the gradient at the upwind location.
* @param grad_phi_downwind Pointer to the gradient at the downwind location.
* @param dCD A constant direction vector representing the direction of the cell face.
* @param max_value The maximum allowable value.
* @param min_value The minimum allowable value.
* @param fi FaceInfo object containing geometric details such as face centroid and cell
* centroids.
* @param fi_elem_is_upwind Boolean indicating if the face info element is upwind.
* @return The result of the `limit` function applied to the provided parameters.
*
* This function performs the following steps:
* 1. Calls the `limit` method with the provided scalar values, gradient vectors, direction
* vector, maximum and minimum values, face information, and upwind status.
* 2. Returns the result of the `limit` method.
*
* This functor allows for more intuitive and flexible usage of the `Limiter` class, enabling
* instances of the class to be called with arguments directly.
*
* @example
* @code
* Limiter<Real> * myLimiter = ... // Assume this is properly initialized
* Real phi_upwind = 2.0;
* Real phi_downwind = 1.5;
* VectorValue<Real> grad_upwind(0.1, 0.2, 0.3);
* VectorValue<Real> grad_downwind(0.4, 0.5, 0.6);
* RealVectorValue dCD(1.0, 0.0, 0.0);
* Real max_value = 5.0;
* Real min_value = 1.0;
* FaceInfo * fi = ... // Assume this is properly initialized
* bool is_upwind = true;
* Real result = (*myLimiter)(phi_upwind, phi_downwind, &grad_upwind, &grad_downwind, dCD,
* max_value, min_value, fi, is_upwind);
* @endcode
*/
T operator()(const T & phi_upwind,
const T & phi_downwind,
Expand All @@ -239,34 +160,11 @@ class Limiter
}

/**
* @brief Computes the flux limiting ratio using gradients.
* This method works well for incompressible and compressible flow.
*
* This function calculates the flux limiting ratio based on the provided gradients
* at the upwind and downwind locations, along with a direction vector.
*
* @tparam T The data type of the gradient values and the return type.
* @param grad_phi_upwind Pointer to the gradient vector at the upwind location.
* @param grad_phi_downwind Pointer to the gradient vector at the downwind location.
* @param grad_phi_upwind Pointer to the gradient at the upwind location.
* @param grad_phi_downwind Pointer to the gradient at the downwind location.
* @param dCD A constant direction vector representing the direction of the cell face.
* @return The computed flux limiting ratio.
*
* This function performs the following steps:
* 1. Computes the dot product of the upwind gradient vector with the direction vector `dCD`.
* 2. Computes the dot product of the downwind gradient vector with the direction vector `dCD`.
* 3. Calculates the ratio of the upwind gradient dot product to the downwind gradient dot
* product, adding a small epsilon value to the denominator to prevent division by zero.
*
* @note The small epsilon value `1e-10` is added to the denominator to avoid division by zero
* and numerical instability.
*
* @example
* @code
* VectorValue<Real> grad_upwind(0.1, 0.2, 0.3);
* VectorValue<Real> grad_downwind(0.4, 0.5, 0.6);
* RealVectorValue dCD(1.0, 0.0, 0.0);
* Real ratio = rf_grad(&grad_upwind, &grad_downwind, dCD);
* @endcode
*/
T rf_grad(const VectorValue<T> * grad_phi_upwind,
const VectorValue<T> * grad_phi_downwind,
Expand All @@ -279,34 +177,15 @@ class Limiter
};

/**
* @brief Computes the flux limiting ratio using successive deltas.
*
* This function calculates the flux limiting ratio based on the upwind value,
* its gradient, maximum and minimum allowable values, and geometric information
* from the face and cell centroids.
*
* @tparam T The data type of the scalar values and the return type.
* @param phi_upwind The scalar value at the upwind location.
* @param grad_phi_upwind Pointer to the gradient vector at the upwind location.
* @tparam T The data type of the field values and the return type.
* @param phi_upwind The field value at the upwind location.
* @param grad_phi_upwind Pointer to the gradient at the upwind location.
* @param max_value The maximum allowable value.
* @param min_value The minimum allowable value.
* @param fi FaceInfo object containing geometric details such as face centroid and cell
* centroids.
* @param fi_elem_is_upwind Boolean indicating if the face info element is upwind.
* @return The computed flux limiting ratio.
*
* This function performs the following steps:
* 1. Retrieves the face centroid from the `FaceInfo` object.
* 2. Determines the cell centroid based on whether the current element is upwind.
* 3. Computes the delta value at the face by taking the dot product of the upwind gradient
* vector with the difference between the face and cell centroids.
* 4. Computes the delta values for the maximum and minimum allowable values, adding a small
* epsilon value to prevent division by zero.
* 5. Calculates the flux limiting ratio based on whether the delta value at the face is
* non-negative or negative, using the appropriate delta (either max or min).
*
* @note The small epsilon value `1e-10` is added to the delta max and delta min values to
* avoid division by zero and numerical instability.
*/
T rf_minmax(const T & phi_upwind,
const VectorValue<T> * grad_phi_upwind,
Expand Down
27 changes: 1 addition & 26 deletions framework/include/limiters/MinModLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ namespace Moose
namespace FV
{
/**
* @brief Implements the Min-Mod limiter for flux limiting in numerical methods.
*
* The Min-Mod limiter is used to reduce numerical oscillations and
* enforce monotonicity in computational fluid dynamics (CFD) and other numerical simulations.
* The limiter function $\beta(r_f)$ is defined as:
* The Min-Mod limiter function $\beta(r_f)$ is defined as:
*
* \f[
* \beta(r_f) = \text{max}(0, \text{min}(1, r_f))
Expand All @@ -36,31 +32,13 @@ class MinModLimiter : public Limiter<T>
{
public:
/**
* @brief Computes the limited value using the Min-Mod limiter.
*
* This method overrides the pure virtual `limit` method in the base `Limiter` class.
* It calculates the flux limiting ratio based on the Min-Mod limiter formula.
*
* @param grad_phi_upwind Pointer to the gradient vector at the upwind location.
* @param grad_phi_downwind Pointer to the gradient vector at the downwind location.
* @param dCD A constant direction vector representing the direction of the cell face.
* @return The computed flux limiting ratio.
*
* This method performs the following steps:
* 1. Asserts that the upwind gradient pointer is not null.
* 2. Computes the gradient ratio coefficient \( r_f \) using the `rf_grad` method.
* 3. Applies the Min-Mod limiter formula to \( r_f \) to obtain the limited value.
* 4. Returns the computed limited value.
*
* @example
* @code
* MinModLimiter<Real> minMod;
* VectorValue<Real> grad_upwind(0.1, 0.2, 0.3);
* VectorValue<Real> grad_downwind(0.4, 0.5, 0.6);
* RealVectorValue dCD(1.0, 0.0, 0.0);
* Real result = minMod.limit(0.0, 0.0, &grad_upwind, &grad_downwind, dCD, 0.0, 0.0, nullptr,
* true);
* @endcode
*/
T limit(const T & phi_upwind,
const T & phi_downwind,
Expand Down Expand Up @@ -89,9 +67,6 @@ class MinModLimiter : public Limiter<T>

InterpMethod interpMethod() const override final { return InterpMethod::MinMod; }

/**
* @brief Default constructor for the Min-Mod limiter.
*/
MinModLimiter() = default;
};
}
Expand Down
31 changes: 2 additions & 29 deletions framework/include/limiters/QUICKLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ namespace Moose
namespace FV
{
/**
* @brief Implements the QUICK limiter for flux limiting in numerical methods.
*
* The QUICK (Quadratic Upstream Interpolation for Convective Kinematics) limiter is used to reduce
* numerical oscillations and enforce monotonicity in computational fluid dynamics (CFD) and other
* numerical simulations. This limiter ensures Total Variation Diminishing (TVD) compliance.
*
* The limiter function is derived from the following equations:
* The QUICK (Quadratic Upstream Interpolation for Convective Kinematics) limiter
* function is derived from the following equations:
*
* 1. Calculation of the gradient ratio coefficient \( r_f \):
* \f[
Expand All @@ -45,8 +40,6 @@ class QUICKLimiter : public Limiter<T>
{
public:
/**
* @brief Computes the limited value using the QUICK limiter.
*
* This method overrides the pure virtual `limit` method in the base `Limiter` class.
* It calculates the flux limiting ratio based on the QUICK limiter formula.
*
Expand All @@ -56,23 +49,6 @@ class QUICKLimiter : public Limiter<T>
* @param grad_phi_downwind Pointer to the gradient vector at the downwind location.
* @param dCD A constant direction vector representing the direction of the cell face.
* @return The computed flux limiting ratio.
*
* This method performs the following steps:
* 1. Asserts that the upwind gradient pointer is not null.
* 2. Computes the gradient ratio coefficient \( r_f \) using the `rf_grad` method or `rF` method.
* 3. Applies the QUICK limiter formula to \( r_f \) to obtain the limited value, ensuring TVD
* compliance.
* 4. Returns the computed limited value.
*
* @example
* @code
* QUICKLimiter<Real> quick;
* VectorValue<Real> grad_upwind(0.1, 0.2, 0.3);
* VectorValue<Real> grad_downwind(0.4, 0.5, 0.6);
* RealVectorValue dCD(1.0, 0.0, 0.0);
* Real result = quick.limit(0.0, 0.0, &grad_upwind, &grad_downwind, dCD, 0.0, 0.0, nullptr,
* true);
* @endcode
*/
T limit(const T & phi_upwind,
const T & phi_downwind,
Expand Down Expand Up @@ -111,9 +87,6 @@ class QUICKLimiter : public Limiter<T>

InterpMethod interpMethod() const override final { return InterpMethod::QUICK; }

/**
* @brief Default constructor for the QUICK limiter.
*/
QUICKLimiter() = default;
};
}
Expand Down
Loading

0 comments on commit 8bb6863

Please sign in to comment.