From 01f1dd1dc680f1a9fe6dae6a0c66c7b73b2c97d5 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Thu, 26 Oct 2023 14:06:42 -0600 Subject: [PATCH] Avoid divide by 0 in TubeCalc when velocity is 0 by setting CD to 0 in this case. --- .../net/sf/openrocket/aerodynamics/barrowman/TubeCalc.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/aerodynamics/barrowman/TubeCalc.java b/core/src/net/sf/openrocket/aerodynamics/barrowman/TubeCalc.java index 3abd7aa30..cb8b1e8cd 100644 --- a/core/src/net/sf/openrocket/aerodynamics/barrowman/TubeCalc.java +++ b/core/src/net/sf/openrocket/aerodynamics/barrowman/TubeCalc.java @@ -40,6 +40,11 @@ public abstract class TubeCalc extends RocketComponentCalc { public double calculatePressureCD(FlightConditions conditions, double stagnationCD, double baseCD, WarningSet warnings) { + // If we aren't moving, treat CD as 0 + final double v = conditions.getVelocity(); + if (v < MathUtil.EPSILON) + return 0; + // Need to check for tube inner area 0 in case of rockets using launch lugs with // an inner radius of 0 to emulate rail guides (or just weird rockets, of course) double tubeCD = 0.0; @@ -49,7 +54,6 @@ public abstract class TubeCalc extends RocketComponentCalc { final double p = conditions.getAtmosphericConditions().getPressure(); final double t = conditions.getAtmosphericConditions().getTemperature(); final double rho = conditions.getAtmosphericConditions().getDensity(); - final double v = conditions.getVelocity(); // Reynolds number (note Reynolds number for the interior of a pipe is based on diameter, // not length (t))