From: villberg Date: Mon, 8 Sep 2014 08:24:52 +0000 (+0000) Subject: Pre-step initialization was not up-to-date X-Git-Tag: v1.29.0~190 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=aea873cc5d400db7ef8c563c7e6f83a7ef032448;p=simantics%2Fsysdyn.git Pre-step initialization was not up-to-date refs #5224 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30223 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java index b4dc80e0..34f6319b 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java @@ -16,7 +16,6 @@ import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TObjectIntHashMap; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -425,7 +424,6 @@ final public class Environment implements IEnvironment, ISystem { Double d = (Double)environment.getValue(i); dims[i] = d.intValue(); } - System.err.println("zeros " + Arrays.toString(dims)); return make(dims, 0); } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java index dd1e876f..7c988f90 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java @@ -28,6 +28,7 @@ import fi.semantum.sysdyn.solver.parser.SimpleNode; public class Solver { + private static final boolean VALIDATE = false; private static final boolean PRINT_EXCEPTIONS = false; private static final int STACK_SIZE = 1000; private static final int MAX_LOOPS = 50; @@ -111,13 +112,15 @@ public class Solver { private String codeCache = null; private void validate(Variable var, Object value) { - if(value instanceof Double) { - if(Double.isNaN((Double)value)) { - throw new IllegalStateException("value is invalid (NaN)"); + if(VALIDATE) { + if(value instanceof Double) { + if(Double.isNaN((Double)value)) { + throw new IllegalStateException("value is invalid (NaN)"); + } + } + if(value instanceof Array) { + for(Object o : ((Array)value).elements()) validate(var, o); } - } - if(value instanceof Array) { - for(Object o : ((Array)value).elements()) validate(var, o); } } @@ -315,19 +318,22 @@ public class Solver { ass.target.assign(env, ass.subscripts, value); } - // Solve initial values for(VariableDeclaration vd : model.variables) { try { for(Argument arg : vd.modification.args) { if(arg.name.endsWith("start")) { Object value = arg.modification.evaluate(env); if(vd.variable.base.dimension() == 1) { + validate(vd.variable, value); vd.variable.assign(env, null, value); } else { + validate(vd.variable, value); if(value instanceof Double) { Array array = new Array(); for(int i=0;i