From fdf112839298f331fde75a988dd2fee8a024d753 Mon Sep 17 00:00:00 2001 From: villberg Date: Sun, 8 Jun 2014 20:46:32 +0000 Subject: [PATCH] Fixed NPE when initial equations are not defined for enumerated stocks. This is just a work-around. Modelica code generation should be fixed to include the proper initial equations. Stocks are now initialized to 0. refs #4932 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29598 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../src/fi/semantum/sysdyn/solver/Derivate.java | 2 ++ .../src/fi/semantum/sysdyn/solver/Environment.java | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Derivate.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Derivate.java index 131ca742..7d26af56 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Derivate.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Derivate.java @@ -29,6 +29,8 @@ public class Derivate implements IExpression { Environment environment = (Environment)_environment; // Double old = (Double)environment.getValue(variable.name + variable.subscriptKey()); Double old = (Double)environment.getValue(variable.base.index(_environment, subscripts)); + // FIXME: should not be fixed like this + if(old == null) old = 0.0; return old+environment.step*(Double)e.evaluate(environment); } 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 01df0c3a..90f84a9b 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 @@ -483,8 +483,12 @@ final public class Environment implements IEnvironment, ISystem { for (int i = 0; i < model.derivativeArray.length; i++) { Variable v = model.derivativeArray[i].target; if(!used.add(v.base.name)) continue; - for(int index=0;index