]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
FMU export does not include the universal "time" variable. Added a "time" variable...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 26 Apr 2012 11:56:34 +0000 (11:56 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 26 Apr 2012 11:56:34 +0000 (11:56 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24823 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org_simantics_modelica_fmi_FMUControlJNI.h
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java
org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java

index 526042dad16ed7820abffae90fe87dbde0f748db..4f118dc3f32042867577814bc6dfe9a83c7e09d7 100644 (file)
@@ -111,6 +111,14 @@ JNIEXPORT jobjectArray JNICALL Java_org_simantics_modelica_fmi_FMUControlJNI_get
 JNIEXPORT jstring JNICALL Java_org_simantics_modelica_fmi_FMUControlJNI_getLastErrorMessage_1\r
   (JNIEnv *, jobject);\r
 \r
+/*\r
+ * Class:     org_simantics_modelica_fmi_FMUControlJNI\r
+ * Method:    getRealValue_\r
+ * Signature: (Ljava/lang/String;)D\r
+ */\r
+JNIEXPORT jdouble JNICALL Java_org_simantics_modelica_fmi_FMUControlJNI_getRealValue_1\r
+  (JNIEnv *, jobject, jstring);\r
+\r
 #ifdef __cplusplus\r
 }\r
 #endif\r
index 62d13428287870c1fe76d0e01efabd7684f68d67..c7ed31f0912787394a2f1f0695ee4edbe7d15f3e 100644 (file)
@@ -155,6 +155,9 @@ public class SysdynProject extends AbstractProjectFeature {
             VirtualGraphSupport support = session.getService(VirtualGraphSupport.class);\r
 \r
             support.getWorkspacePersistent("experiments");\r
+            support.getWorkspacePersistent("profiles");\r
+//            support.getWorkspacePersistent("preferences");\r
+            support.getWorkspacePersistent("issues");\r
 \r
         } catch (DatabaseException e) {\r
 \r
index bc00a1885b46caeb997dd99533409da58aba52be..6d9c3579116bdd50356b5432ae23fe14210e0fe9 100644 (file)
@@ -89,10 +89,10 @@ TOKEN:
 | "break"              | "encapsulated" | "if"         | "output"      | "true"\r
 | "class"              | "end"                 | "import"      | "package" | "type"\r
 | "connect"    | "enumeration" | "in"          | "parameter" | "when"\r
-| "connector"  | "equation"    | "initial" | "partial" | "while"\r
+| "connector"  | "equation"    | /*"initial" |*/ "partial" | "while"\r
 | "constant"   | "expandable"  | "inner"       | "protected" | "within"\r
 | "constrainedby" | "extends"  | "input"       | "public"\r
-| "der"                | "external"    | "loop"        | "record"\r
+| /*"der"              |*/ "external"  | "loop"        | "record"\r
 | "(" | ")" | "{" | "}" | "[" | "]" | "." | ":" | ";" | ","\r
 | "<" | "<=" | ">" | ">=" | "==" | "<>"\r
 | "+" | "-" | ".+" | ".-"\r
index bcda5af70007b51cc7283534069f81cfc5d01ae9..6721ad51f48ceb054a8dfb7ce6f1ce7dd1d6ee42 100644 (file)
@@ -130,8 +130,6 @@ public class SysdynGameExperiment extends SysdynExperiment {
                                \r
                                // Initialize results\r
                                results.clear();\r
-                               results.put("time", new ArrayList<Double>());\r
-                               results.get("time").add(control.getTime());\r
                                \r
                                double[] initialValues = new double[subscription.length];\r
                                initialValues = control.getSubscribedResults(initialValues);\r
@@ -168,7 +166,6 @@ public class SysdynGameExperiment extends SysdynExperiment {
                        while(control.getTime() < (eTime - 1e-9)) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers\r
                                control.simulateStep();\r
                                results = control.getSubscribedResults(results);\r
-                               this.results.get("time").add(control.getTime());\r
                                for(int k = 0; k < subscription.length; k++) {\r
                                        this.results.get(subscription[k]).add(results[k]);\r
                                }\r
index 53ac48bd521e7705710a4ca6efbeeba325ffa6ac..ecbc5262ba4336b972c459e1f85a6956fcae3ce4 100644 (file)
@@ -26,6 +26,7 @@ import org.simantics.sysdyn.representation.Module;
 import org.simantics.sysdyn.representation.ModuleType;\r
 import org.simantics.sysdyn.representation.Stock;\r
 import org.simantics.sysdyn.representation.Variable;\r
+import org.simantics.sysdyn.representation.utils.RepresentationUtils;\r
 \r
 /**\r
  * ModelicaWriter writes Sysdyn model representations (objmap) into Modelica code.\r
@@ -64,6 +65,8 @@ public class ModelicaWriter {
      */\r
     private static void writeConfiguration(Configuration configuration, StringBuilder b) {\r
         String app;\r
+        \r
+        boolean game = RepresentationUtils.isGameExperimentActive();\r
 \r
         // Lists for storing different configuration elements\r
         ArrayList<IndependentVariable> variables = new ArrayList<IndependentVariable>();\r
@@ -130,6 +133,18 @@ public class ModelicaWriter {
             app = variable.getDeclaration();\r
             if (app != null) b.append(app);\r
         }\r
+        \r
+        \r
+        // Time variable for FMU (game) simulations\r
+        if(game) {\r
+               if(configuration.getModel() != null)\r
+                       // Parameter for model root. Values changed in FMU simulator\r
+                       b.append("parameter Real time = 0;\n");\r
+               else\r
+                       // Continuous variable for module instances\r
+                       b.append("Real time;\n");\r
+\r
+        }\r
 \r
         if(!modules.isEmpty()) {\r
             b.append("// Module definitions\n");\r
@@ -196,6 +211,13 @@ public class ModelicaWriter {
                     b.append("    " + moduleLabel + "." + input.getName() + " = " + input.getDefaultInputValue(moduleLabel) + ";\n");\r
             }\r
         }\r
+        \r
+        if(game && !modules.isEmpty()) {\r
+            b.append("// Time values for module\n");\r
+               for(Module m : modules) {\r
+                       b.append("    " + m.getName() + ".time = time;\n");\r
+               }\r
+        }\r
 \r
         b.append("end ").append(className).append(";\n\n");\r
 \r
index 4fce639cd6b7cd1c31fc90fa17b3dbd20111d3f9..8fb226a459a764f08ff061aa2c55879e46ff087c 100644 (file)
@@ -135,7 +135,7 @@ public enum Variability {
      * @return Variabilty of a variable\r
      */\r
     static public Variability getVariability(IndependentVariable variable) {\r
-       if(RepresentationUtils.isGameExperimentActive())\r
+       if(RepresentationUtils.isGameExperimentActive() && !(variable instanceof Stock))\r
                // FIXME: Game experiment may not be runnable even if normal experiments are. \r
                return getVariability(variable, false, null);\r
        else\r
index 085754f4a86b6b60647c2d9a6d9d829c1bf3896d..469f52fdd9e3454fcf370bdeea934051e5277f04 100644 (file)
@@ -139,6 +139,7 @@ public class StockExpression extends Expression {
                 }\r
             }\r
         } catch (ParseException e) {\r
+               e.printStackTrace();\r
         }\r
         return true;\r
     }\r
@@ -149,7 +150,7 @@ public class StockExpression extends Expression {
         if(useStartValue(variable))\r
             return null;\r
         // format the initial equation for modelica execution \r
-        String equation = FormatUtils.formatExpressionForModelica(variable, initialEquation);\r
+        String equation = FormatUtils.formatExpressionForModelica(variable, initialEquation, false);\r
        String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange());\r
        if(range == null)\r
                range = "";\r