Skip to content

In advection minmod_S_vNeg() almost always returns 0 #109

Description

@lrobion

In AdvDiffSystem::forwardEulerAdvection the advection is computed as second order upwind that regresses to first order based on the minmod flux limiter value.

The fast minmod_S_vNeg implementation is incorrect:

inline double minmod_S_vNeg(int pointID) const noexcept{
if(!isValidPointID(pointID - 1) || neighbor_point(FaceDirection::NORTH, pointID)) return 0;
double phi_P = phi_[pointID];
double phi_S = phi_[pointID - 1];
double phi_N = phi_[neighbor_point(FaceDirection::NORTH, pointID)];
double r = (phi_P - phi_S == 0) ? 0 : (phi_N - phi_P) / (phi_P - phi_S);
return std::max(0.0, std::min(r, 1.0));
}

It should instead be:

inline double minmod_S_vNeg(int pointID) const noexcept{
    if(!isValidPointID(pointID - 1) || !isValidPointID(pointID + 1)) return 0;
    double phi_P = phi_[pointID];
    double phi_S = phi_[pointID - 1];
    double phi_N = phi_[pointID + 1]; // this line was correct but slower than this (all the other functions do this too)
    double r = (phi_P - phi_S == 0) ? 0 : (phi_N - phi_P) / (phi_P - phi_S);
    return std::max(0.0, std::min(r, 1.0));

This is probably a leftover from the copy pasting of the more general function which used neighbor_point. The if check is incorrect because neighbor_point returns an index which is rarely 0 -> if check is true ->function almost always returned 0. This meant the advection scheme for all advection on the southern face of a cell with a negative velocity (most common case given that ice crystals settle) regressed to first order advection instead of second due to the bug in minmod.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions