From 458e9e3d3d3e3dd105a029b109c33c9cb39cb5c8 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Fri, 20 Jan 2023 11:33:34 -0700 Subject: [PATCH] Add unit test for in-line pods --- .../net/sf/openrocket/util/TestRockets.java | 61 ++++++++++++++++++- .../aerodynamics/BarrowmanCalculatorTest.java | 50 +++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index bb9ba1347..2471997b2 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -1743,10 +1743,69 @@ public class TestRockets { return rocket; } + // Alpha III modified to have an inline pod + public static final Rocket makeEstesAlphaIIIwithInlinePod() { + + Rocket rocket = TestRockets.makeEstesAlphaIII(); + + // Find rocket components to manipulate + final InstanceMap imap = rocket.getSelectedConfiguration().getActiveInstances(); + AxialStage stage = null; + BodyTube body = null; + + RocketComponent c = null; + for(Map.Entry> entry: imap.entrySet() ) { + c = entry.getKey(); + + // reference everything to the bottom + c.setAxialMethod(AxialMethod.BOTTOM); + + if (c instanceof AxialStage) { + stage = (AxialStage) c; + } + + if (c instanceof BodyTube) { + body = (BodyTube) c; + } + } + + // disconnect the body from the stage + stage.removeChild(body); + + // We need to reference the components hooked to the body to its aft end, not forward + + // Make a shorter copy of the body tube and connect it the Stage + // Notice -- total lengths of the short tubes must add up to match the original + BodyTube frontTube = new BodyTube(body.getLength()/2.0, body.getOuterRadius(), body.getThickness()); + frontTube.setName("Front Body Tube"); + stage.addChild(frontTube); + + // Add a PodSet to the front body tube. + PodSet pod = new PodSet(); + pod.setInstanceCount(1); + pod.setRadiusMethod(RadiusMethod.COAXIAL); + frontTube.addChild(pod); + pod.setAxialMethod(AxialMethod.TOP); + pod.setAxialOffset(frontTube.getLength()); + + // Add another even shorter tube to the pod + BodyTube middleTube = new BodyTube(body.getLength()/4.0, body.getOuterRadius(), body.getThickness()); + middleTube.setName("Middle Body Tube"); + pod.addChild(middleTube); + + // Shorten the original body tube, rename it, and put it on the pod + body.setName("Aft body tube"); + body.setLength(body.getLength()/4.0); + pod.addChild(body); + + return rocket; + + } + /** * dump a test rocket to a file, so we can open it in OR */ - static void dumpRocket(Rocket rocket, String filename) { + public static void dumpRocket(Rocket rocket, String filename) { OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentFromRocket(rocket); OpenRocketSaver saver = new OpenRocketSaver(); diff --git a/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java b/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java index 2acd0f49c..9293773bc 100644 --- a/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java +++ b/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java @@ -19,6 +19,7 @@ import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.NoseCone; import net.sf.openrocket.rocketcomponent.ParallelStage; +import net.sf.openrocket.rocketcomponent.PodSet; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.TrapezoidFinSet; @@ -442,4 +443,53 @@ public class BarrowmanCalculatorTest { assertEquals(" Estes Alpha III with multiple empty stages cp y value is incorrect:", cp_calcRef.y, cp_calcMulti.y , EPSILON); assertEquals(" Estes Alpha III with multiple empty stages cp z value is incorrect:", cp_calcRef.z, cp_calcMulti.z , EPSILON); } + + /** + * Tests in-line pod aerodynamics and warnings + * + */ + @Test + public void testInlinePods() { + WarningSet warnings = new WarningSet(); + + // reference rocket and results + final Rocket refRocket = TestRockets.makeEstesAlphaIII(); + final FlightConfiguration refConfig = refRocket.getSelectedConfiguration(); + final FlightConditions refConditions = new FlightConditions(refConfig); + + final BarrowmanCalculator refCalc = new BarrowmanCalculator(); + double refCP = refCalc.getCP(refConfig, refConditions, warnings).x; + final AerodynamicForces refForces = refCalc.getAerodynamicForces(refConfig, refConditions, warnings); + assertTrue("reference rocket should have no warnings", warnings.isEmpty()); + final double refCD = refForces.getCD(); + + // test rocket + final Rocket testRocket = TestRockets.makeEstesAlphaIIIwithInlinePod(); + final PodSet pod = (PodSet) testRocket.getChild(0).getChild(1).getChild(0); + final FlightConfiguration testConfig = testRocket.getSelectedConfiguration(); + final FlightConditions testConditions = new FlightConditions(testConfig); + + TestRockets.dumpRocket(testRocket, "/home/joseph/rockets/openrocket/git/openrocket/work/testrocket.ork"); + final BarrowmanCalculator testCalc = new BarrowmanCalculator(); + double testCP = testCalc.getCP(testConfig, testConditions, warnings).x; + final AerodynamicForces testForces = testCalc.getAerodynamicForces(testConfig, testConditions, warnings); + assertTrue("test rocket should have no warnings", warnings.isEmpty()); + + assertEquals("ref and test rocket CP should match", refCP, testCP, EPSILON); + + final double testCD = testForces.getCD(); + assertEquals("ref and test rocket CD should match", refCD, testCD, EPSILON); + + // move the pod back. + pod.setAxialOffset(pod.getAxialOffset() + 0.1); + testCP = testCalc.getCP(testConfig, testConditions, warnings).x; + assertFalse("should be warning from gap in airframe", warnings.isEmpty()); + + // move the pod forward. + warnings.clear(); + pod.setAxialOffset(pod.getAxialOffset() - 0.2); + testCP = testCalc.getCP(testConfig, testConditions, warnings).x; + assertFalse("should be warning from airframe overlap", warnings.isEmpty()); + } + }