Fixed average thrust time to deal with variable DT
authorBill Kuker <bkuker@billkuker.com>
Thu, 2 Jul 2009 14:17:21 +0000 (14:17 +0000)
committerBill Kuker <bkuker@billkuker.com>
Thu, 2 Jul 2009 14:17:21 +0000 (14:17 +0000)
src/com/billkuker/rocketry/motorsim/visual/BurnPanel.java

index dc69c3391b693cc19ab3408ebf5ee4d0a246ddb0..4fb45af174548d24cf25a68a025a1c0b0ff5a139 100644 (file)
@@ -91,24 +91,25 @@ public class BurnPanel extends JPanel {
                        \r
 \r
                                Amount<RocketScience.Impulse> ns = Amount.valueOf(0, RocketScience.NEWTON_SECOND);\r
-                               Amount<Force> averageThrust = Amount.valueOf(0, SI.NEWTON);\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
-                               int thrustCount = 0;\r
-                               \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
-                                               thrustCount++;\r
-                                               averageThrust = averageThrust.plus(i.thrust);\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
-                               if ( thrustCount > 0)\r
-                                       averageThrust = averageThrust.divide(thrustCount);\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
                                int cn = (int)(Math.log(ns.doubleValue(RocketScience.NEWTON_SECOND)/1.25) / Math.log(2));\r
                                char cl = (char)((int)'A' + cn);\r