Moved burn summary math out of GUI
authorBill Kuker <bkuker@billkuker.com>
Sun, 31 Oct 2010 15:56:51 +0000 (15:56 +0000)
committerBill Kuker <bkuker@billkuker.com>
Sun, 31 Oct 2010 15:56:51 +0000 (15:56 +0000)
gui/com/billkuker/rocketry/motorsim/visual/BurnPanel.java
src/com/billkuker/rocketry/motorsim/BurnSummary.java [new file with mode: 0644]

index dad56f511fed921847804a546b542636c7555b01..29f8f1ebecbdc3611ba6a228e4fc883d124030ae 100644 (file)
@@ -22,7 +22,7 @@ import javax.swing.event.ChangeListener;
 import org.jscience.physics.amount.Amount;\r
 \r
 import com.billkuker.rocketry.motorsim.Burn;\r
-import com.billkuker.rocketry.motorsim.Burn.Interval;\r
+import com.billkuker.rocketry.motorsim.BurnSummary;\r
 import com.billkuker.rocketry.motorsim.RocketScience;\r
 \r
 public class BurnPanel extends JPanel {\r
@@ -95,57 +95,30 @@ public class BurnPanel extends JPanel {
                        add( new SL(), BorderLayout.SOUTH);\r
                        \r
                        \r
+                       \r
+                       {\r
+                               BurnSummary bi = new BurnSummary(burn);\r
+                               JPanel text = new JPanel(new GridLayout(2, 5));\r
 \r
-                               Amount<RocketScience.Impulse> ns = Amount.valueOf(0, RocketScience.NEWTON_SECOND);\r
-                               \r
-                               Amount<Duration> thrustTime = Amount.valueOf(0, SI.SECOND);\r
-                               Amount<Force> maxThrust = Amount.valueOf(0, SI.NEWTON);\r
-                               Amount<Pressure> maxPressure = Amount.valueOf(0, SI.MEGA(SI.PASCAL));\r
-\r
-                               for( Interval i: burn.getData().values() ){\r
-                                       ns = ns.plus(i.dt.times(i.thrust));\r
-                                       if ( i.thrust.isGreaterThan(Amount.valueOf(0.01, SI.NEWTON))){\r
-                                               thrustTime = thrustTime.plus(i.dt);\r
-                                       }\r
-                                       if ( i.thrust.isGreaterThan(maxThrust))\r
-                                               maxThrust = i.thrust;\r
-                                       if ( i.chamberPressure.isGreaterThan(maxPressure))\r
-                                               maxPressure = i.chamberPressure;\r
-                               }\r
-                               \r
-                               Amount<Force> averageThrust = Amount.valueOf(0, SI.NEWTON);\r
-                               if ( thrustTime.isGreaterThan(Amount.valueOf(0, SI.SECOND)))\r
-                                       averageThrust = ns.divide(thrustTime).to(SI.NEWTON);\r
-\r
-                               float cnf = (float)(Math.log(ns.doubleValue(RocketScience.NEWTON_SECOND)/1.25) / Math.log(2));\r
-                               int cn = (int)cnf;\r
-                               float fraction = cnf - cn;\r
-                               int percent = (int)(100 * fraction);\r
-                               char cl = (char)((int)'A' + cn);\r
+                               text.add(new JLabel("Rating"));\r
+                               text.add(new JLabel("Total Impulse"));\r
+                               text.add(new JLabel("ISP"));\r
+                               text.add(new JLabel("Max Thrust"));\r
+                               text.add(new JLabel("Average Thust"));\r
+                               text.add(new JLabel("Max Pressure"));\r
 \r
-                               \r
-                               Amount<Duration> isp = ns.divide(\r
-                                               b.getMotor().getGrain().volume(Amount.valueOf(0, SI.MILLIMETER))\r
-                                                       .times(b.getMotor().getFuel().getIdealDensity().times(b.getMotor().getFuel().getDensityRatio()))\r
-                                               ).to(SI.METERS_PER_SECOND).divide(Amount.valueOf(9.81, SI.METERS_PER_SQUARE_SECOND)).to(SI.SECOND);\r
-                       \r
-                       JPanel text = new JPanel(new GridLayout(2,5));\r
+                               text.add(new JLabel(bi.getRating()));\r
+                               text.add(new JLabel(RocketScience.ammountToRoundedString(bi.totalImpulse())));\r
+                               text.add(new JLabel(RocketScience.ammountToRoundedString(bi.specificImpulse())));\r
+                               text.add(new JLabel(RocketScience\r
+                                               .ammountToRoundedString(bi.maxThrust())));\r
+                               text.add(new JLabel(RocketScience\r
+                                               .ammountToRoundedString(bi.averageThrust())));\r
+                               text.add(new JLabel(RocketScience\r
+                                               .ammountToRoundedString(bi.maxPressure())));\r
 \r
-                       text.add(new JLabel("Rating"));\r
-                       text.add(new JLabel("Total Impulse"));\r
-                       text.add(new JLabel("ISP"));\r
-                       text.add(new JLabel("Max Thrust"));\r
-                       text.add(new JLabel("Average Thust"));\r
-                       text.add(new JLabel("Max Pressure"));\r
-                       \r
-                       text.add(new JLabel(percent + "% " + new String(new char[]{cl}) + "-" +Math.round(averageThrust.doubleValue(SI.NEWTON))));\r
-                       text.add(new JLabel(RocketScience.ammountToRoundedString(ns)));\r
-                       text.add(new JLabel(RocketScience.ammountToRoundedString(isp)));                        \r
-                       text.add(new JLabel(RocketScience.ammountToRoundedString(maxThrust)));\r
-                       text.add(new JLabel(RocketScience.ammountToRoundedString(averageThrust)));\r
-                       text.add(new JLabel(RocketScience.ammountToRoundedString(maxPressure)));\r
-                       \r
-                       add(text, BorderLayout.NORTH);\r
+                               add(text, BorderLayout.NORTH);\r
+                       }\r
                        \r
                        \r
                } catch (NoSuchMethodException e){\r
diff --git a/src/com/billkuker/rocketry/motorsim/BurnSummary.java b/src/com/billkuker/rocketry/motorsim/BurnSummary.java
new file mode 100644 (file)
index 0000000..4d19a0e
--- /dev/null
@@ -0,0 +1,91 @@
+package com.billkuker.rocketry.motorsim;\r
+\r
+import javax.measure.quantity.Duration;\r
+import javax.measure.quantity.Force;\r
+import javax.measure.quantity.Pressure;\r
+import javax.measure.unit.SI;\r
+\r
+import org.jscience.physics.amount.Amount;\r
+\r
+import com.billkuker.rocketry.motorsim.Burn.Interval;\r
+\r
+public class BurnSummary {\r
+\r
+       Amount<RocketScience.Impulse> ns = Amount.valueOf(0,\r
+                       RocketScience.NEWTON_SECOND);\r
+\r
+       Amount<Duration> thrustTime = Amount.valueOf(0, SI.SECOND);\r
+       Amount<Force> maxThrust = Amount.valueOf(0, SI.NEWTON);\r
+       Amount<Pressure> maxPressure = Amount.valueOf(0, SI.MEGA(SI.PASCAL));\r
+       Amount<Duration> isp;\r
+       \r
+       public BurnSummary(Burn b) {\r
+               for (Interval i : b.getData().values()) {\r
+                       ns = ns.plus(i.dt.times(i.thrust));\r
+                       if (i.thrust.isGreaterThan(Amount.valueOf(0.01, SI.NEWTON))) {\r
+                               thrustTime = thrustTime.plus(i.dt);\r
+                       }\r
+                       if (i.thrust.isGreaterThan(maxThrust))\r
+                               maxThrust = i.thrust;\r
+                       if (i.chamberPressure.isGreaterThan(maxPressure))\r
+                               maxPressure = i.chamberPressure;\r
+               }\r
+               \r
+               isp = ns\r
+               .divide(b\r
+                               .getMotor()\r
+                               .getGrain()\r
+                               .volume(Amount.valueOf(0, SI.MILLIMETER))\r
+                               .times(b.getMotor()\r
+                                               .getFuel()\r
+                                               .getIdealDensity()\r
+                                               .times(b.getMotor().getFuel()\r
+                                                               .getDensityRatio())))\r
+               .to(SI.METERS_PER_SECOND)\r
+               .divide(Amount.valueOf(9.81,\r
+                               SI.METERS_PER_SQUARE_SECOND)).to(SI.SECOND);\r
+\r
+       }\r
+\r
+       public String getRating() {\r
+               float cnf = (float) (Math.log(ns\r
+                               .doubleValue(RocketScience.NEWTON_SECOND) / 1.25) / Math\r
+                               .log(2));\r
+               int cn = (int) cnf;\r
+               float fraction = cnf - cn;\r
+               int percent = (int) (100 * fraction);\r
+               char cl = (char) ((int) 'A' + cn);\r
+               \r
+               return percent + "% "\r
+               + new String(new char[] { cl }) + "-"\r
+               + Math.round(averageThrust().doubleValue(SI.NEWTON));\r
+       }\r
+\r
+       public Amount<RocketScience.Impulse> totalImpulse() {\r
+               return ns;\r
+       }\r
+\r
+       public Amount<Duration> thrustTime() {\r
+               return thrustTime;\r
+       }\r
+\r
+       public Amount<Force> maxThrust() {\r
+               return maxThrust;\r
+       }\r
+       \r
+       public Amount<Duration> specificImpulse(){\r
+               return isp;\r
+       }\r
+\r
+       public Amount<Force> averageThrust() {\r
+               Amount<Force> averageThrust = Amount.valueOf(0, SI.NEWTON);\r
+               if (thrustTime().isGreaterThan(Amount.valueOf(0, SI.SECOND)))\r
+                       averageThrust = totalImpulse().divide(thrustTime).to(SI.NEWTON);\r
+               return averageThrust;\r
+       }\r
+\r
+       public Amount<Pressure> maxPressure(){\r
+               return maxPressure;\r
+       }\r
+\r
+}\r