Skip to content

Commit

Permalink
Merge symmetric methods into a single one.
Browse files Browse the repository at this point in the history
  • Loading branch information
pvc1989 committed May 24, 2024
1 parent c574750 commit e31c5af
Showing 1 changed file with 30 additions and 37 deletions.
67 changes: 30 additions & 37 deletions include/mini/riemann/euler/ausm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,29 @@ class Ausm {
using Speed = Scalar;
// Get F on T Axia
Flux GetFluxUpwind(const Primitive& left, const Primitive& right) {
Flux flux_positive = GetPositiveFlux(left);
Flux flux_negative = GetNegativeFlux(right);
flux_positive += flux_negative;
return flux_positive;
auto positive = [](Scalar *mach_normal, Scalar *p_normal){
Scalar mach = *mach_normal;
if (mach >= -1 && mach <= 1) {
auto half_mach_plus = (1 + mach) * 0.5;
*mach_normal = half_mach_plus * half_mach_plus;
*p_normal *= half_mach_plus;
} else if (mach < -1) {
*mach_normal = 0.0;
*p_normal = 0.0;
}
};
auto negative = [](Scalar *mach_normal, Scalar *p_normal){
Scalar mach = *mach_normal;
if (mach >= -1 && mach <= 1) {
auto half_mach_minus = (1 - mach) * 0.5;
*mach_normal = -half_mach_minus * half_mach_minus;
*p_normal *= half_mach_minus;
} else if (mach > 1) {
*mach_normal = 0.0;
*p_normal = 0.0;
}
};
return GetSignedFlux(left, positive) + GetSignedFlux(right, negative);
}
// Get F of U
static Flux GetFlux(const Primitive& state) {
Expand All @@ -51,42 +70,16 @@ class Ausm {
requires(kDimensions == 3) {
return { 1, primitive.u(), primitive.v(), primitive.w(), enthalpy };
}
Flux GetPositiveFlux(const Primitive& state) {
double p_positive = state.p();
template <class SignedOperation>
Flux GetSignedFlux(const Primitive& state, SignedOperation &&operation) {
double a = Gas::GetSpeedOfSound(state);
double mach = state.u() / a;
double mach_positive = mach;
double h = a * a / Gas::GammaMinusOne() + state.GetKineticEnergy();
Flux flux = BuildFlux(state, h);
if (mach >= -1 && mach <= 1) {
mach_positive = (mach + 1) * (mach + 1) * 0.25;
p_positive = state.p() * (mach + 1) * 0.5;
} else if (mach < -1) {
mach_positive = 0.0;
p_positive = 0.0;
}
double temp = state.rho() * a * mach_positive;
flux *= temp;
flux.momentumX() += p_positive;
return flux;
}
Flux GetNegativeFlux(const Primitive& state) {
double p_negative = state.p();
double a = Gas::GetSpeedOfSound(state);
double mach = state.u() / a;
double mach_negative = mach;
double h = a * a / Gas::GammaMinusOne() + state.GetKineticEnergy();
Flux flux = BuildFlux(state, h);
if (mach >= -1 && mach <= 1) {
mach_negative = - (mach - 1) * (mach - 1) * 0.25;
p_negative = - state.p() * (mach - 1) * 0.5;
} else if (mach > 1) {
mach_negative = 0.0;
p_negative = 0.0;
}
double temp = state.rho() * a * mach_negative;
flux *= temp;
flux.momentumX() += p_negative;
double mach_normal = state.u() / a;
double p_normal = state.p();
operation(&mach_normal, &p_normal);
flux *= state.rho() * a * mach_normal;
flux.momentumX() += p_normal;
return flux;
}
};
Expand Down

0 comments on commit e31c5af

Please sign in to comment.