From: lehtonen Date: Mon, 23 Jun 2014 12:41:29 +0000 (+0000) Subject: Merged /sysdyn/trunk:r29682,r29683,r29687,r29690 to /sysdyn/branches/1.8 for sysdyn... X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=be3eba2001a64221ede61a44cd0fb560705d683e;p=simantics%2Fsysdyn.git Merged /sysdyn/trunk:r29682,r29683,r29687,r29690 to /sysdyn/branches/1.8 for sysdyn 1.8.1. refs #4891 refs #4935 refs #4990 refs #4994 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches@29696 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java index a8c875d6..d3cfce24 100644 --- a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java +++ b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java @@ -100,6 +100,15 @@ final public class Environment implements IEnvironment, ISystem { return Math.exp(x); } + }); + model.functions.put("log", new Fn1(2) { + + @Override + public Object evaluate(IEnvironment environment, int argc) { + Double x = (Double)environment.getValue(0); + return Math.log(x); + } + }); model.functions.put("zidz", new Fn1(2) { diff --git a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java index 5aa460e2..dd082219 100644 --- a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java +++ b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java @@ -16,18 +16,18 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) { case 0: if ((active1 & 0x80000L) != 0L) - return 20; - if ((active0 & 0x377bdef7bdef7bf0L) != 0L || (active1 & 0x180000000L) != 0L) + return 22; + if ((active1 & 0xb30010L) != 0L) + return 10; + if ((active0 & 0x884210842108400L) != 0L) { jjmatchedKind = 90; - return 2; + return 48; } - if ((active1 & 0xb30010L) != 0L) - return 13; - if ((active0 & 0x884210842108400L) != 0L) + if ((active0 & 0x377bdef7bdef7bf0L) != 0L || (active1 & 0x180000000L) != 0L) { jjmatchedKind = 90; - return 44; + return 2; } return -1; case 1: @@ -190,7 +190,7 @@ private int jjMoveStringLiteralDfa0_0() jjmatchedKind = 68; return jjMoveStringLiteralDfa1_0(0x0L, 0xb30000L); case 47: - return jjStartNfaWithStates_0(0, 83, 20); + return jjStartNfaWithStates_0(0, 83, 22); case 58: jjmatchedKind = 69; return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000L); @@ -941,7 +941,7 @@ static final long[] jjbitVec0 = { private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 44; + jjnewStateCnt = 48; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -971,29 +971,34 @@ private int jjMoveNfa_0(int startState, int curPos) else if (curChar == 47) jjAddStates(7, 8); else if (curChar == 46) - jjCheckNAdd(13); + jjCheckNAdd(10); else if (curChar == 34) jjCheckNAddStates(9, 11); break; - case 44: + case 48: if ((0x3ff400000000000L & l) != 0L) { if (kind > 90) kind = 90; jjCheckNAdd(2); } + else if (curChar == 43) + { + if (kind > 92) + kind = 92; + } else if (curChar == 45) { if (kind > 92) kind = 92; } break; - case 20: + case 22: if (curChar == 47) { if (kind > 3) kind = 3; - jjCheckNAdd(27); + jjCheckNAdd(29); } else if (curChar == 42) jjCheckNAddStates(12, 14); @@ -1022,126 +1027,142 @@ private int jjMoveNfa_0(int startState, int curPos) kind = 91; break; case 9: - if (curChar == 45 && kind > 92) - kind = 92; - break; - case 12: if (curChar == 46) - jjCheckNAdd(13); + jjCheckNAdd(10); break; - case 13: + case 10: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 94) kind = 94; jjCheckNAddStates(15, 18); break; - case 15: + case 12: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 94) kind = 94; - jjCheckNAdd(15); + jjCheckNAdd(12); break; - case 16: + case 14: if (curChar == 45) - jjCheckNAdd(15); + jjCheckNAdd(12); + break; + case 15: + if (curChar == 43) + jjCheckNAdd(12); + break; + case 18: + if (curChar == 45 && kind > 92) + kind = 92; break; case 19: + if (curChar == 43 && kind > 92) + kind = 92; + break; + case 21: if (curChar == 47) jjAddStates(7, 8); break; - case 21: + case 23: if ((0xfffffbffffffffffL & l) != 0L) jjCheckNAddStates(12, 14); break; - case 22: + case 24: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 23; + jjstateSet[jjnewStateCnt++] = 25; break; - case 23: + case 25: if ((0xffff7fffffffffffL & l) != 0L) jjCheckNAddStates(12, 14); break; - case 24: + case 26: if (curChar == 47 && kind > 2) kind = 2; break; - case 25: + case 27: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 24; + jjstateSet[jjnewStateCnt++] = 26; break; - case 26: + case 28: if (curChar != 47) break; if (kind > 3) kind = 3; - jjCheckNAdd(27); + jjCheckNAdd(29); break; - case 27: + case 29: if ((0xfffffffffffffbffL & l) == 0L) break; if (kind > 3) kind = 3; - jjCheckNAdd(27); + jjCheckNAdd(29); break; - case 28: + case 30: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 93) kind = 93; jjCheckNAddStates(0, 6); break; - case 29: + case 31: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 93) kind = 93; - jjCheckNAdd(29); + jjCheckNAdd(31); break; - case 30: + case 32: if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(30, 31); + jjCheckNAddTwoStates(32, 33); break; - case 31: + case 33: if (curChar != 46) break; if (kind > 94) kind = 94; jjCheckNAddStates(19, 22); break; - case 32: + case 34: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 94) kind = 94; jjCheckNAddStates(19, 22); break; - case 34: + case 36: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 94) kind = 94; - jjCheckNAdd(34); + jjCheckNAdd(36); break; - case 35: + case 38: if (curChar == 45) - jjCheckNAdd(34); + jjCheckNAdd(36); break; - case 38: + case 39: + if (curChar == 43) + jjCheckNAdd(36); + break; + case 41: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(23, 26); break; - case 40: + case 43: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 94) kind = 94; - jjCheckNAdd(40); + jjCheckNAdd(43); break; - case 41: + case 45: if (curChar == 45) - jjCheckNAdd(40); + jjCheckNAdd(43); + break; + case 46: + if (curChar == 43) + jjCheckNAdd(43); break; default : break; } @@ -1167,11 +1188,11 @@ private int jjMoveNfa_0(int startState, int curPos) kind = 92; } if (curChar == 69) - jjCheckNAdd(9); + jjCheckNAddTwoStates(18, 19); else if (curChar == 101) - jjCheckNAdd(9); + jjCheckNAddTwoStates(18, 19); break; - case 44: + case 48: case 2: if ((0x7fffffe87fffffeL & l) == 0L) break; @@ -1201,58 +1222,58 @@ private int jjMoveNfa_0(int startState, int curPos) if ((0x2000000020L & l) != 0L && kind > 92) kind = 92; break; - case 10: + case 11: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 12; + break; + case 13: if (curChar == 101) - jjCheckNAdd(9); + jjCheckNAddTwoStates(14, 15); break; - case 11: + case 16: if (curChar == 69) - jjCheckNAdd(9); - break; - case 14: - if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 15; + jjCheckNAddTwoStates(14, 15); break; case 17: if (curChar == 101) - jjCheckNAdd(16); + jjCheckNAddTwoStates(18, 19); break; - case 18: + case 20: if (curChar == 69) - jjCheckNAdd(16); + jjCheckNAddTwoStates(18, 19); break; - case 21: case 23: + case 25: jjCheckNAddStates(12, 14); break; - case 27: + case 29: if (kind > 3) kind = 3; - jjstateSet[jjnewStateCnt++] = 27; + jjstateSet[jjnewStateCnt++] = 29; break; - case 33: + case 35: if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 34; + jjstateSet[jjnewStateCnt++] = 36; break; - case 36: + case 37: if (curChar == 101) - jjCheckNAdd(35); + jjCheckNAddTwoStates(38, 39); break; - case 37: + case 40: if (curChar == 69) - jjCheckNAdd(35); + jjCheckNAddTwoStates(38, 39); break; - case 39: + case 42: if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 40; + jjstateSet[jjnewStateCnt++] = 43; break; - case 42: + case 44: if (curChar == 101) - jjCheckNAdd(41); + jjCheckNAddTwoStates(45, 46); break; - case 43: + case 47: if (curChar == 69) - jjCheckNAdd(41); + jjCheckNAddTwoStates(45, 46); break; default : break; } @@ -1271,17 +1292,17 @@ private int jjMoveNfa_0(int startState, int curPos) if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(9, 11); break; - case 21: case 23: + case 25: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(12, 14); break; - case 27: + case 29: if ((jjbitVec0[i2] & l2) == 0L) break; if (kind > 3) kind = 3; - jjstateSet[jjnewStateCnt++] = 27; + jjstateSet[jjnewStateCnt++] = 29; break; default : break; } @@ -1294,15 +1315,15 @@ private int jjMoveNfa_0(int startState, int curPos) kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 44 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 48 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } static final int[] jjnextStates = { - 29, 30, 31, 38, 39, 42, 43, 20, 26, 4, 5, 7, 21, 22, 25, 13, - 14, 17, 18, 32, 33, 36, 37, 38, 39, 42, 43, + 31, 32, 33, 41, 42, 44, 47, 22, 28, 4, 5, 7, 23, 24, 27, 10, + 11, 13, 16, 34, 35, 37, 40, 41, 42, 44, 47, }; /** Token literal values. */ @@ -1341,8 +1362,8 @@ static final long[] jjtoSkip = { 0xeL, 0x0L, }; protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[44]; -private final int[] jjstateSet = new int[88]; +private final int[] jjrounds = new int[48]; +private final int[] jjstateSet = new int[96]; private final StringBuilder jjimage = new StringBuilder(); private StringBuilder image = jjimage; private int jjimageLen; @@ -1373,7 +1394,7 @@ private void ReInitRounds() { int i; jjround = 0x80000001; - for (i = 44; i-- > 0;) + for (i = 48; i-- > 0;) jjrounds[i] = 0x80000000; } diff --git a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj index 190ea2f8..839340c8 100644 --- a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj +++ b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj @@ -78,7 +78,7 @@ TOKEN: | | { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } -| +| | | "." ()? ( )? diff --git a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt index 2fc5f9ce..c65900fd 100644 --- a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt +++ b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt @@ -74,7 +74,7 @@ TOKEN: | | { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } -| +| | | "." ()? ( )? diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java index 27f33a69..7ccc8155 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Copyright (c) 2007, 2012, 2014 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -28,6 +28,7 @@ import org.simantics.sysdyn.representation.utils.RepresentationUtils; * Variability of a variable in system dynamics models. * * @author Teemu Lempinen + * @author Tuomas Miettinen * */ public enum Variability { @@ -164,23 +165,28 @@ public enum Variability { * @return Variabilty of a variable */ static public Variability getVariability(IndependentVariable variable) { - if(RepresentationUtils.isPartOfGameExperiment(variable) && !(variable instanceof Stock)) { - - /* - * Game experiments cannot use as many parameter variables as normal experiments. - * If a parameter variable is changed, other parameter values depending on that - * parameter value are not automatically changed. - * - * Something of a hack: - * Allow variable references, if there are not incoming dependencies to the variable. - * This enables the use of derived variables for initial values of stocks. - */ - if(variable.getIncomingDependencies() == null || variable.getIncomingDependencies().isEmpty()) - return getVariability(variable, true, null); - else - return getVariability(variable, false, null); - } else { - return getVariability(variable, true, null); + try { + if(RepresentationUtils.isPartOfGameExperiment(variable) && !(variable instanceof Stock)) { + + /* + * Game experiments cannot use as many parameter variables as normal experiments. + * If a parameter variable is changed, other parameter values depending on that + * parameter value are not automatically changed. + * + * Something of a hack: + * Allow variable references, if there are not incoming dependencies to the variable. + * This enables the use of derived variables for initial values of stocks. + */ + if(variable.getIncomingDependencies() == null || variable.getIncomingDependencies().isEmpty()) + return getVariability(variable, true, null); + else + return getVariability(variable, false, null); + } else { + return getVariability(variable, true, null); + } + } catch (StackOverflowError e) { + // For circular dependencies; selecting continuous for a good guess. + return Variability.CONTINUOUS; } } diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java index 731151f1..4203b80a 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java @@ -180,7 +180,9 @@ public class LoopUtils { dependingVariables.add(head); } } - elementaryLoopItems.get(original).dependencies.addAll(dependingVariables); + ElementaryLoopItem el = elementaryLoopItems.get(original); + if (el != null) + el.dependencies.addAll(dependingVariables); } // Fill the adjacent matrix