From 7a2ede6e2491740b41836debf3e10c99e06b4b6e Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 25 Sep 2023 18:43:05 -0600 Subject: [PATCH] Use current atmospheric conditions, not previous conditions, in calculating thrust. This lets us get rid of previousAtmosphericConditions completely. Note that while we pass acceleration and atmospheric conditions into calculateAverageThrust(), we don't actually do anything with them there. They appear to be passed in for some sort of eventual enhancements when we do things like altitude compensation for motors, or acceleration for hybrids or water rockets. It also turned out that while we called getPreviousAtmosphericConditions() when call ing calculateAverageThrust(), setPreviousAtmosphericConditions() was never called. --- .../openrocket/simulation/RK4SimulationStatus.java | 14 -------------- .../simulation/RK4SimulationStepper.java | 10 ++++++++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/core/src/net/sf/openrocket/simulation/RK4SimulationStatus.java b/core/src/net/sf/openrocket/simulation/RK4SimulationStatus.java index 67465e16d..d42d951fa 100644 --- a/core/src/net/sf/openrocket/simulation/RK4SimulationStatus.java +++ b/core/src/net/sf/openrocket/simulation/RK4SimulationStatus.java @@ -8,7 +8,6 @@ public class RK4SimulationStatus extends SimulationStatus implements Cloneable { private Coordinate launchRodDirection; private double previousAcceleration = 0; - private AtmosphericConditions previousAtmosphericConditions; // Used for determining when to store aerodynamic computation warnings: private double maxZVelocity = 0; @@ -26,7 +25,6 @@ public class RK4SimulationStatus extends SimulationStatus implements Cloneable { this.previousAcceleration = ((RK4SimulationStatus) other).previousAcceleration; this.maxZVelocity = ((RK4SimulationStatus) other).maxZVelocity; this.startWarningTime = ((RK4SimulationStatus) other).startWarningTime; - this.previousAtmosphericConditions = ((RK4SimulationStatus) other).previousAtmosphericConditions; } } public void setLaunchRodDirection(Coordinate launchRodDirection) { @@ -49,18 +47,6 @@ public class RK4SimulationStatus extends SimulationStatus implements Cloneable { this.previousAcceleration = previousAcceleration; } - - public AtmosphericConditions getPreviousAtmosphericConditions() { - return previousAtmosphericConditions; - } - - - public void setPreviousAtmosphericConditions( - AtmosphericConditions previousAtmosphericConditions) { - this.previousAtmosphericConditions = previousAtmosphericConditions; - } - - public double getMaxZVelocity() { return maxZVelocity; } diff --git a/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java b/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java index 2801fbc6a..9c1b825af 100644 --- a/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java +++ b/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java @@ -102,11 +102,17 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { store.timestep = MathUtil.max(MathUtil.min(store.timestep, maxTimeStep), MIN_TIME_STEP); checkNaN(store.timestep); + /* + * Get the current atmospheric conditions + */ + calculateFlightConditions(status, store); + store.atmosphericConditions = store.flightConditions.getAtmosphericConditions(); + /* * Compute the initial thrust estimate. This is used for the first time step computation. */ - store.thrustForce = calculateAverageThrust(status, store.timestep, store.timestep, - status.getPreviousAtmosphericConditions(), false); + store.thrustForce = calculateAverageThrust(status, store.timestep, store.longitudinalAcceleration, + store.atmosphericConditions, false); /* * Perform RK4 integration. Decide the time step length after the first step.