From 2c85c2807c2730f8a039f5b31797fdf341cb07b4 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 26 Apr 2012 11:56:34 +0000 Subject: [PATCH] FMU export does not include the universal "time" variable. Added a "time" variable to each module instance. The same expression thus work with fmu and normal simulation. (refs #3398) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24823 ac1ea38d-2e2b-0410-8846-a27921b304fc --- ...org_simantics_modelica_fmi_FMUControlJNI.h | 8 +++++++ .../sysdyn/ui/project/SysdynProject.java | 3 +++ .../expressionParser/ExpressionParser.jj | 4 ++-- .../sysdyn/manager/SysdynGameExperiment.java | 3 --- .../sysdyn/modelica/ModelicaWriter.java | 22 +++++++++++++++++++ .../sysdyn/representation/Variability.java | 2 +- .../expressions/StockExpression.java | 3 ++- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/org.simantics.modelica/src/org_simantics_modelica_fmi_FMUControlJNI.h b/org.simantics.modelica/src/org_simantics_modelica_fmi_FMUControlJNI.h index 526042da..4f118dc3 100644 --- a/org.simantics.modelica/src/org_simantics_modelica_fmi_FMUControlJNI.h +++ b/org.simantics.modelica/src/org_simantics_modelica_fmi_FMUControlJNI.h @@ -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 (JNIEnv *, jobject); +/* + * Class: org_simantics_modelica_fmi_FMUControlJNI + * Method: getRealValue_ + * Signature: (Ljava/lang/String;)D + */ +JNIEXPORT jdouble JNICALL Java_org_simantics_modelica_fmi_FMUControlJNI_getRealValue_1 + (JNIEnv *, jobject, jstring); + #ifdef __cplusplus } #endif diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index 62d13428..c7ed31f0 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -155,6 +155,9 @@ public class SysdynProject extends AbstractProjectFeature { VirtualGraphSupport support = session.getService(VirtualGraphSupport.class); support.getWorkspacePersistent("experiments"); + support.getWorkspacePersistent("profiles"); +// support.getWorkspacePersistent("preferences"); + support.getWorkspacePersistent("issues"); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj index bc00a188..6d9c3579 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj @@ -89,10 +89,10 @@ TOKEN: | "break" | "encapsulated" | "if" | "output" | "true" | "class" | "end" | "import" | "package" | "type" | "connect" | "enumeration" | "in" | "parameter" | "when" -| "connector" | "equation" | "initial" | "partial" | "while" +| "connector" | "equation" | /*"initial" |*/ "partial" | "while" | "constant" | "expandable" | "inner" | "protected" | "within" | "constrainedby" | "extends" | "input" | "public" -| "der" | "external" | "loop" | "record" +| /*"der" |*/ "external" | "loop" | "record" | "(" | ")" | "{" | "}" | "[" | "]" | "." | ":" | ";" | "," | "<" | "<=" | ">" | ">=" | "==" | "<>" | "+" | "-" | ".+" | ".-" diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java index bcda5af7..6721ad51 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -130,8 +130,6 @@ public class SysdynGameExperiment extends SysdynExperiment { // Initialize results results.clear(); - results.put("time", new ArrayList()); - results.get("time").add(control.getTime()); double[] initialValues = new double[subscription.length]; initialValues = control.getSubscribedResults(initialValues); @@ -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 control.simulateStep(); results = control.getSubscribedResults(results); - this.results.get("time").add(control.getTime()); for(int k = 0; k < subscription.length; k++) { this.results.get(subscription[k]).add(results[k]); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java index 53ac48bd..ecbc5262 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -26,6 +26,7 @@ import org.simantics.sysdyn.representation.Module; import org.simantics.sysdyn.representation.ModuleType; import org.simantics.sysdyn.representation.Stock; import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.utils.RepresentationUtils; /** * ModelicaWriter writes Sysdyn model representations (objmap) into Modelica code. @@ -64,6 +65,8 @@ public class ModelicaWriter { */ private static void writeConfiguration(Configuration configuration, StringBuilder b) { String app; + + boolean game = RepresentationUtils.isGameExperimentActive(); // Lists for storing different configuration elements ArrayList variables = new ArrayList(); @@ -130,6 +133,18 @@ public class ModelicaWriter { app = variable.getDeclaration(); if (app != null) b.append(app); } + + + // Time variable for FMU (game) simulations + if(game) { + if(configuration.getModel() != null) + // Parameter for model root. Values changed in FMU simulator + b.append("parameter Real time = 0;\n"); + else + // Continuous variable for module instances + b.append("Real time;\n"); + + } if(!modules.isEmpty()) { b.append("// Module definitions\n"); @@ -196,6 +211,13 @@ public class ModelicaWriter { b.append(" " + moduleLabel + "." + input.getName() + " = " + input.getDefaultInputValue(moduleLabel) + ";\n"); } } + + if(game && !modules.isEmpty()) { + b.append("// Time values for module\n"); + for(Module m : modules) { + b.append(" " + m.getName() + ".time = time;\n"); + } + } b.append("end ").append(className).append(";\n\n"); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java index 4fce639c..8fb226a4 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java @@ -135,7 +135,7 @@ public enum Variability { * @return Variabilty of a variable */ static public Variability getVariability(IndependentVariable variable) { - if(RepresentationUtils.isGameExperimentActive()) + if(RepresentationUtils.isGameExperimentActive() && !(variable instanceof Stock)) // FIXME: Game experiment may not be runnable even if normal experiments are. return getVariability(variable, false, null); else diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java index 085754f4..469f52fd 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java @@ -139,6 +139,7 @@ public class StockExpression extends Expression { } } } catch (ParseException e) { + e.printStackTrace(); } return true; } @@ -149,7 +150,7 @@ public class StockExpression extends Expression { if(useStartValue(variable)) return null; // format the initial equation for modelica execution - String equation = FormatUtils.formatExpressionForModelica(variable, initialEquation); + String equation = FormatUtils.formatExpressionForModelica(variable, initialEquation, false); String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange()); if(range == null) range = ""; -- 2.47.1