]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Pre-step initialization was not up-to-date
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 8 Sep 2014 08:24:52 +0000 (08:24 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 8 Sep 2014 08:24:52 +0000 (08:24 +0000)
refs #5224

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

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

index b4dc80e03f168f53fc0a3c8c12bd7fdd9ebf52c5..34f6319bca78256d78babaabdc839e3156abc310 100644 (file)
@@ -16,7 +16,6 @@ import gnu.trove.list.array.TIntArrayList;
 import gnu.trove.map.hash.TObjectIntHashMap;\r
 \r
 import java.util.ArrayList;\r
-import java.util.Arrays;\r
 import java.util.Collection;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
@@ -425,7 +424,6 @@ final public class Environment implements IEnvironment, ISystem {
                                        Double d = (Double)environment.getValue(i);\r
                                        dims[i] = d.intValue();\r
                                }\r
-                               System.err.println("zeros " + Arrays.toString(dims));\r
                                return make(dims, 0);\r
                        }\r
                        \r
index dd1e876ffdff07c47d61e084ceb8a8248b7a3097..7c988f908d0f6fdbcf0bd205c4e5137aedfcc5a1 100644 (file)
@@ -28,6 +28,7 @@ import fi.semantum.sysdyn.solver.parser.SimpleNode;
 \r
 public class Solver {\r
 \r
+       private static final boolean VALIDATE = false;  \r
        private static final boolean PRINT_EXCEPTIONS = false;  \r
        private static final int STACK_SIZE = 1000;\r
        private static final int MAX_LOOPS = 50;\r
@@ -111,13 +112,15 @@ public class Solver {
        private String codeCache = null;\r
        \r
        private void validate(Variable var, Object value) {\r
-               if(value instanceof Double) {\r
-                       if(Double.isNaN((Double)value)) {\r
-                               throw new IllegalStateException("value is invalid (NaN)");\r
+               if(VALIDATE) {\r
+                       if(value instanceof Double) {\r
+                               if(Double.isNaN((Double)value)) {\r
+                                       throw new IllegalStateException("value is invalid (NaN)");\r
+                               }\r
+                       }\r
+                       if(value instanceof Array) {\r
+                               for(Object o : ((Array)value).elements()) validate(var, o);\r
                        }\r
-               }\r
-               if(value instanceof Array) {\r
-                       for(Object o : ((Array)value).elements()) validate(var, o);\r
                }\r
        }\r
        \r
@@ -315,19 +318,22 @@ public class Solver {
                                ass.target.assign(env, ass.subscripts, value);\r
                        }\r
 \r
-                       // Solve initial values\r
                        for(VariableDeclaration vd : model.variables) {\r
                                try {\r
                                        for(Argument arg : vd.modification.args) {\r
                                                if(arg.name.endsWith("start")) {\r
                                                        Object value = arg.modification.evaluate(env);\r
                                                        if(vd.variable.base.dimension() == 1) {\r
+                                                               validate(vd.variable, value);\r
                                                                vd.variable.assign(env, null, value);\r
                                                        } else {\r
+                                                               validate(vd.variable, value);\r
                                                                if(value instanceof Double) {\r
                                                                        Array array = new Array();\r
                                                                        for(int i=0;i<vd.variable.base.dimension();i++) array.addElement(value);\r
                                                                        vd.variable.assign(env, null, array);\r
+                                                               } else if (value instanceof Array) {\r
+                                                                       vd.variable.assign(env, null, value);\r
                                                                } else {\r
                                                                        throw new IllegalStateException();\r
                                                                }\r