Moved some magic constants for regstep
authorBill Kuker <bkuker@billkuker.com>
Thu, 2 Jul 2009 15:56:39 +0000 (15:56 +0000)
committerBill Kuker <bkuker@billkuker.com>
Thu, 2 Jul 2009 15:56:39 +0000 (15:56 +0000)
src/com/billkuker/rocketry/motorsim/Burn.java

index 54958571206bfcb857d2838487175e9b375c16b0..c528333185343c2ab80ddf8ab910b8e5ec6a4142 100644 (file)
@@ -26,6 +26,10 @@ import org.jscience.physics.amount.Amount;
 import org.jscience.physics.amount.Constants;\r
 \r
 public class Burn {\r
+       //Some constants to tune adaptive regression step\r
+       private static final double regStepIncreaseFactor = 1.01;\r
+       private static final double regStepDecreaseFactor = .5;\r
+       private static final Amount<Pressure> chamberPressureMaxDelta = Amount.valueOf(.5, SI.MEGA(SI.PASCAL));\r
        \r
        private static Logger log = Logger.getLogger(Burn.class);\r
        protected final Motor motor;\r
@@ -82,7 +86,8 @@ public class Burn {
                \r
                step:\r
                for ( int i = 0; i < 5000; i++ ) {\r
-                       regStep = regStep.times(1.01);\r
+                       assert(positive(regStep));\r
+                       regStep = regStep.times(regStepIncreaseFactor);\r
                        \r
                        Interval prev = data.get(data.lastKey());\r
                        log.debug(prev);\r
@@ -155,7 +160,7 @@ public class Burn {
                        //Product can not go negative!\r
                        if ( !positive(next.chamberProduct) ){\r
                                log.warn("ChamberProduct Negative on step " + i + "!, Adjusting regstep down and repeating step!");\r
-                               regStep = regStep.divide(2);\r
+                               regStep = regStep.times(regStepDecreaseFactor);\r
                                continue step;\r
                        }\r
                        assert(positive(next.chamberProduct));\r
@@ -176,9 +181,9 @@ public class Burn {
                                        SI.PASCAL);\r
                        \r
                        Amount<Pressure> dp = next.chamberPressure.minus(prev.chamberPressure);\r
-                       if ( dp.abs().isGreaterThan(Amount.valueOf(.5, SI.MEGA(SI.PASCAL)))){\r
+                       if ( dp.abs().isGreaterThan(chamberPressureMaxDelta)){\r
                                log.warn("DP " + dp + " too big!, Adjusting regstep down and repeating step!");\r
-                               regStep = regStep.divide(2);\r
+                               regStep = regStep.times(regStepDecreaseFactor);\r
                                continue step;\r
                        }\r
                        \r
@@ -191,8 +196,6 @@ public class Burn {
                        }\r
                        \r
                        data.put(data.lastKey().plus(dt), next);\r
-\r
-                       assert(positive(regStep));\r
                }\r
 \r
                long time = new Date().getTime() - start;\r