From d2f364f0868a09f074aa159faa866bf05d054341 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Fri, 4 Mar 2022 17:52:44 -0700 Subject: [PATCH 1/3] Correctly identify when time is past end of thrustcurve so thrust is 0 in getAverageThrust This has been lurking -- we're not actually supposed to be calling getAverageThrustThrust when we're past the end of the thrustcurve (there's a test for whether the motor is active before calling it), but another bug in the parallel staging code exposed it. --- core/src/net/sf/openrocket/motor/ThrustCurveMotor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java index 904b87053..51f78e511 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java @@ -338,11 +338,11 @@ public class ThrustCurveMotor implements Motor, Comparable, Se int timeIndex = 0; - while( timeIndex < time.length-2 && startTime > time[timeIndex+1] ) { + while( timeIndex < time.length-1 && startTime > time[timeIndex+1] ) { timeIndex++; } - if ( timeIndex == time.length ) { + if ( timeIndex == time.length-1 ) { return 0.0; } From 24e1dcc7fe449b7c20a494d9db2be51c9f918a2d Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 7 Mar 2022 09:46:27 -0700 Subject: [PATCH 2/3] Make sure active motor list is updated after all stage state changes Use getActiveMotors() instead of getMotors() to get motors in thrust calculation --- .../sf/openrocket/rocketcomponent/FlightConfiguration.java | 7 ++++--- .../openrocket/simulation/AbstractSimulationStepper.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 2ec435327..7cbd9f0bf 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -109,23 +109,23 @@ public class FlightConfiguration implements FlightConfigurableParameter activeMotorList = status.getMotors(); + Collection activeMotorList = status.getActiveMotors(); for (MotorClusterState currentMotorState : activeMotorList ) { thrust += currentMotorState.getAverageThrust( status.getSimulationTime(), currentTime ); //thrust += currentMotorState.getThrust( currentTime ); From 6a8d53307062061c76001957ef0cfd3061618049 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 7 Mar 2022 09:59:14 -0700 Subject: [PATCH 3/3] Cache active motors instead of recalculating on each call --- .../rocketcomponent/FlightConfiguration.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 7cbd9f0bf..70f645ab1 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -63,6 +63,7 @@ public class FlightConfiguration implements FlightConfigurableParameter stages = new HashMap(); final protected HashMap motors = new HashMap(); + final private Collection activeMotors = new ArrayList(); private int boundsModID = -1; private BoundingBox cachedBounds = new BoundingBox(); @@ -499,18 +500,12 @@ public class FlightConfiguration implements FlightConfigurableParameter getActiveMotors() { - Collection activeMotors = new ArrayList(); - for( MotorConfiguration config : this.motors.values() ){ - if( isComponentActive( config.getMount() )){ - activeMotors.add( config ); - } - } return activeMotors; } private void updateMotors() { - this.motors.clear(); + motors.clear(); for ( RocketComponent comp : getActiveComponents() ){ if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){ @@ -520,10 +515,16 @@ public class FlightConfiguration implements FlightConfigurableParameter