]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Output interval created to ease the load for reading simulation results. Game experim...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 30 May 2012 08:49:43 +0000 (08:49 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 30 May 2012 08:49:43 +0000 (08:49 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25068 ac1ea38d-2e2b-0410-8846-a27921b304fc

16 files changed:
org.simantics.modelica/FMUSolution/FMUSolution.opensdf [deleted file]
org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java
org.simantics.modelica/src/org/simantics/modelica/data/Mat4Reader.java
org.simantics.modelica/src/org/simantics/modelica/data/MatSimulationResult.java
org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java
org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynInitKeys.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynPlaybackExperiment.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java

diff --git a/org.simantics.modelica/FMUSolution/FMUSolution.opensdf b/org.simantics.modelica/FMUSolution/FMUSolution.opensdf
deleted file mode 100644 (file)
index f8442e6..0000000
Binary files a/org.simantics.modelica/FMUSolution/FMUSolution.opensdf and /dev/null differ
index 1c3b1e2f228ced7380a40a40c48378ff9c840833..8787adf946066afc8014938caef0be77d971defb 100644 (file)
@@ -28,7 +28,7 @@ public class CSVSimulationResult extends SimulationResult {
         * Overridden method to support csv-formatted simulation results\r
         */\r
        @Override\r
-    public void read(InputStream stream) {\r
+    public void read(InputStream stream, int outputInterval) {\r
                errors.clear();\r
                \r
                // First line contains the variable names in format "name" (including quotes);\r
@@ -42,7 +42,7 @@ public class CSVSimulationResult extends SimulationResult {
                // Create lists for receiving values for each variable. Names still with quotes.\r
                for(String name : names) {\r
                        if(!name.isEmpty())\r
-                               valueMap.put(name, new DataSet(name, new double[numberOfTimeSteps], new double[numberOfTimeSteps]));\r
+                               valueMap.put(name, new DataSet(name, new double[numberOfLines], new double[numberOfLines]));\r
                }\r
 \r
                int row = 0;\r
index 0d89636832aed87990336826ff772a52ddf59969..ceafe6b0b097a3f971372654d7a2dc6f5d2936c0 100644 (file)
@@ -108,7 +108,14 @@ public class Mat4Reader {
         }\r
     }\r
 \r
-    public static Map<String, double[]> read(InputStream in) throws IOException {\r
+    /**\r
+     * \r
+     * @param in InputStream of a mat file\r
+     * @param outputInterval the interval of results to be read. 1 reads all time steps, 2 reads every other time step, etc... \r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public static Map<String, double[]> read(InputStream in, int outputInterval) throws IOException {\r
         Mat4Reader reader = new Mat4Reader(in);\r
         reader.readMatrix(); // Header\r
         StringMatrix names = (StringMatrix)reader.readMatrix(); // Variable names\r
@@ -131,13 +138,17 @@ public class Mat4Reader {
         for(int i=0;i<info.columns;++i) {\r
             if(infoData[i*4] != 2)\r
                 continue;\r
-            double[] v = new double[values.columns];\r
+            // If values.columns % outputInterval != 0, the value in the last time step would not be displayed without adding a +1;\r
+            int size = values.columns % outputInterval != 0 ? values.columns / outputInterval + 1 : values.columns; \r
+            double[] v = new double[size];\r
             int sc = infoData[i*4+1];\r
             int c = sc > 0 ? sc-1 : 1-sc;\r
             //System.out.println("i=" + i + ", sc=" + sc + ", c=" + c);\r
-            for(int j=0;j<v.length;++j)\r
-                v[j] = valueData[rows*j+c];\r
-            if(sc < 0)\r
+            for(int j=0;j<v.length;++j) {\r
+               int adjusted = j * outputInterval;\r
+               if(adjusted >= values.columns) adjusted = values.columns - 1;\r
+                v[j] = valueData[rows * adjusted + c];\r
+            } if(sc < 0)\r
                 for(int j=0;j<v.length;++j)\r
                     v[j] = -v[j];\r
             result.put(names.data[i], v);\r
index e563d514212efd1c1ba972ccfd6cfbb48f1c6052..73a67d12b3adf6068834f47b632c8b2ddc3d4549 100644 (file)
@@ -24,10 +24,10 @@ import java.util.Map;
 public class MatSimulationResult extends SimulationResult {\r
     \r
     @Override\r
-    public void read(InputStream stream) {\r
+    public void read(InputStream stream, int interval) {\r
         Map<String, double[]> valueMap = null;\r
         try {\r
-            valueMap =  Mat4Reader.read(stream);\r
+            valueMap =  Mat4Reader.read(stream, interval);\r
         } catch (IOException e) {\r
             e.printStackTrace();\r
             return;\r
index 725d7e71befd5a111ed8dac7901f7aa8a2c8b871..a21a21554827d8c8a402b844108e3b59ea4e8c39 100644 (file)
@@ -50,7 +50,7 @@ public class SimulationResult {
 \r
     protected List<DataSet> variables = new ArrayList<DataSet>();\r
     protected List<DataSet> initials = new ArrayList<DataSet>();\r
-    protected int numberOfTimeSteps = 0;\r
+    protected int numberOfLines = 0;\r
     \r
     /**\r
      * Private class used in displaying errors\r
@@ -262,36 +262,50 @@ public class SimulationResult {
     }\r
 \r
 \r
-    final static Pattern p1 = Pattern.compile("DataSet: ([^ ]*)");\r
+    \r
+    /**\r
+     * Read result file. Read all values in the result file.\r
+     *  \r
+     * @param file result file\r
+     * @throws FileNotFoundException\r
+     * @throws IOException\r
+     */\r
+    public void read(File file) throws FileNotFoundException, IOException {\r
+       read(file, 1);\r
+    }\r
+\r
 \r
     /**\r
      * Read result file\r
      * \r
      * @param file result file\r
+     * @param interval the interval of results to be read. 1 reads all time steps, 2 reads every other time step, etc...\r
      * @throws FileNotFoundException\r
      * @throws IOException\r
      */\r
-    public void read(File file) throws FileNotFoundException, IOException {\r
+    public void read(File file, int interval) throws FileNotFoundException, IOException {\r
         // First check the number of time steps\r
         FileReader fr = new FileReader(file);\r
         LineNumberReader  lnr = new LineNumberReader(fr);\r
         lnr.skip(Long.MAX_VALUE);\r
-        numberOfTimeSteps = lnr.getLineNumber() - 1; // minus the first row, which is for names\r
+        numberOfLines = lnr.getLineNumber() - 1; // minus the first row, which is for names\r
         lnr.close();\r
         fr.close();\r
 \r
         InputStream is = new FileInputStream(file);\r
-        read(is);\r
+        read(is, interval);\r
         is.close();\r
     }\r
 \r
-    \r
+    final static Pattern p1 = Pattern.compile("DataSet: ([^ ]*)");\r
+\r
     /**\r
      * Read result file. The basic implementation supports\r
      * plt-formatted results. Overridden to support other formats. \r
      * @param stream FileInputStream for the result file\r
+     * @param interval the interval of results to be read. 1 reads all time steps, 2 reads every other time step, etc...\r
      */\r
-    public void read(InputStream stream) {\r
+    public void read(InputStream stream, int outputInterval) {\r
         while(true) {\r
             String line = getLine(stream);\r
             if(line == null)\r
@@ -307,8 +321,8 @@ public class SimulationResult {
                 return;\r
             String name = matcher.group(1);\r
 \r
-            double[] dtimes = new double[numberOfTimeSteps];\r
-            double[] dvalues = new double[numberOfTimeSteps];\r
+            double[] dtimes = new double[numberOfLines];\r
+            double[] dvalues = new double[numberOfLines];\r
             int i = 0;\r
             while(true) {\r
                 String line = getLine(stream);\r
index efe3183fb9e739f23e8abc2e11d436338108becb..185aa2016d61749af563452940037e17ea6eb9a0 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index 54086f8a7641f8498cf7cb66c3e5140c363c535c..9584de37c0429f9f399df38923116e466868edd3 100644 (file)
@@ -33,6 +33,7 @@ SYSDYN.SharedModuleOntolofgy <T L0.Ontology
 SYSDYN.SysdynModel <T MOD.StructuralModel
     >-- SYSDYN.SysdynModel.startTime --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.SysdynModel.stopTime --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
+    >-- SYSDYN.SysdynModel.simulationStepLength --> L0.Double <R L0.HasProperty : L0.FunctionalRelation    
     >-- SYSDYN.SysdynModel.outputInterval --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.SysdynModel.tolerance --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.SysdynModel.solver --> L0.String <R L0.HasProperty : L0.FunctionalRelation
index d4ebd8ce13ec4404c754ddc316708117e0854f4b..c4f222e9ec16397c94f9afdb39f9b184071a948f 100644 (file)
@@ -284,6 +284,8 @@ public class SysdynResource {
     public final Resource SysdynModel;\r
     public final Resource SysdynModel_outputInterval;\r
     public final Resource SysdynModel_outputInterval_Inverse;\r
+    public final Resource SysdynModel_simulationStepLength;\r
+    public final Resource SysdynModel_simulationStepLength_Inverse;\r
     public final Resource SysdynModel_solver;\r
     public final Resource SysdynModel_solver_Inverse;\r
     public final Resource SysdynModel_startTime;\r
@@ -634,6 +636,8 @@ public class SysdynResource {
         public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.1/SysdynModel";\r
         public static final String SysdynModel_outputInterval = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/outputInterval";\r
         public static final String SysdynModel_outputInterval_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/outputInterval/Inverse";\r
+        public static final String SysdynModel_simulationStepLength = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/simulationStepLength";\r
+        public static final String SysdynModel_simulationStepLength_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/simulationStepLength/Inverse";\r
         public static final String SysdynModel_solver = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/solver";\r
         public static final String SysdynModel_solver_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/solver/Inverse";\r
         public static final String SysdynModel_startTime = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/startTime";\r
@@ -994,6 +998,8 @@ public class SysdynResource {
         SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
         SysdynModel_outputInterval = getResourceOrNull(graph, URIs.SysdynModel_outputInterval);\r
         SysdynModel_outputInterval_Inverse = getResourceOrNull(graph, URIs.SysdynModel_outputInterval_Inverse);\r
+        SysdynModel_simulationStepLength = getResourceOrNull(graph, URIs.SysdynModel_simulationStepLength);\r
+        SysdynModel_simulationStepLength_Inverse = getResourceOrNull(graph, URIs.SysdynModel_simulationStepLength_Inverse);\r
         SysdynModel_solver = getResourceOrNull(graph, URIs.SysdynModel_solver);\r
         SysdynModel_solver_Inverse = getResourceOrNull(graph, URIs.SysdynModel_solver_Inverse);\r
         SysdynModel_startTime = getResourceOrNull(graph, URIs.SysdynModel_startTime);\r
index aae0b0ef51f9d66cbcf9b48136652bb0114147f9..27e3b551bdaad5b75e0fee2ade08acb214eb6259 100644 (file)
@@ -61,17 +61,16 @@ public class PlaybackSliderContribution extends ToolBarContributionItem {
                 return;\r
             spe = (SysdynPlaybackExperiment)experiment;\r
 \r
-            Double[] numbers = new Double[3];\r
+            Double[] numbers = new Double[2];\r
             try {\r
                 numbers = SimanticsUI.getSession().syncRequest(new Read<Double[]>() {\r
                     @Override\r
                     public Double[] perform(ReadGraph graph) throws DatabaseException {\r
-                        Double[] numbers = new Double[3];\r
+                        Double[] numbers = new Double[2];\r
                         Resource model = spe.getModel();\r
                         SysdynResource sr = SysdynResource.getInstance(graph);\r
                         numbers[0] = graph.getRelatedValue(model, sr.SysdynModel_startTime);\r
                         numbers[1] = graph.getRelatedValue(model, sr.SysdynModel_stopTime);\r
-                        numbers[2] = graph.getPossibleRelatedValue(model, sr.SysdynModel_outputInterval);\r
                         return numbers;\r
                     }\r
                 });\r
index f0d9b324fefcda81909066796022850065cd1a05..96dea950c51521d1b01e96885faede1d3aa72034 100644 (file)
@@ -120,12 +120,22 @@ public class ConfigurationTab extends LabelPropertyTabContributor {
         label = new Label(composite, SWT.NONE);\r
         label.setText("Step length\n(empty = default)");\r
 \r
+        TrackedText stepLength = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT);\r
+        stepLength.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.SysdynModel_simulationStepLength));\r
+        stepLength.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SysdynModel_simulationStepLength));\r
+        stepLength.setInputValidator(new DoubleValidator());\r
+        GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(stepLength.getWidget());\r
+        \r
+        label = new Label(composite, SWT.NONE);\r
+        label.setText("Output interval\n(empty = all steps)");\r
+\r
         TrackedText outputInterval = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT);\r
         outputInterval.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.SysdynModel_outputInterval));\r
         outputInterval.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SysdynModel_outputInterval));\r
         outputInterval.setInputValidator(new DoubleValidator());\r
         GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(outputInterval.getWidget());\r
         \r
+        \r
         label = new Label(composite, SWT.NONE);\r
         label.setText("Method");\r
         \r
index 9b0d515c1602ec66670c3be8a0ac87a2f9d7bef3..17d8bac1be91b6f6ae2ae2595650f4f2cd8d7d9e 100644 (file)
@@ -49,9 +49,9 @@ import org.simantics.utils.datastructures.Pair;
  */\r
 public class HistoryDatasetResult extends SimulationResult {\r
     @Override\r
-    public void read(File file) {} // Do nothing\r
+    public void read(File file, int interval) {} // Do nothing\r
     @Override\r
-    public void read(InputStream stream) {} // Do nothing\r
+    public void read(InputStream stream, int interval) {} // Do nothing\r
 \r
     private boolean disposed;\r
 \r
index c82649c38b5735a0e2c66a9de16969843f00e7ae..d0e8f385ec0942e17f05c82911fa019de90da30c 100644 (file)
@@ -196,17 +196,22 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                Model model = configuration.getModel();\r
                Double startTime = model.getStartTime();\r
                Double stopTime = model.getStopTime();\r
-               Double numberOfIntervals = model.getOutputInterval();\r
                inits.put(SysdynInitKeys.START_VALUE, startTime.toString());\r
                inits.put(SysdynInitKeys.STOP_VALUE, stopTime.toString());\r
                String outputFormat = "\"mat\"";\r
                inits.put(SysdynInitKeys.OUTPUT_FORMAT, outputFormat);\r
-               if(numberOfIntervals != null) {\r
-                       inits.put(SysdynInitKeys.STEP_VALUE, numberOfIntervals.toString());\r
-                       inits.put(SysdynInitKeys.NUMBER_OF_INTERVALS, "" + ((int)((stopTime - startTime) / numberOfIntervals)));\r
+               \r
+               Double simulationStepLength = model.getSimulationStepLength();\r
+               if(simulationStepLength != null) {\r
+                       inits.put(SysdynInitKeys.STEP_VALUE, simulationStepLength.toString());\r
+                       inits.put(SysdynInitKeys.NUMBER_OF_INTERVALS, "" + ((int)((stopTime - startTime) / simulationStepLength)));\r
                } else {\r
                        inits.put(SysdynInitKeys.STEP_VALUE, "" + (stopTime - startTime) / 500);\r
                }\r
+               \r
+               Double outputInterval = model.getOutputInterval();\r
+               inits.put(SysdynInitKeys.OUTPUT_INTERVAL, outputInterval != null ? outputInterval.toString() : inits.get(SysdynInitKeys.STEP_VALUE));\r
+               \r
                String method = "\"" + model.getSolver() + "\"";\r
                inits.put(SysdynInitKeys.METHOD, method);\r
                if(model.getTolerance() != null)\r
@@ -251,7 +256,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                                );\r
                ModelicaManager.printProcessOutput(process, monitor);\r
 \r
-               Thread resultThread = getResultThread(simulationLocation, monitor, progressMonitor);\r
+               Thread resultThread = getResultThread(simulationLocation, inits, monitor, progressMonitor);\r
                resultThread.run();\r
 \r
                process = null;\r
@@ -260,11 +265,12 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
        /**\r
         * Get a thread for reading and saving reuslts from a normal simulation\r
         * @param simulationLocation\r
+        * @param inits \r
         * @param monitor\r
         * @param progressMonitor\r
         * @return\r
         */\r
-       protected Thread getResultThread(final SimulationLocation simulationLocation, final IModelicaMonitor monitor, final IProgressMonitor progressMonitor) {\r
+       protected Thread getResultThread(final SimulationLocation simulationLocation, final HashMap<String, String> inits, final IModelicaMonitor monitor, final IProgressMonitor progressMonitor) {\r
                return new Thread() {\r
                        @Override\r
                        public void run() {\r
@@ -282,7 +288,23 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                                                        result = new SimulationResult();\r
                                                else\r
                                                        result = new MatSimulationResult(); // The latest format\r
-                                               result.read(simulationLocation.outputFile);\r
+                                               \r
+                                               \r
+                                               // The interval of results saved. Every result? Every other result? etc...\r
+                                               int outIntervalInt = 1;\r
+                                               String outputInterval = inits.get(SysdynInitKeys.OUTPUT_INTERVAL);\r
+                                               if(outputInterval != null) {\r
+                                                       String stepTime = inits.get(SysdynInitKeys.STEP_VALUE);\r
+                                                       \r
+                                                       Double step = Double.parseDouble(stepTime);\r
+                                                       Double outInterval = Double.parseDouble(outputInterval);\r
+                                                       \r
+                                                       double nearest = roundUp(outInterval, step);\r
+                                                       outIntervalInt = (int)(nearest / step);\r
+                                                       if(outIntervalInt <= 0) outIntervalInt = 1;\r
+                                               }\r
+                                               \r
+                                               result.read(simulationLocation.outputFile, outIntervalInt);\r
                                                result.readInits(simulationLocation.initFile);\r
                                                result.filter();\r
                                                sysdynModel.getSysdynResult().setResult(result);\r
@@ -305,6 +327,17 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                        }\r
                };\r
        }\r
+       \r
+       protected static double roundUp(double numToRound, double multiple) {  \r
+               if(multiple == 0) {\r
+                       return numToRound;  \r
+               }\r
+               double remainder = numToRound % multiple; \r
+               if (remainder == 0) {\r
+                       return numToRound; \r
+               }\r
+               return numToRound + multiple - remainder; \r
+       }  \r
 \r
 \r
        /**\r
@@ -340,11 +373,11 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
        \r
        protected void storeImportantInits(HashMap<String, String> inits) {\r
                previousImportantInits.clear();\r
-               previousImportantInits.put("start value", inits.get(SysdynInitKeys.START_VALUE));\r
-               previousImportantInits.put("stop value", inits.get(SysdynInitKeys.STOP_VALUE));\r
-               previousImportantInits.put("method", inits.get(SysdynInitKeys.METHOD));\r
-               previousImportantInits.put("outputFormat", inits.get(SysdynInitKeys.OUTPUT_FORMAT));\r
-               previousImportantInits.put("variableFilter", inits.get(SysdynInitKeys.VARIABLE_FILTER));\r
+               previousImportantInits.put(SysdynInitKeys.START_VALUE, inits.get(SysdynInitKeys.START_VALUE));\r
+               previousImportantInits.put(SysdynInitKeys.STOP_VALUE, inits.get(SysdynInitKeys.STOP_VALUE));\r
+               previousImportantInits.put(SysdynInitKeys.METHOD, inits.get(SysdynInitKeys.METHOD));\r
+               previousImportantInits.put(SysdynInitKeys.OUTPUT_FORMAT, inits.get(SysdynInitKeys.OUTPUT_FORMAT));\r
+               previousImportantInits.put(SysdynInitKeys.VARIABLE_FILTER, inits.get(SysdynInitKeys.VARIABLE_FILTER));\r
        }\r
 \r
        /**\r
index 8d82b12f7aacbf39b815e8ff75811766daacbebd..8bb2e09cd376813610eaeec5d32c9a210f604b03 100644 (file)
@@ -33,7 +33,7 @@ import org.simantics.modelica.fmi.FMUControlJNI;
 import org.simantics.modelica.fmi.FMUJNIException;\r
 import org.simantics.simulation.experiment.ExperimentState;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.datastructures.Triple;\r
 \r
 /**\r
  * Game experiment\r
@@ -47,9 +47,11 @@ public class SysdynGameExperiment extends SysdynExperiment {
        private HashMap<String, ArrayList<Double>> results;\r
        private double stepLength = DEFAULT_STEP_LENGTH;\r
        private double stepDuration = DEFAULT_STEP_DURATION;\r
+       private int savePer = 1;\r
        \r
        public static double DEFAULT_STEP_DURATION = 1.0;\r
        public static double DEFAULT_STEP_LENGTH        = 0.1;\r
+       public static int DEFAULT_OUTPUT_INTERVAL       = 1;\r
        \r
        public SysdynGameExperiment(Resource experiment, Resource model) {\r
                super(experiment, model);\r
@@ -71,6 +73,11 @@ public class SysdynGameExperiment extends SysdynExperiment {
                this.stepLength = stepLength;\r
        }\r
        \r
+       public void setOutputInterval(int interval) {\r
+               this.savePer = interval;\r
+       }\r
+\r
+       \r
        public FMUControlJNI getFMUControl() {\r
                return control;\r
        }\r
@@ -84,23 +91,33 @@ public class SysdynGameExperiment extends SysdynExperiment {
                \r
                results = new HashMap<String, ArrayList<Double>>();\r
                \r
-               g.asyncRequest(new Read<Pair<Double, Double>>() {\r
+               g.asyncRequest(new Read<Triple<Double, Double, Double>>() {\r
 \r
                        @Override\r
-                       public Pair<Double, Double> perform(ReadGraph graph)\r
+                       public Triple<Double, Double, Double> perform(ReadGraph graph)\r
                                        throws DatabaseException {\r
                                SysdynResource sr = SysdynResource.getInstance(graph);\r
                                Double stepDuration = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepDuration);\r
-                               Double stepLength =graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepLength);\r
-                               return new Pair<Double, Double>(stepDuration, stepLength);\r
+                               Double stepLength = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepLength);\r
+                               Double outputInterval = graph.getPossibleRelatedValue(model, sr.SysdynModel_outputInterval);\r
+                               return new Triple<Double, Double, Double>(stepDuration, stepLength, outputInterval);\r
                        }\r
-               }, new AsyncListener<Pair<Double, Double>>() {\r
+               }, new AsyncListener<Triple<Double, Double, Double>>() {\r
 \r
                        @Override\r
                        public void execute(AsyncReadGraph graph,\r
-                                       Pair<Double, Double> result) {\r
+                                       Triple<Double, Double, Double> result) {\r
                                setStepDuration(result.first != null ? result.first : DEFAULT_STEP_DURATION);\r
                                setStepLength(result.second != null ? result.second : DEFAULT_STEP_LENGTH);\r
+                               \r
+                               if(result.third == null) {\r
+                                       setOutputInterval(DEFAULT_OUTPUT_INTERVAL);\r
+                               } else {\r
+                                       double nearest = roundUp(result.third, getStepLength());\r
+                                       int interval = (int)(nearest / getStepLength());\r
+                                       if(interval <= 0) interval = 1;\r
+                                       setOutputInterval(interval);\r
+                               }\r
                        }\r
 \r
                        @Override\r
@@ -108,6 +125,7 @@ public class SysdynGameExperiment extends SysdynExperiment {
                                throwable.printStackTrace();\r
                                setStepDuration(DEFAULT_STEP_DURATION);\r
                                setStepLength(DEFAULT_STEP_LENGTH);\r
+                               setOutputInterval(DEFAULT_OUTPUT_INTERVAL);\r
                        }\r
 \r
                        @Override\r
@@ -219,7 +237,6 @@ public class SysdynGameExperiment extends SysdynExperiment {
 \r
                @Override\r
                protected IStatus run(IProgressMonitor monitor) {\r
-                       \r
                        int nSteps = (int)(duration / stepLength); \r
                        int work = 1 + nSteps * 3 + 2; // initialization + number of steps * number of phases per step + set result + call result listeners \r
                        \r
@@ -241,20 +258,24 @@ public class SysdynGameExperiment extends SysdynExperiment {
                                double[] results = new double[subscription.length];\r
                                \r
                                monitor.worked(1);\r
-\r
+                               \r
+                               int stepNumber = 1;\r
                                while(control.getTime() < (eTime - 1e-9)) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers\r
                                        monitor.subTask("Simulate step (time = " + control.getTime() + ")");\r
                                        control.simulateStep();\r
                                        monitor.worked(1);\r
                                        \r
-                                       monitor.subTask("Get results (time = " + control.getTime() + ")");\r
-                                       results = control.getSubscribedResults(results);\r
-                                       monitor.worked(1);\r
-\r
-                                       monitor.subTask("Save results (time = " + control.getTime() + ")");\r
-                                       for(int k = 0; k < subscription.length; k++) {\r
-                                               SysdynGameExperiment.this.results.get(subscription[k]).add(results[k]);\r
+                                       if(stepNumber % savePer == 0) {\r
+                                               monitor.subTask("Get results (time = " + control.getTime() + ")");\r
+                                               results = control.getSubscribedResults(results);\r
+                                               monitor.worked(1);\r
+\r
+                                               monitor.subTask("Save results (time = " + control.getTime() + ")");\r
+                                               for(int k = 0; k < subscription.length; k++) {\r
+                                                       SysdynGameExperiment.this.results.get(subscription[k]).add(results[k]);\r
+                                               }\r
                                        }\r
+                                       stepNumber++;\r
                                        monitor.worked(1);\r
                                }\r
                                \r
@@ -268,7 +289,6 @@ public class SysdynGameExperiment extends SysdynExperiment {
                        } catch (FMUJNIException e) {\r
                                System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage());\r
                        }\r
-                       \r
                        return Status.OK_STATUS;\r
                }\r
        }\r
index 3d405ebd2ea816ee2ccfeeac0b384a5bf0078960..65168bcb5a2f328214a180806374b9a1f92823c6 100644 (file)
@@ -26,5 +26,6 @@ public class SysdynInitKeys {
        public static String METHOD                             = "method";\r
        public static String TOLERANCE                          = "tolerance";\r
        public static String VARIABLE_FILTER            = "variableFilter";\r
+       public static String OUTPUT_INTERVAL            = "outputInterval";\r
 \r
 }\r
index 5c8f955cfa3623810c697eb33d63613e8cab6ade..45cebeab791a41245abeef62a0857d85f1ea4d1e 100644 (file)
@@ -232,7 +232,6 @@ public class SysdynPlaybackExperiment extends SysdynExperiment implements IDynam
         SysdynResource sr = SysdynResource.getInstance(graph);\r
         numbers[0] = graph.getRelatedValue(model, sr.SysdynModel_startTime);\r
         numbers[1] = graph.getRelatedValue(model, sr.SysdynModel_stopTime);\r
-        numbers[2] = graph.getPossibleRelatedValue(model, sr.SysdynModel_outputInterval);\r
 \r
         PlaybackConfiguration config = new PlaybackConfiguration();\r
         config.simulationDuration = numbers[1] - numbers[0] - time;\r
index 3cb5be55770eeea45a3f971c43425f07d46c0f9f..6e22190f2d3cf0d8a2d75bf60cdc48130a3e2cab 100644 (file)
@@ -39,6 +39,9 @@ public class Model {
 \r
     @RelatedValue(SysdynResource.URIs.SysdynModel_outputInterval)\r
     private Double outputInterval;\r
+    \r
+    @RelatedValue(SysdynResource.URIs.SysdynModel_simulationStepLength)\r
+    private Double stepLength;\r
 \r
     @RelatedValue(SysdynResource.URIs.SysdynModel_tolerance)\r
     private Double tolerance;\r
@@ -83,13 +86,20 @@ public class Model {
     }\r
 \r
     /**\r
-     * Result output interval\r
+     * Simulation output interval\r
      * @return\r
      */\r
     public Double getOutputInterval() {\r
         return outputInterval;\r
     }\r
 \r
+    /**\r
+     * Simulation step length\r
+     * @return\r
+     */\r
+    public Double getSimulationStepLength() {\r
+       return stepLength;\r
+    }\r
     /**\r
      * \r
      * @return Tolerance for simulation engine\r