From 6bc74f6b91192565b89e7fe25dc4f4f88394ee64 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 24 Nov 2022 19:25:07 +0100 Subject: [PATCH 1/2] [#1848] Parse all stages (including boosters) for top stage --- core/src/net/sf/openrocket/rocketcomponent/Rocket.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index c7e82866b..ae6dfe554 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -209,16 +209,16 @@ public class Rocket extends ComponentAssembly { } /** - * Get the topmost stage, only taking into account active stages from the flight configuration. + * Get the topmost stage (including boosters), only taking into account active stages from the flight configuration. * @param config flight configuration dictating which stages are active * @return the topmost active stage, or null if there are no active stages. */ public AxialStage getTopmostStage(FlightConfiguration config) { if (config == null) return null; - for (int i = 0; i < getChildCount(); i++) { - if (getChild(i) instanceof AxialStage && config.isStageActive(getChild(i).getStageNumber())) { - return (AxialStage) getChild(i); + for (AxialStage stage : getStageList()) { + if (config.isStageActive(stage.getStageNumber())) { + return stage; } } return null; From 39b479a3c93b19278a4b29b438f29066f1eca99c Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 28 Nov 2022 19:57:42 +0100 Subject: [PATCH 2/2] Add unit test for only booster stage active --- .../simulation/DisableStageTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/core/test/net/sf/openrocket/simulation/DisableStageTest.java b/core/test/net/sf/openrocket/simulation/DisableStageTest.java index bbd62d4cf..f92c634ea 100644 --- a/core/test/net/sf/openrocket/simulation/DisableStageTest.java +++ b/core/test/net/sf/openrocket/simulation/DisableStageTest.java @@ -235,6 +235,34 @@ public class DisableStageTest extends BaseTestCase { compareSims(simOriginal, simDisabled, delta); } + /** + * Test whether the simulations run when only the booster stage is active. + */ + @Test + public void testBooster3() { + Rocket rocketDisabled = TestRockets.makeFalcon9Heavy(); + + FlightConfigurationId fid = new FlightConfigurationId(TestRockets.FALCON_9H_FCID_1); + Simulation simDisabled = new Simulation(rocketDisabled); + simDisabled.setFlightConfigurationId(fid); + simDisabled.getOptions().setISAAtmosphere(true); + simDisabled.getOptions().setTimeStep(0.05); + + //// Test only enabling the booster stage (test for GitHub issue #1848) + simDisabled.getActiveConfiguration().setOnlyStage(2); + + //// Test that the top stage is the booster stage + Assert.assertEquals(rocketDisabled.getTopmostStage(simDisabled.getActiveConfiguration()), rocketDisabled.getStage(2)); + + try { // Just check that the simulation runs without exceptions + simDisabled.simulate(); + } catch (SimulationException e) { + if (!(e instanceof MotorIgnitionException)) { + Assert.fail("Simulation failed: " + e); + } + } + } + /** * Compare simActual to simExpected and fail the unit test if there was an error during simulation or * the two don't match.