]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Merged /sysdyn/trunk:r29682,r29683,r29687,r29690 to /sysdyn/branches/1.8 for sysdyn...
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 23 Jun 2014 12:41:29 +0000 (12:41 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 23 Jun 2014 12:41:29 +0000 (12:41 +0000)
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

1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java
1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java
1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj
1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt
1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java
1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java

index a8c875d6c375dbe7c895a99c8e5a0443fd5f16d5..d3cfce2490c8b009ac9880d231619e39f3c29b91 100644 (file)
@@ -100,6 +100,15 @@ final public class Environment implements IEnvironment, ISystem {
                                return Math.exp(x);\r
                        }\r
                        \r
+               });\r
+               model.functions.put("log", new Fn1(2) {\r
+\r
+                       @Override\r
+                       public Object evaluate(IEnvironment environment, int argc) {\r
+                               Double x = (Double)environment.getValue(0);\r
+                               return Math.log(x);\r
+                       }\r
+                       \r
                });\r
                model.functions.put("zidz", new Fn1(2) {\r
 \r
index 5aa460e21333bbe30566c613a29635e61ee1aa4b..dd08221904d8064d8f66c0487d4ddbc970b9e44e 100644 (file)
@@ -16,18 +16,18 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1)
    {\r
       case 0:\r
          if ((active1 & 0x80000L) != 0L)\r
-            return 20;\r
-         if ((active0 & 0x377bdef7bdef7bf0L) != 0L || (active1 & 0x180000000L) != 0L)\r
+            return 22;\r
+         if ((active1 & 0xb30010L) != 0L)\r
+            return 10;\r
+         if ((active0 & 0x884210842108400L) != 0L)\r
          {\r
             jjmatchedKind = 90;\r
-            return 2;\r
+            return 48;\r
          }\r
-         if ((active1 & 0xb30010L) != 0L)\r
-            return 13;\r
-         if ((active0 & 0x884210842108400L) != 0L)\r
+         if ((active0 & 0x377bdef7bdef7bf0L) != 0L || (active1 & 0x180000000L) != 0L)\r
          {\r
             jjmatchedKind = 90;\r
-            return 44;\r
+            return 2;\r
          }\r
          return -1;\r
       case 1:\r
@@ -190,7 +190,7 @@ private int jjMoveStringLiteralDfa0_0()
          jjmatchedKind = 68;\r
          return jjMoveStringLiteralDfa1_0(0x0L, 0xb30000L);\r
       case 47:\r
-         return jjStartNfaWithStates_0(0, 83, 20);\r
+         return jjStartNfaWithStates_0(0, 83, 22);\r
       case 58:\r
          jjmatchedKind = 69;\r
          return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000L);\r
@@ -941,7 +941,7 @@ static final long[] jjbitVec0 = {
 private int jjMoveNfa_0(int startState, int curPos)\r
 {\r
    int startsAt = 0;\r
-   jjnewStateCnt = 44;\r
+   jjnewStateCnt = 48;\r
    int i = 1;\r
    jjstateSet[0] = startState;\r
    int kind = 0x7fffffff;\r
@@ -971,29 +971,34 @@ private int jjMoveNfa_0(int startState, int curPos)
                   else if (curChar == 47)\r
                      jjAddStates(7, 8);\r
                   else if (curChar == 46)\r
-                     jjCheckNAdd(13);\r
+                     jjCheckNAdd(10);\r
                   else if (curChar == 34)\r
                      jjCheckNAddStates(9, 11);\r
                   break;\r
-               case 44:\r
+               case 48:\r
                   if ((0x3ff400000000000L & l) != 0L)\r
                   {\r
                      if (kind > 90)\r
                         kind = 90;\r
                      jjCheckNAdd(2);\r
                   }\r
+                  else if (curChar == 43)\r
+                  {\r
+                     if (kind > 92)\r
+                        kind = 92;\r
+                  }\r
                   else if (curChar == 45)\r
                   {\r
                      if (kind > 92)\r
                         kind = 92;\r
                   }\r
                   break;\r
-               case 20:\r
+               case 22:\r
                   if (curChar == 47)\r
                   {\r
                      if (kind > 3)\r
                         kind = 3;\r
-                     jjCheckNAdd(27);\r
+                     jjCheckNAdd(29);\r
                   }\r
                   else if (curChar == 42)\r
                      jjCheckNAddStates(12, 14);\r
@@ -1022,126 +1027,142 @@ private int jjMoveNfa_0(int startState, int curPos)
                      kind = 91;\r
                   break;\r
                case 9:\r
-                  if (curChar == 45 && kind > 92)\r
-                     kind = 92;\r
-                  break;\r
-               case 12:\r
                   if (curChar == 46)\r
-                     jjCheckNAdd(13);\r
+                     jjCheckNAdd(10);\r
                   break;\r
-               case 13:\r
+               case 10:\r
                   if ((0x3ff000000000000L & l) == 0L)\r
                      break;\r
                   if (kind > 94)\r
                      kind = 94;\r
                   jjCheckNAddStates(15, 18);\r
                   break;\r
-               case 15:\r
+               case 12:\r
                   if ((0x3ff000000000000L & l) == 0L)\r
                      break;\r
                   if (kind > 94)\r
                      kind = 94;\r
-                  jjCheckNAdd(15);\r
+                  jjCheckNAdd(12);\r
                   break;\r
-               case 16:\r
+               case 14:\r
                   if (curChar == 45)\r
-                     jjCheckNAdd(15);\r
+                     jjCheckNAdd(12);\r
+                  break;\r
+               case 15:\r
+                  if (curChar == 43)\r
+                     jjCheckNAdd(12);\r
+                  break;\r
+               case 18:\r
+                  if (curChar == 45 && kind > 92)\r
+                     kind = 92;\r
                   break;\r
                case 19:\r
+                  if (curChar == 43 && kind > 92)\r
+                     kind = 92;\r
+                  break;\r
+               case 21:\r
                   if (curChar == 47)\r
                      jjAddStates(7, 8);\r
                   break;\r
-               case 21:\r
+               case 23:\r
                   if ((0xfffffbffffffffffL & l) != 0L)\r
                      jjCheckNAddStates(12, 14);\r
                   break;\r
-               case 22:\r
+               case 24:\r
                   if (curChar == 42)\r
-                     jjstateSet[jjnewStateCnt++] = 23;\r
+                     jjstateSet[jjnewStateCnt++] = 25;\r
                   break;\r
-               case 23:\r
+               case 25:\r
                   if ((0xffff7fffffffffffL & l) != 0L)\r
                      jjCheckNAddStates(12, 14);\r
                   break;\r
-               case 24:\r
+               case 26:\r
                   if (curChar == 47 && kind > 2)\r
                      kind = 2;\r
                   break;\r
-               case 25:\r
+               case 27:\r
                   if (curChar == 42)\r
-                     jjstateSet[jjnewStateCnt++] = 24;\r
+                     jjstateSet[jjnewStateCnt++] = 26;\r
                   break;\r
-               case 26:\r
+               case 28:\r
                   if (curChar != 47)\r
                      break;\r
                   if (kind > 3)\r
                      kind = 3;\r
-                  jjCheckNAdd(27);\r
+                  jjCheckNAdd(29);\r
                   break;\r
-               case 27:\r
+               case 29:\r
                   if ((0xfffffffffffffbffL & l) == 0L)\r
                      break;\r
                   if (kind > 3)\r
                      kind = 3;\r
-                  jjCheckNAdd(27);\r
+                  jjCheckNAdd(29);\r
                   break;\r
-               case 28:\r
+               case 30:\r
                   if ((0x3ff000000000000L & l) == 0L)\r
                      break;\r
                   if (kind > 93)\r
                      kind = 93;\r
                   jjCheckNAddStates(0, 6);\r
                   break;\r
-               case 29:\r
+               case 31:\r
                   if ((0x3ff000000000000L & l) == 0L)\r
                      break;\r
                   if (kind > 93)\r
                      kind = 93;\r
-                  jjCheckNAdd(29);\r
+                  jjCheckNAdd(31);\r
                   break;\r
-               case 30:\r
+               case 32:\r
                   if ((0x3ff000000000000L & l) != 0L)\r
-                     jjCheckNAddTwoStates(30, 31);\r
+                     jjCheckNAddTwoStates(32, 33);\r
                   break;\r
-               case 31:\r
+               case 33:\r
                   if (curChar != 46)\r
                      break;\r
                   if (kind > 94)\r
                      kind = 94;\r
                   jjCheckNAddStates(19, 22);\r
                   break;\r
-               case 32:\r
+               case 34:\r
                   if ((0x3ff000000000000L & l) == 0L)\r
                      break;\r
                   if (kind > 94)\r
                      kind = 94;\r
                   jjCheckNAddStates(19, 22);\r
                   break;\r
-               case 34:\r
+               case 36:\r
                   if ((0x3ff000000000000L & l) == 0L)\r
                      break;\r
                   if (kind > 94)\r
                      kind = 94;\r
-                  jjCheckNAdd(34);\r
+                  jjCheckNAdd(36);\r
                   break;\r
-               case 35:\r
+               case 38:\r
                   if (curChar == 45)\r
-                     jjCheckNAdd(34);\r
+                     jjCheckNAdd(36);\r
                   break;\r
-               case 38:\r
+               case 39:\r
+                  if (curChar == 43)\r
+                     jjCheckNAdd(36);\r
+                  break;\r
+               case 41:\r
                   if ((0x3ff000000000000L & l) != 0L)\r
                      jjCheckNAddStates(23, 26);\r
                   break;\r
-               case 40:\r
+               case 43:\r
                   if ((0x3ff000000000000L & l) == 0L)\r
                      break;\r
                   if (kind > 94)\r
                      kind = 94;\r
-                  jjCheckNAdd(40);\r
+                  jjCheckNAdd(43);\r
                   break;\r
-               case 41:\r
+               case 45:\r
                   if (curChar == 45)\r
-                     jjCheckNAdd(40);\r
+                     jjCheckNAdd(43);\r
+                  break;\r
+               case 46:\r
+                  if (curChar == 43)\r
+                     jjCheckNAdd(43);\r
                   break;\r
                default : break;\r
             }\r
@@ -1167,11 +1188,11 @@ private int jjMoveNfa_0(int startState, int curPos)
                         kind = 92;\r
                   }\r
                   if (curChar == 69)\r
-                     jjCheckNAdd(9);\r
+                     jjCheckNAddTwoStates(18, 19);\r
                   else if (curChar == 101)\r
-                     jjCheckNAdd(9);\r
+                     jjCheckNAddTwoStates(18, 19);\r
                   break;\r
-               case 44:\r
+               case 48:\r
                case 2:\r
                   if ((0x7fffffe87fffffeL & l) == 0L)\r
                      break;\r
@@ -1201,58 +1222,58 @@ private int jjMoveNfa_0(int startState, int curPos)
                   if ((0x2000000020L & l) != 0L && kind > 92)\r
                      kind = 92;\r
                   break;\r
-               case 10:\r
+               case 11:\r
+                  if ((0x2000000020L & l) != 0L)\r
+                     jjstateSet[jjnewStateCnt++] = 12;\r
+                  break;\r
+               case 13:\r
                   if (curChar == 101)\r
-                     jjCheckNAdd(9);\r
+                     jjCheckNAddTwoStates(14, 15);\r
                   break;\r
-               case 11:\r
+               case 16:\r
                   if (curChar == 69)\r
-                     jjCheckNAdd(9);\r
-                  break;\r
-               case 14:\r
-                  if ((0x2000000020L & l) != 0L)\r
-                     jjstateSet[jjnewStateCnt++] = 15;\r
+                     jjCheckNAddTwoStates(14, 15);\r
                   break;\r
                case 17:\r
                   if (curChar == 101)\r
-                     jjCheckNAdd(16);\r
+                     jjCheckNAddTwoStates(18, 19);\r
                   break;\r
-               case 18:\r
+               case 20:\r
                   if (curChar == 69)\r
-                     jjCheckNAdd(16);\r
+                     jjCheckNAddTwoStates(18, 19);\r
                   break;\r
-               case 21:\r
                case 23:\r
+               case 25:\r
                   jjCheckNAddStates(12, 14);\r
                   break;\r
-               case 27:\r
+               case 29:\r
                   if (kind > 3)\r
                      kind = 3;\r
-                  jjstateSet[jjnewStateCnt++] = 27;\r
+                  jjstateSet[jjnewStateCnt++] = 29;\r
                   break;\r
-               case 33:\r
+               case 35:\r
                   if ((0x2000000020L & l) != 0L)\r
-                     jjstateSet[jjnewStateCnt++] = 34;\r
+                     jjstateSet[jjnewStateCnt++] = 36;\r
                   break;\r
-               case 36:\r
+               case 37:\r
                   if (curChar == 101)\r
-                     jjCheckNAdd(35);\r
+                     jjCheckNAddTwoStates(38, 39);\r
                   break;\r
-               case 37:\r
+               case 40:\r
                   if (curChar == 69)\r
-                     jjCheckNAdd(35);\r
+                     jjCheckNAddTwoStates(38, 39);\r
                   break;\r
-               case 39:\r
+               case 42:\r
                   if ((0x2000000020L & l) != 0L)\r
-                     jjstateSet[jjnewStateCnt++] = 40;\r
+                     jjstateSet[jjnewStateCnt++] = 43;\r
                   break;\r
-               case 42:\r
+               case 44:\r
                   if (curChar == 101)\r
-                     jjCheckNAdd(41);\r
+                     jjCheckNAddTwoStates(45, 46);\r
                   break;\r
-               case 43:\r
+               case 47:\r
                   if (curChar == 69)\r
-                     jjCheckNAdd(41);\r
+                     jjCheckNAddTwoStates(45, 46);\r
                   break;\r
                default : break;\r
             }\r
@@ -1271,17 +1292,17 @@ private int jjMoveNfa_0(int startState, int curPos)
                   if ((jjbitVec0[i2] & l2) != 0L)\r
                      jjCheckNAddStates(9, 11);\r
                   break;\r
-               case 21:\r
                case 23:\r
+               case 25:\r
                   if ((jjbitVec0[i2] & l2) != 0L)\r
                      jjCheckNAddStates(12, 14);\r
                   break;\r
-               case 27:\r
+               case 29:\r
                   if ((jjbitVec0[i2] & l2) == 0L)\r
                      break;\r
                   if (kind > 3)\r
                      kind = 3;\r
-                  jjstateSet[jjnewStateCnt++] = 27;\r
+                  jjstateSet[jjnewStateCnt++] = 29;\r
                   break;\r
                default : break;\r
             }\r
@@ -1294,15 +1315,15 @@ private int jjMoveNfa_0(int startState, int curPos)
          kind = 0x7fffffff;\r
       }\r
       ++curPos;\r
-      if ((i = jjnewStateCnt) == (startsAt = 44 - (jjnewStateCnt = startsAt)))\r
+      if ((i = jjnewStateCnt) == (startsAt = 48 - (jjnewStateCnt = startsAt)))\r
          return curPos;\r
       try { curChar = input_stream.readChar(); }\r
       catch(java.io.IOException e) { return curPos; }\r
    }\r
 }\r
 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
 };\r
 \r
 /** Token literal values. */\r
@@ -1341,8 +1362,8 @@ static final long[] jjtoSkip = {
    0xeL, 0x0L, 
 };\r
 protected SimpleCharStream input_stream;\r
-private final int[] jjrounds = new int[44];\r
-private final int[] jjstateSet = new int[88];\r
+private final int[] jjrounds = new int[48];\r
+private final int[] jjstateSet = new int[96];\r
 private final StringBuilder jjimage = new StringBuilder();\r
 private StringBuilder image = jjimage;\r
 private int jjimageLen;\r
@@ -1373,7 +1394,7 @@ private void ReInitRounds()
 {\r
    int i;\r
    jjround = 0x80000001;\r
-   for (i = 44; i-- > 0;)\r
+   for (i = 48; i-- > 0;)\r
       jjrounds[i] = 0x80000000;\r
 }\r
 \r
index 190ea2f86aa97874f7044825e92805dd3d47b0e5..839340c836286c052a48fc95e8e18be3c3ed53f8 100644 (file)
@@ -78,7 +78,7 @@ TOKEN:
 | <IDENT: ["a"-"z","A"-"Z","_"] (["a"-"z","A"-"Z","_",".", "0"-"9"])* >\r
 | <STRING: "\"" (~["\"", "\\", "\n"] | "\\" ~["\n"])* "\"">\r
     { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); }\r
-| <EXP: "e" | "e-" | "E" | "E-" >\r
+| <EXP: "e" | "e-" | "E" | "E-" | "E+" | "e+" >\r
 | <UNSIGNED_INTEGER: (["0"-"9"])+ >\r
 | <UNSIGNED_NUMBER:  \r
     ( <UNSIGNED_INTEGER> "." (<UNSIGNED_INTEGER>)? (<EXP> <UNSIGNED_INTEGER>)?\r
index 2fc5f9ce5e00c77b55e4b20a7179a72f980cbe65..c65900fd944a24e1ddbb7c09040be32c1f0d2826 100644 (file)
@@ -74,7 +74,7 @@ TOKEN:
 | <IDENT: ["a"-"z","A"-"Z","_"] (["a"-"z","A"-"Z","_",".", "0"-"9"])* >\r
 | <STRING: "\"" (~["\"", "\\", "\n"] | "\\" ~["\n"])* "\"">\r
     { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); }\r
-| <EXP: "e" | "e-" | "E" | "E-" >\r
+| <EXP: "e" | "e-" | "E" | "E-" | "E+" | "e+" >\r
 | <UNSIGNED_INTEGER: (["0"-"9"])+ >\r
 | <UNSIGNED_NUMBER:  \r
     ( <UNSIGNED_INTEGER> "." (<UNSIGNED_INTEGER>)? (<EXP> <UNSIGNED_INTEGER>)?\r
index 27f33a69b79ce4df484e41d2e5799fc52a170f3d..7ccc8155ee0f6d241d5a7de9963c365a045701ff 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2012, 2014 Association for Decentralized Information Management in\r
  * Industry THTH ry.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
@@ -28,6 +28,7 @@ import org.simantics.sysdyn.representation.utils.RepresentationUtils;
  * Variability of a variable in system dynamics models. \r
  * \r
  * @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
  *\r
  */\r
 public enum Variability {\r
@@ -164,23 +165,28 @@ public enum Variability {
      * @return Variabilty of a variable\r
      */\r
     static public Variability getVariability(IndependentVariable variable) {\r
-       if(RepresentationUtils.isPartOfGameExperiment(variable) && !(variable instanceof Stock)) {\r
-               \r
-               /* \r
-                * Game experiments cannot use as many parameter variables as normal experiments.\r
-                * If a parameter variable is changed, other parameter values depending on that \r
-                * parameter value are not automatically changed.\r
-                * \r
-                * Something of a hack: \r
-                * Allow variable references, if there are not incoming dependencies to the variable.\r
-                * This enables the use of derived variables for initial values of stocks.\r
-                */\r
-               if(variable.getIncomingDependencies() == null || variable.getIncomingDependencies().isEmpty())\r
-                       return getVariability(variable, true, null);\r
-               else\r
-                       return getVariability(variable, false, null);\r
-       } else {\r
-               return getVariability(variable, true, null);\r
+       try {\r
+                       if(RepresentationUtils.isPartOfGameExperiment(variable) && !(variable instanceof Stock)) {\r
+                               \r
+                               /* \r
+                                * Game experiments cannot use as many parameter variables as normal experiments.\r
+                                * If a parameter variable is changed, other parameter values depending on that \r
+                                * parameter value are not automatically changed.\r
+                                * \r
+                                * Something of a hack: \r
+                                * Allow variable references, if there are not incoming dependencies to the variable.\r
+                                * This enables the use of derived variables for initial values of stocks.\r
+                                */\r
+                               if(variable.getIncomingDependencies() == null || variable.getIncomingDependencies().isEmpty())\r
+                                       return getVariability(variable, true, null);\r
+                               else\r
+                                       return getVariability(variable, false, null);\r
+                       } else {\r
+                               return getVariability(variable, true, null);\r
+                       }\r
+       } catch (StackOverflowError e) {\r
+               // For circular dependencies; selecting continuous for a good guess.\r
+               return Variability.CONTINUOUS;\r
        }\r
     }\r
 \r
index 731151f15ca64aba870d2e774edb947ca6a63c98..4203b80a82d57c32231325554a5f75bcedf3dc96 100644 (file)
@@ -180,7 +180,9 @@ public class LoopUtils {
                                        dependingVariables.add(head);\r
                                }\r
                        }\r
-                       elementaryLoopItems.get(original).dependencies.addAll(dependingVariables);\r
+                       ElementaryLoopItem el = elementaryLoopItems.get(original);\r
+                       if (el != null)\r
+                               el.dependencies.addAll(dependingVariables);\r
                }\r
                \r
                // Fill the adjacent matrix\r