\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
}\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