]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #6860 Sysdyn update site on top of Simantics Desktop
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 12 Dec 2016 11:18:53 +0000 (11:18 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 12 Dec 2016 11:18:53 +0000 (11:18 +0000)
Share project "org.simantics.sysdyn.omsolver" into "https://www.simantics.org/svn/simantics"

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/git@33415 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.omsolver/.classpath [new file with mode: 0644]
org.simantics.sysdyn.omsolver/.project [new file with mode: 0644]
org.simantics.sysdyn.omsolver/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
org.simantics.sysdyn.omsolver/META-INF/MANIFEST.MF [new file with mode: 0644]
org.simantics.sysdyn.omsolver/build.properties [new file with mode: 0644]
org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/Activator.java [new file with mode: 0644]
org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/GameExperiment.java [new file with mode: 0644]
org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/GameExperimentFactory.java [new file with mode: 0644]
org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/ModelicaSolver.java [new file with mode: 0644]

diff --git a/org.simantics.sysdyn.omsolver/.classpath b/org.simantics.sysdyn.omsolver/.classpath
new file mode 100644 (file)
index 0000000..b862a29
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>\r
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
+       <classpathentry kind="src" path="src"/>\r
+       <classpathentry kind="output" path="bin"/>\r
+</classpath>\r
diff --git a/org.simantics.sysdyn.omsolver/.project b/org.simantics.sysdyn.omsolver/.project
new file mode 100644 (file)
index 0000000..29ec02d
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>org.simantics.sysdyn.omsolver</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>org.eclipse.jdt.core.javabuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.ManifestBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.SchemaBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>org.eclipse.pde.PluginNature</nature>\r
+               <nature>org.eclipse.jdt.core.javanature</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/org.simantics.sysdyn.omsolver/.settings/org.eclipse.jdt.core.prefs b/org.simantics.sysdyn.omsolver/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..295926d
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8\r
+org.eclipse.jdt.core.compiler.compliance=1.8\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.8\r
diff --git a/org.simantics.sysdyn.omsolver/META-INF/MANIFEST.MF b/org.simantics.sysdyn.omsolver/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..c0ab4de
--- /dev/null
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Open Modelica solver
+Bundle-SymbolicName: org.simantics.sysdyn.omsolver
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Require-Bundle: org.simantics.sysdyn;bundle-version="1.9.0",
+ org.eclipse.osgi;bundle-version="3.10.102",
+ org.simantics.fmu;bundle-version="1.1.0",
+ org.simantics;bundle-version="1.0.0",
+ org.simantics.modelica;bundle-version="1.1.0",
+ org.simantics.modeling;bundle-version="1.1.1",
+ org.simantics.simulation;bundle-version="1.1.0"
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.simantics.sysdyn.omsolver.Activator
diff --git a/org.simantics.sysdyn.omsolver/build.properties b/org.simantics.sysdyn.omsolver/build.properties
new file mode 100644 (file)
index 0000000..41eb6ad
--- /dev/null
@@ -0,0 +1,4 @@
+source.. = src/\r
+output.. = bin/\r
+bin.includes = META-INF/,\\r
+               .\r
diff --git a/org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/Activator.java b/org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/Activator.java
new file mode 100644 (file)
index 0000000..9391e60
--- /dev/null
@@ -0,0 +1,70 @@
+package org.simantics.sysdyn.omsolver;\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.osgi.framework.BundleActivator;\r
+import org.osgi.framework.BundleContext;\r
+import org.simantics.fmu.FMUControlJNI;\r
+import org.simantics.sysdyn.solver.SolverSettings.SolverType;\r
+import org.simantics.sysdyn.solver.Solvers;\r
+import org.simantics.utils.FileUtils;\r
+\r
+public class Activator implements BundleActivator {\r
+\r
+       private static BundleContext context;\r
+\r
+       static BundleContext getContext() {\r
+               return context;\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)\r
+        */\r
+       public void start(BundleContext bundleContext) throws Exception {\r
+               Activator.context = bundleContext;\r
+               clearFMUTempDirectory();\r
+               Solvers.registerGameExperimentFactory(SolverType.OPENMODELICA, new GameExperimentFactory());\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
+        */\r
+       public void stop(BundleContext bundleContext) throws Exception {\r
+               Solvers.unregisterGameExperimentFactory(SolverType.OPENMODELICA);\r
+               clearFMUTempDirectory();\r
+               Activator.context = null;\r
+       }\r
+\r
+       /**\r
+        * Clears fmu temp directory. This directory hosts\r
+        * fmu files for game experiments. In normal situations\r
+        * experiments clean up their temp files, but for example\r
+        * a system crash may leave files to temp directory. \r
+        */\r
+       private void clearFMUTempDirectory() {\r
+               // Find commone "TEMP/fmu" directory\r
+               File commonDir = new File(FMUControlJNI.TEMP_FMU_COMMON_DIRECTORY);\r
+               if(commonDir != null && commonDir.isDirectory()) {\r
+\r
+                       // List all files and directories in "TEMP/fmu" \r
+                       for(File child : commonDir.listFiles()) {\r
+                               if(child.isDirectory()) {\r
+                                       // If directory is found, try to get the lock file in it\r
+                                       File lock = new File(child, FMUControlJNI.LOCK_FILE_NAME);\r
+                                       if(!lock.isFile() || lock.delete()) {\r
+                                               // If lock is not found, or the lock can be delted, the directory is not locked. -> Delete the rest of the directory\r
+                                               try {\r
+                                                       FileUtils.deleteAll(child);\r
+                                                       child.delete();\r
+                                               } catch (IOException e) {\r
+\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+}\r
diff --git a/org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/GameExperiment.java b/org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/GameExperiment.java
new file mode 100644 (file)
index 0000000..9104b4c
--- /dev/null
@@ -0,0 +1,415 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012, 2015 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
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.omsolver;\r
+\r
+import gnu.trove.list.array.TDoubleArrayList;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+import java.lang.reflect.Field;\r
+import java.util.HashMap;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.NullProgressMonitor;\r
+import org.simantics.Simantics;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.fmu.FMUControlJNI;\r
+import org.simantics.fmu.FMUJNIException;\r
+import org.simantics.modelica.IModelicaMonitor;\r
+import org.simantics.modelica.ModelicaManager;\r
+import org.simantics.modelica.SimulationLocation;\r
+import org.simantics.modeling.PartialIC;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
+import org.simantics.sysdyn.simulation.SimulationJob.HeadlessModelicaMonitor;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+\r
+/**\r
+ * Game experiment\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class GameExperiment extends SysdynGameExperimentBase {\r
+\r
+       private ModelicaSolver solver;\r
+       public FMUControlJNI control;\r
+       private boolean loaded = false;\r
+       \r
+       private static boolean fortranLibrariesLoaded = false;\r
+       \r
+       public GameExperiment(Resource experiment, Resource model) {\r
+               super(experiment, model);\r
+               this.solver = new ModelicaSolver(this);\r
+       }\r
+       \r
+       public FMUControlJNI getFMUControl() {\r
+               return control;\r
+       }\r
+       \r
+       @Override\r
+       public void init(ReadGraph g) {\r
+               super.init(g);\r
+\r
+               if(control == null)\r
+                       control = new FMUControlJNI();\r
+               \r
+               results = new TDoubleArrayList[results != null ? results.length : 0];\r
+               \r
+       }\r
+       \r
+       @Override\r
+       protected void onExperimentDisposed() {\r
+               super.onExperimentDisposed();\r
+               if(control!=null) {\r
+                       try {\r
+                               control.unloadFMU();\r
+                               loaded = false;\r
+                       } catch (FMUJNIException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+       }\r
+\r
+       private boolean isValidFMU(File file) {\r
+               if(!file.exists()) return false;\r
+               if(!file.isFile()) return false;\r
+               if(file.length() == 0) return false;\r
+               return true;\r
+       }\r
+       \r
+\r
+       @Override\r
+       public synchronized void simulate(final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, String modelName) throws IOException {\r
+               canceled = false;\r
+\r
+               progressMonitor.subTask("Write modelica classes");\r
+\r
+               // Write Modelica files       \r
+               String modelText = getModelicaCode(monitor, true, getOpenModelicaVersion());\r
+               if(modelText == null)\r
+                       return;\r
+               \r
+        omcVersion = ModelicaManager.getDefaultOMVersion();\r
+        \r
+        monitor.message("Simulate " + modelName + " using OpenModelica " + omcVersion);\r
+        \r
+               progressMonitor.worked(1);\r
+\r
+               // Write initial files and add init-parameters\r
+               progressMonitor.subTask("Write simulation files");\r
+               HashMap<String, String> inits = getExperimentParameters(monitor);\r
+\r
+\r
+               // add loadFile script to load all related functions and function libraries \r
+               String additionalScript = getAdditionalScripts();\r
+\r
+               // Create simulation files\r
+               SimulationLocation simulationLocation = createSimulationFiles(sysdynModel, modelText, inits, additionalScript, true);\r
+               progressMonitor.worked(1);\r
+\r
+               // Load precompiled fmu if structure has not changed and it has not yet been loaded\r
+               File fmu = null;\r
+               if(!sysdynModel.isStructureModified()) {\r
+                   if(!simulationLocation.executableFile.isFile()) {\r
+                       fmu = loadModelFmu(simulationLocation);\r
+                   } else {\r
+                       fmu = simulationLocation.executableFile;\r
+                   }\r
+               }\r
+               // Build the model and store previous model structure and inits that affect the building\r
+               // If there is no exe file OR the model structure has not changed, no need to build\r
+               if (fmu == null && (!isValidFMU(simulationLocation.executableFile) || sysdynModel.isStructureModified())) {\r
+                       progressMonitor.subTask("Build model");\r
+                       buildModel(simulationLocation, monitor);\r
+                       \r
+                       saveModelFmu(simulationLocation);\r
+               }\r
+\r
+               progressMonitor.worked(1);\r
+\r
+               if(simulationLocation != null && !canceled) {\r
+                       // Load fmu and initialize it for simulation\r
+                       try {\r
+                               if (!fortranLibrariesLoaded) { // Enable this when we update from OpenModelica 1.9.0beta4!\r
+                                       File omDir = ModelicaManager.getOMHome();\r
+                                       File mingw = new File(omDir, "MinGW");\r
+                                       File mbin = new File(mingw, "bin");\r
+                                       \r
+                                       // Add MinGW path to java.library.path. This is a bit of a hack because \r
+                                       // java.library.path isn't intended to be set programmatically.\r
+                                       String newLibPath = System.getProperty("java.library.path") + File.pathSeparator + mbin.getAbsolutePath();\r
+                                       System.setProperty("java.library.path", newLibPath);\r
+                                       Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");\r
+                                       fieldSysPath.setAccessible(true);\r
+                                       if (fieldSysPath != null) {\r
+                                               fieldSysPath.set(System.class.getClassLoader(), null);\r
+                                       }\r
+                                       \r
+                                       System.loadLibrary("libgfortran-3");\r
+                                       System.out.println("Loaded libgfortran-3.dll");\r
+                                       System.loadLibrary("pthreadGC2");\r
+                                       System.out.println("Loaded pthreadGC2.dll");\r
+                                       fortranLibrariesLoaded = true;\r
+                               }\r
+                \r
+                               control.loadFMUFile(simulationLocation.executableFile.getAbsolutePath()); // unzip and load fmu\r
+                               loaded = true;\r
+                               instantiate();\r
+                               \r
+                       } catch (FMUJNIException e) {\r
+                               System.err.println("SysdynGameExperiment initialization failed:\n\t" + e.getMessage());\r
+                       } catch (SecurityException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
+                       } catch (NoSuchFieldException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
+                       } catch (IllegalArgumentException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
+                       } catch (IllegalAccessException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
+                       }\r
+\r
+               }\r
+               process = null;\r
+               simulate(false); \r
+       }\r
+\r
+       /**\r
+        * Load fmu file from database, if it exists for the model of this experiment\r
+        * \r
+        * @param simulationLocation SimulationLocation indicating where the fmu should be loaded\r
+        * @return Loaded fmu or null if it was not loaded from database\r
+        */\r
+       private File loadModelFmu(SimulationLocation simulationLocation) {\r
+           File fmu = null;\r
+           try {\r
+               final String fmuLocation = simulationLocation.executableFile.getAbsolutePath();\r
+            fmu = session.syncRequest(new Read<File>() {\r
+                @Override\r
+                public File perform(ReadGraph graph) throws DatabaseException {\r
+                    File result = null;\r
+                    FileOutputStream fos;\r
+                    try {\r
+                        fos = new FileOutputStream(fmuLocation);\r
+                        byte[] fileBArray = graph.getPossibleRelatedValue(\r
+                                getModel(), SysdynResource.getInstance(graph).SysdynModel_fmuFile, Bindings.BYTE_ARRAY);\r
+                        \r
+                        if(fileBArray != null) {\r
+                            fos.write(fileBArray);\r
+                            fos.close();\r
+                            result = new File(fmuLocation);\r
+                        } else {\r
+                            fos.close();\r
+                            return null;\r
+                        }\r
+                        \r
+                    } catch (FileNotFoundException e) {\r
+                        e.printStackTrace();\r
+                    } catch (IOException e) {\r
+                        e.printStackTrace();\r
+                    }\r
+                    return result;\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+           \r
+           return fmu;\r
+       }\r
+       \r
+       /**\r
+        * Save fmu file from simulationLocation to database\r
+        * @param simulationLocation Location for finding fmu\r
+        */\r
+       private void saveModelFmu(SimulationLocation simulationLocation) {\r
+           final String fmuLocation = simulationLocation.executableFile.getAbsolutePath();\r
+           session.asyncRequest(new WriteRequest() {\r
+\r
+               @Override\r
+               public void perform(WriteGraph graph) throws DatabaseException {\r
+                   File file = new File(fmuLocation);\r
+                   byte[] fileBArray = new byte[(int)file.length()];\r
+                   FileInputStream fis;\r
+                   try {\r
+                       fis = new FileInputStream(file);\r
+\r
+                       fis.read(fileBArray);\r
+                       graph.claimLiteral(\r
+                               getModel(), \r
+                               SysdynResource.getInstance(graph).SysdynModel_fmuFile, \r
+                               fileBArray, Bindings.BYTE_ARRAY);\r
+                       fis.close();\r
+                   } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                   } catch (IOException e) {\r
+                       e.printStackTrace();\r
+                   }\r
+            }\r
+        });\r
+       }\r
+\r
+\r
+       @Override\r
+    public void rewindTo(double time) {\r
+       \r
+        if(control == null)\r
+            return;\r
+        \r
+        if(time >-0.001 && time < 0.001) {\r
+               try {\r
+                               simulate(new HeadlessModelicaMonitor(), new NullProgressMonitor(), sysdynModel.getConfiguration().getLabel());\r
+                   //instantiate();\r
+                       } catch (IOException e) {\r
+                               Logger.defaultLogError(e);\r
+                       }\r
+        } else {\r
+            System.out.println("rewindTo");\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public void refresh(Session session) {\r
+        try {\r
+            control.initializeSimulation();\r
+            clearResults();\r
+            //getInitialResultValues();\r
+            \r
+        } catch (FMUJNIException e) {\r
+            System.err.println("SysdynGameExperiment instantiate failed: " + e.getMessage());\r
+        }\r
+    }\r
+    \r
+    private synchronized void instantiate() {\r
+        try {\r
+            HashMap<String, String> inits = getExperimentParameters(null);\r
+\r
+            control.setStepLength(stepLength); // FIXME: fixed step lenghth\r
+            control.setTime(startTime);\r
+            control.instantiateSimulation(); // instantiate simulation\r
+\r
+            if(!control.isInitialized()) {\r
+                       control.initializeSimulation();\r
+                   }\r
+\r
+            if(inits.get("variableFilter") == null || inits.get("variableFilter").equals(".*"))\r
+                subscription = control.getAllVariables();\r
+            else\r
+                subscription = control.filterVariables(inits.get("variableFilter"));\r
+            \r
+            // Initialize subscription indexes map for fast result reading in getValue()\r
+            if(subscriptionIndexes == null)\r
+                subscriptionIndexes = new HashMap<String, Integer>();\r
+            \r
+            subscriptionIndexes.clear();\r
+            for(int i = 0; i < subscription.length; i++) {\r
+                subscriptionIndexes.put(subscription[i], i);\r
+            }\r
+            \r
+            results = new TDoubleArrayList[subscription.length];\r
+\r
+            // Initialize container for current simulation results\r
+            currentValues = new double[subscription.length];\r
+            \r
+            // subscribe all variables\r
+            control.subscribe(subscription); \r
+\r
+            clearResults();\r
+            //getInitialResultValues();\r
+            \r
+                       Simantics.getSession().syncRequest(new WriteRequest() {\r
+\r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
+                                       Resource run = Layer0Utils.getPossibleChild(graph, GameExperiment.this.experiment, getIdentifier());\r
+                                       if(run == null) {\r
+                                               System.err.println("No run");\r
+                                               return;\r
+                                       }\r
+                                       \r
+                                       Variable base = Variables.getVariable(graph, run);\r
+                                       \r
+                                       SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
+                                       \r
+                                       Resource ic = graph.getPossibleObject(GameExperiment.this.experiment, SYSDYN.Experiment_ic);\r
+                                       if(ic == null) return;\r
+                                       \r
+                                       PartialIC data = graph.getPossibleRelatedValue(ic, SYSDYN.InitialCondition_HasInitialValues, PartialIC.BINDING);\r
+                                       data.apply(graph, base);\r
+                                       \r
+                               }\r
+                               \r
+                       });\r
+            \r
+        } catch (FMUJNIException e) {\r
+            System.err.println("SysdynGameExperiment instantiate failed: " + e.getMessage());\r
+        } catch (DatabaseException e) {\r
+            System.err.println("SysdynGameExperiment instantiate failed: " + e.getMessage());\r
+               }\r
+    }\r
+\r
+//    private synchronized void getInitialResultValues() {\r
+//        try {\r
+//            // Initialize results\r
+//            results.clear();\r
+//\r
+//            currentValues = control.getSubscribedResults(currentValues);\r
+//            for(int k = 0; k < subscription.length; k++) {\r
+//                results.put(subscription[k], new ArrayList<Double>());\r
+//                results.get(subscription[k]).add(currentValues[k]);\r
+//            }\r
+//\r
+//            ((MemoryResult)getCurrentResult()).setResult(new GameResult(this.results, this.subscription));\r
+//            resultsChanged();  \r
+//        } catch (FMUJNIException e) {\r
+//            System.err.println("SysdynGameExperiment getInitialResultValues failed: " + e.getMessage());\r
+//        }\r
+//    }\r
+    \r
+    @Override\r
+    public void updateSubscriptions() {\r
+       \r
+       if(!loaded) return;\r
+       \r
+        try {\r
+            if(control.isInitialized())\r
+                currentValues = control.getSubscribedResults(currentValues);\r
+        } catch (FMUJNIException e) {\r
+            e.printStackTrace();\r
+        }\r
+        super.updateSubscriptions();\r
+    }\r
+\r
+       @Override\r
+       public ISolver getSolver() {\r
+               return solver;\r
+       }\r
+    \r
+ }\r
diff --git a/org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/GameExperimentFactory.java b/org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/GameExperimentFactory.java
new file mode 100644 (file)
index 0000000..e9439a7
--- /dev/null
@@ -0,0 +1,14 @@
+package org.simantics.sysdyn.omsolver;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.sysdyn.manager.SysdynExperiment;\r
+import org.simantics.sysdyn.manager.SysdynExperimentFactory;\r
+\r
+public class GameExperimentFactory implements SysdynExperimentFactory {\r
+\r
+       @Override\r
+       public SysdynExperiment create(Resource experiment, Resource model) {\r
+               return new GameExperiment(experiment, model);\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/ModelicaSolver.java b/org.simantics.sysdyn.omsolver/src/org/simantics/sysdyn/omsolver/ModelicaSolver.java
new file mode 100644 (file)
index 0000000..17528b7
--- /dev/null
@@ -0,0 +1,93 @@
+package org.simantics.sysdyn.omsolver;\r
+\r
+import org.simantics.fmu.FMUJNIException;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+import org.simantics.sysdyn.solver.SolverSettings.SolverType;\r
+\r
+public class ModelicaSolver implements ISolver {\r
+       \r
+       GameExperiment exp;\r
+       \r
+       public ModelicaSolver(GameExperiment exp) {\r
+               this.exp = exp;\r
+       }\r
+       \r
+       @Override\r
+       public void initialize() throws Exception {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void buildModel() throws Exception {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void runSolver() throws Exception {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void updateResults() throws Exception {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public SolverType getType() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public double[] getSubscribedResults(double[] array) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public void prepareToStep() throws Exception {\r
+\r
+               // initialize if not initialized\r
+               if(!exp.control.isInitialized()) {\r
+                       exp.control.setTime(exp.startTime);\r
+                       exp.control.initializeSimulation();\r
+                       exp.clearResults();\r
+                       //                              getInitialResultValues();\r
+               }\r
+\r
+               exp.control.setStepLength(exp.stepLength); // Set step length each time in case there has been changes\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void simulateStep() throws Exception {\r
+               exp.control.simulateStep();\r
+       }\r
+\r
+       @Override\r
+       public void setStepLength(double length) throws Exception {\r
+               exp.control.setStepLength(length);\r
+       }\r
+\r
+       @Override\r
+       public double getTime() {\r
+               if(exp.control != null) {\r
+                       try {\r
+                               return exp.control.getTime();\r
+                       } catch (FMUJNIException e) {\r
+                       }\r
+               }\r
+               return 0.0;\r
+       }\r
+\r
+       @Override\r
+       public void setRealValue(String name, double value) throws Exception {\r
+               exp.control.setRealValue(name, value);\r
+       }\r
+\r
+       \r
+}\r