]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5382
authorjussi.koskela <jussi.koskela@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 9 Sep 2014 11:13:14 +0000 (11:13 +0000)
committerjussi.koskela <jussi.koskela@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 9 Sep 2014 11:13:14 +0000 (11:13 +0000)
Initial state incorrect after parameter update

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

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

index 7c988f908d0f6fdbcf0bd205c4e5137aedfcc5a1..4d083f77e4dfc63077d3513d2f7975f641193ebd 100644 (file)
@@ -305,47 +305,51 @@ public class Solver {
 \r
                if(!started && dirty) {\r
                        \r
-                       // Solve all algebraic equations\r
-                       Assignment[] assignments = model.assignmentArray;\r
-                       for(int i=0;i<assignments.length;i++) {\r
-                               if(assignments[i].isConstant) continue;\r
-                               Object value = assignments[i].expression.evaluate(env);\r
-                               assignments[i].target.assign(env, assignments[i].subscripts, value);\r
-                       }\r
-                       for(Assignment ass : model.initials) {\r
-                               if(ass.isConstant) continue;\r
-                               Object value = ass.expression.evaluate(env);\r
-                               ass.target.assign(env, ass.subscripts, value);\r
-                       }\r
-\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
+                       for(int loop=0;loop<3;loop++) {\r
+                       \r
+                               // Solve all algebraic equations\r
+                               Assignment[] assignments = model.assignmentArray;\r
+                               for(int i=0;i<assignments.length;i++) {\r
+                                       if(assignments[i].isConstant) continue;\r
+                                       Object value = assignments[i].expression.evaluate(env);\r
+                                       assignments[i].target.assign(env, assignments[i].subscripts, value);\r
+                               }\r
+                               for(Assignment ass : model.initials) {\r
+                                       if(ass.isConstant) continue;\r
+                                       Object value = ass.expression.evaluate(env);\r
+                                       ass.target.assign(env, ass.subscripts, value);\r
+                               }\r
+       \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
-                                                                       throw new IllegalStateException();\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
                                                                }\r
                                                        }\r
                                                }\r
-                                       }\r
-                               } catch (Exception e) {\r
-                                       if(PRINT_EXCEPTIONS) {\r
-                                               e.printStackTrace();\r
-                                               System.err.println("failed to assign " + vd.variable.toString());\r
+                                       } catch (Exception e) {\r
+                                               if(PRINT_EXCEPTIONS) {\r
+                                                       e.printStackTrace();\r
+                                                       System.err.println("failed to assign " + vd.variable.toString());\r
+                                               }\r
                                        }\r
                                }\r
+                               \r
                        }\r
                        \r
                        dirty = false;\r
@@ -406,7 +410,11 @@ public class Solver {
        }\r
        \r
        public double getTime() {\r
-               return env.time;\r
+               if (env != null) {\r
+                       return env.time;\r
+               } else {\r
+                       return 0.0;\r
+               }\r
        }\r
        \r
        public void setValue(String key, double value) {\r