From a5eae084569c5725168782b1666edef5d0511e27 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 9 Oct 2024 22:56:55 +0200 Subject: [PATCH] Clamp Mach to avoid beta singularity --- .../core/aerodynamics/FlightConditions.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/info/openrocket/core/aerodynamics/FlightConditions.java b/core/src/main/java/info/openrocket/core/aerodynamics/FlightConditions.java index f390b9d6c..e68ca211c 100644 --- a/core/src/main/java/info/openrocket/core/aerodynamics/FlightConditions.java +++ b/core/src/main/java/info/openrocket/core/aerodynamics/FlightConditions.java @@ -287,17 +287,16 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable { /** * Calculate the beta value (compressibility factor/Prandtl-Glauert correction factor) for the given Mach number. - * Source: "Active Guidance and Dynamic Flight Mechanics for Model Rockets", David Ketchledge (1993) * @param mach the Mach number. * @return the beta value. */ private static double calculateBeta(double mach) { - if (mach < 0.8) { + if (mach < 0.99999) { return MathUtil.safeSqrt(1 - mach * mach); - } else if (mach < 1.1) - // Because beta reaches infinity for M=1, we clamp the factor to 0.6 in the transonic region (Mach 0.8-1.1) - return 0.6; // sqrt(1 - 0.8^2) - else { + } else if (mach < 1.00001) { + // Clamp to avoid singularity near Mach 1 + return MathUtil.safeSqrt(1 - 0.99999 * 0.99999); + } else { return MathUtil.safeSqrt(mach * mach - 1); } }