]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Fixed NPE when initial equations are not defined for enumerated stocks. This is just...
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Sun, 8 Jun 2014 20:46:32 +0000 (20:46 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Sun, 8 Jun 2014 20:46:32 +0000 (20:46 +0000)
refs #4932

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29598 ac1ea38d-2e2b-0410-8846-a27921b304fc

fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Derivate.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java

index 131ca742555067ea63ba5b12352d13d3e44f73cf..7d26af5630dc37235d18569a7fcb820211b29d18 100644 (file)
@@ -29,6 +29,8 @@ public class Derivate implements IExpression {
                Environment environment = (Environment)_environment;\r
 //             Double old = (Double)environment.getValue(variable.name + variable.subscriptKey());\r
                Double old = (Double)environment.getValue(variable.base.index(_environment, subscripts));\r
+               // FIXME: should not be fixed like this\r
+               if(old == null) old = 0.0;\r
                return old+environment.step*(Double)e.evaluate(environment);\r
        }\r
        \r
index 01df0c3ad441b2e405fc7bf186d8f9806a0acefd..90f84a9b328fe6d2350c07a50828504a4d7605c8 100644 (file)
@@ -483,8 +483,12 @@ final public class Environment implements IEnvironment, ISystem {
                for (int i = 0; i < model.derivativeArray.length; i++) {\r
                        Variable v = model.derivativeArray[i].target;\r
                        if(!used.add(v.base.name)) continue;\r
-                       for(int index=0;index<v.base.dimension();index++)\r
-                               valueArray[offset++] = (Double)getValue(v.base.index(this, null)+index);\r
+                       for(int index=0;index<v.base.dimension();index++) {\r
+                               Double value = (Double)getValue(v.base.index(this, null)+index);\r
+                               // FIXME: should not be fixed like this\r
+                               if(value == null) value = 0.0;\r
+                               valueArray[offset++] = value;\r
+                       }\r
                }\r
                \r
                // NOTE: there is room for optimization as parameter values that do not\r