]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added time property for sysdyn variables. (refs #4280)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 10 May 2013 06:16:13 +0000 (06:16 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 10 May 2013 06:16:13 +0000 (06:16 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27361 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/TimeIndexVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java

index 8391e72f066700154363f6198b0a3e93a4e18917..6a309d35af0bb8e715aec6d5aa734f621b2d4a5a 100644 (file)
@@ -99,6 +99,8 @@ public class Functions {
                                return new ValuesIndexVariable(graph, context, name);\r
                        else if(TIMES.equals(property))\r
                                return new TimesIndexVariable(graph, context, name);\r
+            else if(TIME.equals(property))\r
+                return new TimeIndexVariable(graph, context, name);                    \r
                        else if(NAMES.equals(property))\r
                                return new NamesIndexVariable(graph, context, name);\r
                        else if(ACTIVE_DATASETS.equals(property))\r
index cee804c04e1a4017100ddedf49b899c9d061f7d6..65c34770d98bbacc27b54808f123734567b798c7 100644 (file)
@@ -4,6 +4,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
 import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;\r
 \r
 public class TimeIndexVariable extends IndexVariable<Double> {\r
@@ -17,8 +18,9 @@ public class TimeIndexVariable extends IndexVariable<Double> {
        public Double getValue() {\r
            if(experiment != null && experiment instanceof SysdynPlaybackExperiment)\r
                return ((SysdynPlaybackExperiment)experiment).getTime();\r
-           else\r
-               return null;\r
+           if(experiment != null && experiment instanceof SysdynGameExperiment)\r
+               return ((SysdynGameExperiment)experiment).getTime();\r
+           return null;\r
        }\r
 \r
        @Override\r
index c3c2e6f0d59dce795ea0ef5aed13a2e2dc94d8a0..b64c5265cbfc0753da4e4ab6ed2e686544f2bd53 100644 (file)
@@ -92,6 +92,17 @@ public class SysdynGameExperiment extends SysdynExperiment {
        public FMUControlJNI getFMUControl() {\r
                return control;\r
        }\r
+       \r
+       public double getTime() {\r
+           if(control != null) {\r
+               try {\r
+                   return control.getTime();\r
+               } catch (FMUJNIException e) {\r
+               }\r
+           }\r
+           return 0.0;\r
+       }\r
+       \r
 \r
        @Override\r
        public void init(ReadGraph g) {\r
@@ -353,7 +364,10 @@ public class SysdynGameExperiment extends SysdynExperiment {
                                monitor.worked(1);\r
                                \r
                                int stepNumber = 1;\r
-                               while(control.getTime() < (eTime - 1e-9) && !canceled) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers\r
+                               while(control.getTime() < eTime && !canceled) {\r
+                                   if(eTime - control.getTime() < stepLength)\r
+                                       control.setStepLength(eTime - control.getTime());\r
+                                   \r
                                        monitor.subTask("Simulate step (time = " + control.getTime() + ")");\r
                                        control.simulateStep();\r
                                        monitor.worked(1);\r