Calculate weight of fuel
authorBill Kuker <bkuker@billkuker.com>
Sun, 22 Jan 2012 19:42:00 +0000 (19:42 +0000)
committerBill Kuker <bkuker@billkuker.com>
Sun, 22 Jan 2012 19:42:00 +0000 (19:42 +0000)
gpl/com/billkuker/rocketry/motorsim/visual/openRocket/OneMotorDatabase.java

index 5d238850c080b2ed73cdf20e947ad60ef4da2035..2719c493809d87a84a12d2404df0bb76a42341f2 100644 (file)
@@ -1,8 +1,10 @@
 package com.billkuker.rocketry.motorsim.visual.openRocket;\r
+\r
 import java.util.List;\r
 import java.util.Vector;\r
 \r
 import javax.measure.quantity.Duration;\r
+import javax.measure.quantity.Mass;\r
 import javax.measure.unit.SI;\r
 \r
 import net.sf.openrocket.database.MotorDatabase;\r
@@ -49,7 +51,7 @@ public class OneMotorDatabase implements MotorDatabase {
 \r
                @Override\r
                public String getDescription() {\r
-                       if ( burn == null )\r
+                       if (burn == null)\r
                                return "NO MOTOR YET";\r
                        return burn.getMotor().getName();\r
                }\r
@@ -294,14 +296,29 @@ public class OneMotorDatabase implements MotorDatabase {
                cg = new Coordinate[burn.getData().size()];\r
                time = new double[burn.getData().size()];\r
                thrust = new double[burn.getData().size()];\r
-               \r
 \r
-               for (int i = 0; i < cg.length; i++) {\r
-                       cg[i] = new Coordinate();\r
-                       cg[i].setWeight(0.0); //TODO: Set weight!\r
+               cg[0] = new Coordinate();\r
+               \r
+               double lastWeight = b\r
+                               .getMotor()\r
+                               .getGrain()\r
+                               .volume(Amount.valueOf(0, SI.METER))\r
+                               .times(b.getMotor().getFuel().getIdealDensity()\r
+                                               .times(b.getMotor().getFuel().getDensityRatio()))\r
+                               .to(Mass.UNIT).doubleValue(SI.KILOGRAM);\r
+               \r
+               int i = 0;\r
+               double len = ((ICylindricalChamber) burn.getMotor().getChamber())\r
+                               .getLength().doubleValue(SI.METER);\r
+               \r
+               for (Interval d : burn.getData().values()) {\r
+                       lastWeight = lastWeight - d.fuelBurnt.doubleValue(SI.KILOGRAM);\r
+                       cg[i] = new Coordinate(len/2.0,0,0,lastWeight);\r
+                       System.err.println(lastWeight);\r
+                       i++;\r
                }\r
 \r
-               int i = 0;\r
+               i = 0;\r
                for (Amount<Duration> t : burn.getData().keySet()) {\r
                        time[i++] = t.doubleValue(SI.SECOND);\r
                }\r