From afe56365f4ce81f18e77d334ef499ac143a97832 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Wed, 18 Nov 2015 12:05:36 -0500 Subject: [PATCH] Added BarrowmanCalculator tests --- .../openrocket/masscalc/MassCalculator.java | 2 +- .../net/sf/openrocket/util/TestRockets.java | 83 +++++++++++++++- .../aerodynamics/BarrowmanCalculatorTest.java | 94 +++++++++++++++++++ .../masscalc/MassCalculatorTest.java | 3 - .../gui/scalefigure/RocketPanel.java | 14 +-- 5 files changed, 184 insertions(+), 12 deletions(-) create mode 100644 core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculator.java b/core/src/net/sf/openrocket/masscalc/MassCalculator.java index 405f171aa..98bb13198 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculator.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculator.java @@ -50,7 +50,7 @@ public class MassCalculator implements Monitorable { private static final Logger log = LoggerFactory.getLogger(MassCalculator.class); - private static final double MIN_MASS = 0.001 * MathUtil.EPSILON; + public static final double MIN_MASS = 0.001 * MathUtil.EPSILON; private int rocketMassModID = -1; private int rocketTreeModID = -1; diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index b352e10e2..d8c74e442 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -88,6 +88,7 @@ public class TestRockets { } + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). private static MotorInstance generateMotorInstance_M1350_75mm(){ // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, // Motor.Type type, double[] delays, double diameter, double length, @@ -103,6 +104,7 @@ public class TestRockets { return mtr.getNewInstance(); } + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). private static MotorInstance generateMotorInstance_G77_29mm(){ // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, // Motor.Type type, double[] delays, double diameter, double length, @@ -307,7 +309,84 @@ public class TestRockets { return values[rnd.nextInt(values.length)]; } + // This is a Estes Alpha III + // http://www.rocketreviews.com/alpha-iii---estes-221256.html + // It is picked as a standard, simple, validation rocket. + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). + public static final Rocket makeEstesAlphaIII(){ + + Rocket rocket = new Rocket(); + AxialStage stage = new AxialStage(); + stage.setName("Stage1"); + rocket.addChild(stage); + + double noseconeLength = 0.06985; + double noseconeRadius = 0.012395; + NoseCone nosecone = new NoseCone(Transition.Shape.ELLIPSOID, noseconeLength, noseconeRadius); + nosecone.setAftShoulderLength(0.02479); + nosecone.setAftShoulderRadius(0.011811); + stage.addChild(nosecone); + + double bodytubeLength = 0.19685; + double bodytubeRadius = 0.012395; + double bodytubeThickness = 0.00033; + BodyTube bodytube = new BodyTube(bodytubeLength, bodytubeRadius, bodytubeThickness); + { + LaunchLug lug = new LaunchLug(); + lug.setRelativePosition(Position.TOP); + lug.setAxialOffset(0.111125); + lug.setLength(0.0508); + lug.setOuterRadius(0.002185); + lug.setInnerRadius(0.001981); + bodytube.addChild(lug); + + InnerTube inner = new InnerTube(); + inner.setRelativePosition(Position.TOP); + inner.setAxialOffset(0.13335); + inner.setLength(0.06985); + inner.setOuterRadius(0.009347); + inner.setThickness(0.00033); + inner.setMotorMount(true); + bodytube.addChild(inner); + + // omit other internal components... this method does not return a flyable version of the Mk 2 + } + stage.addChild(bodytube); + + int finCount = 3; + double finRootChord = .05715; + double finTipChord = .03048; + double finSweep = 0.06985455; + double finHeight = 0.04064; + TrapezoidFinSet finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); + finset.setThickness( 0.003175); + finset.setRelativePosition(Position.BOTTOM); + bodytube.addChild(finset); + + Material material = Application.getPreferences().getDefaultComponentMaterial(null, Material.Type.BULK); + nosecone.setMaterial(material); + bodytube.setMaterial(material); + finset.setMaterial(material); + + return rocket; + } + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). + public static final MotorInstance getTestD12Motor() { + // Estes D12: + // http://nar.org/SandT/pdf/Estes/D12.pdf + ThrustCurveMotor motor = new ThrustCurveMotor( + Manufacturer.getManufacturer("Estes"), + "D12-X", "Test Motor", Motor.Type.SINGLE, new double[] {0,3,5,7}, + 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] { 0, 10.2, 0 }, + new Coordinate[] { new Coordinate(0.0035,0,0,44.0), + new Coordinate(0.0035,0,0,30.0), + new Coordinate(0.0035,0,0,21.0)}, + "digest_D12"); + MotorInstance inst = motor.getNewInstance(); + inst.setEjectionDelay(5); + return inst; + } public static Rocket makeSmallFlyable() { double noseconeLength = 0.10, noseconeRadius = 0.01; double bodytubeLength = 0.20, bodytubeRadius = 0.01, bodytubeThickness = 0.001; @@ -609,6 +688,7 @@ public class TestRockets { return rocket; } + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). public static Rocket makeFalcon9Heavy() { Rocket rocket = new Rocket(); rocket.setName("Falcon9H Scale Rocket"); @@ -1143,9 +1223,8 @@ public class TestRockets { } public static OpenRocketDocument makeTestRocket_v108_withBoosters() { - Rocket rocket = new Rocket(); + Rocket rocket = makeFalcon9Heavy(); OpenRocketDocument document = OpenRocketDocumentFactory.createDocumentFromRocket(rocket); - return document; } diff --git a/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java b/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java new file mode 100644 index 000000000..dd84d533a --- /dev/null +++ b/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java @@ -0,0 +1,94 @@ +package net.sf.openrocket.aerodynamics; + +import static org.junit.Assert.*; + +import net.sf.openrocket.ServicesForTesting; +import net.sf.openrocket.motor.MotorInstance; +import net.sf.openrocket.plugin.PluginModule; +import net.sf.openrocket.rocketcomponent.BodyTube; +import net.sf.openrocket.rocketcomponent.FlightConfiguration; +import net.sf.openrocket.rocketcomponent.FlightConfigurationID; +import net.sf.openrocket.rocketcomponent.InnerTube; +import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.Coordinate; +import net.sf.openrocket.util.MathUtil; +import net.sf.openrocket.util.TestRockets; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Module; + +public class BarrowmanCalculatorTest { + protected final double EPSILON = MathUtil.EPSILON; + + private static Injector injector; + + @BeforeClass + public static void setup() { + Module applicationModule = new ServicesForTesting(); + Module pluginModule = new PluginModule(); + + injector = Guice.createInjector( applicationModule, pluginModule); + Application.setInjector(injector); + +// { +// GuiModule guiModule = new GuiModule(); +// Module pluginModule = new PluginModule(); +// Injector injector = Guice.createInjector(guiModule, pluginModule); +// Application.setInjector(injector); +// } + } + + @Test + public void testCPSimpleDry() { + Rocket rocket = TestRockets.makeEstesAlphaIII(); + FlightConfiguration config = rocket.getDefaultConfiguration(); + AerodynamicCalculator calc = new BarrowmanCalculator(); + FlightConditions conditions = new FlightConditions(config); + WarningSet warnings = new WarningSet(); + + // calculated from OpenRocket 15.03 + double expCPx = 0.225; // cm + Coordinate calcCP = calc.getCP(config, conditions, warnings); + + assertEquals(" Estes Alpha III cp x value is incorrect:", expCPx, calcCP.x, EPSILON); + Coordinate expCP = new Coordinate(expCPx, 0,0,0); + assertEquals(" Estes Alpha III CP is incorrect:", expCP, calcCP); + } + + @Test + public void testCPSimpleWithMotor() { + Rocket rkt = TestRockets.makeEstesAlphaIII(); + FlightConfiguration config = rkt.getDefaultConfiguration(); + FlightConfigurationID fcid = config.getFlightConfigurationID(); + AerodynamicCalculator calc = new BarrowmanCalculator(); + FlightConditions conditions = new FlightConditions(config); + WarningSet warnings = new WarningSet(); + + MotorInstance inst = TestRockets.getTestD12Motor(); + InnerTube motorTube = (InnerTube)rkt.getChild(0).getChild(1).getChild(1); + motorTube.setMotorInstance(fcid, inst); + motorTube.setMotorMount(true); + motorTube.setMotorOverhang(0.005); + + // calculated from OpenRocket 15.03 + double expCPx = 0.225; // cm + /// this is what the + Coordinate calcCP = calc.getCP(config, conditions, warnings); + + assertEquals(" Estes Alpha III cp x value is incorrect:", expCPx, calcCP.x, EPSILON); + Coordinate expCP = new Coordinate(expCPx, 0,0,0); + assertEquals(" Estes Alpha III CP is incorrect:", expCP, calcCP); + fail("Not yet implemented"); + } + + @Test + public void testGetWorstCP() { + fail("Not yet implemented"); + } + +} diff --git a/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java b/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java index 1dd1684f1..2e55fc9b4 100644 --- a/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java +++ b/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java @@ -24,9 +24,6 @@ public class MassCalculatorTest extends BaseTestCase { // tolerance for compared double test results protected final double EPSILON = MathUtil.EPSILON; - protected final Coordinate ZERO = new Coordinate(0., 0., 0.); - - @Test public void testRocketNoMotors() { Rocket rkt = TestRockets.makeNoMotorRocket(); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 7e377f201..9e8b80b5f 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -602,17 +602,19 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change extraText.setTheta(cpTheta); cg = massCalculator.getCG(curConfig, MassCalcType.LAUNCH_MASS); - // System.out.println("CG computed as "+cg+ " CP as "+cp); + - if (cp.weight > 0.000001) + if (cp.weight > MassCalculator.MIN_MASS){ cpx = cp.x; - else + }else{ cpx = Double.NaN; - - if (cg.weight > 0.000001) + } + + if (cg.weight > MassCalculator.MIN_MASS){ cgx = cg.x; - else + }else{ cgx = Double.NaN; + } figure3d.setCG(cg); figure3d.setCP(cp);