>-- SYSDYN.Variable.value <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.Variable.value
_ : L0.Value
- L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
- L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ L0.domainProperties FUNCTIONS.valuePropertyProperties
+ L0.valueAccessor FUNCTIONS.valuePropertyValue
>-- SYSDYN.Variable.values <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.Variable.values
_ : L0.Value
- L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
- L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ L0.domainProperties FUNCTIONS.valuePropertyProperties
+ L0.valueAccessor FUNCTIONS.valuePropertyValue
>-- SYSDYN.Variable.times <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.Variable.times
_ : L0.Value
- L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
- L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ L0.domainProperties FUNCTIONS.valuePropertyProperties
+ L0.valueAccessor FUNCTIONS.valuePropertyValue
>-- SYSDYN.Variable.names <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.Variable.names
_ : L0.Value
- L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
- L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ L0.domainProperties FUNCTIONS.valuePropertyProperties
+ L0.valueAccessor FUNCTIONS.valuePropertyValue
>-- SYSDYN.Variable.activeDatasets <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.Variable.activeDatasets
_ : L0.Value
- L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
- L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ L0.domainProperties FUNCTIONS.valuePropertyProperties
+ L0.valueAccessor FUNCTIONS.valuePropertyValue
>-- SYSDYN.Variable.time <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.Variable.time
_ : L0.Value
- L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
- L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ L0.domainProperties FUNCTIONS.valuePropertyProperties
+ L0.valueAccessor FUNCTIONS.valuePropertyValue
>-- SYSDYN.Variable.equation <R L0.HasProperty : L0.FunctionalRelation
L0.valueAccessor FUNCTIONS.equationPropertyValue : L0.ExternalValue
@L0.assert SYSDYN.Variable.equation
_ : L0.Value
+FUNCTIONS.valuePropertyProperties : L0.ExternalValue
+FUNCTIONS.valuePropertyValue : L0.ExternalValue
FUNCTIONS.runChildren : L0.ExternalValue
@L0.assert SYSDYN.GameExperiment.stepLength 0.1
-FUNCTIONS.runChildren : L0.ExternalValue
SYSDYN.Experiment.Run <T SIMU.Run
@L0.assert L0.domainChildren FUNCTIONS.runChildren
>-- SYSDYN.Experiment.Run.time <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.Experiment.Run.time
_ : L0.Value
L0.domainProperties FUNCTIONS.runProperties : L0.ExternalValue
- L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ L0.valueAccessor FUNCTIONS.valuePropertyValue
SYSDYN.SimulateOnChangeExperiment <T SYSDYN.Experiment
>-- SYSDYN.HistoryDataset.sheet --> SHEET.Spreadsheet <R L0.IsRelatedTo : L0.FunctionalRelation
SYSDYN.ResultSet <T L0.Entity
- >-- SYSDYN.Experiment.result --> SYSDYN.Result <R L0.IsComposedOf
+ >-- SYSDYN.Experiment.result
SYSDYN.InitialCondition <T MOD.InitialCondition
>-- SYSDYN.InitialCondition.HasInitialValues --> MOD.PartialIC <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.ValveSymbol.orientation SYSDYN.Horizontal
>-- SYSDYN.ValveSymbol.textLocation --> SYSDYN.Location <R L0.IsWeaklyRelatedTo : L0.FunctionalRelation
L0.IsDependencyOf BasicSymbols
- STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext
+ STR.IsDefinedBy _ : DIA.Composite
@L0.orderedSet
_ : SYSDYN.SysdynTerminal
@MOD.terminal SYSDYN.ValveSymbol SYSDYN.IsHeadOfTerminal
@MOD.defSymbol "Auxiliary" SYSDYN.Auxiliary
L0.HasDescription "(Shift+A)"
L0.IsDependencyOf BasicSymbols
- STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext
+ STR.IsDefinedBy _ : DIA.Composite
@L0.orderedSet
_ : SYSDYN.SysdynTerminal
@MOD.terminal SYSDYN.AuxiliarySymbol SYSDYN.IsHeadOfTerminal
@MOD.defSymbol "Cloud" SYSDYN.Cloud
L0.HasDescription "(Shift+C)"
L0.IsDependencyOf BasicSymbols
- STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext
+ STR.IsDefinedBy _ : DIA.Composite
@L0.orderedSet
_ : SYSDYN.SysdynTerminal
@MOD.terminal SYSDYN.CloudSymbol SYSDYN.IsHeadOfTerminal
@MOD.defSymbol "Input" SYSDYN.Input
L0.HasDescription "(Shift+I)"
L0.IsDependencyOf BasicSymbols
- STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext
+ STR.IsDefinedBy _ : DIA.Composite
@L0.orderedSet
_ : SYSDYN.SysdynTerminal
@MOD.terminal SYSDYN.InputSymbol SYSDYN.IsHeadOfTerminal
@MOD.defSymbol "Stock" SYSDYN.Stock
L0.HasDescription "(Shift+S)"
L0.IsDependencyOf BasicSymbols
- STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext
+ STR.IsDefinedBy _ : DIA.Composite
@L0.orderedSet
_ : SYSDYN.SysdynTerminal
@MOD.terminal SYSDYN.StockSymbol SYSDYN.IsHeadOfTerminal
@MOD.defSymbol "Shadow" SYSDYN.Shadow
L0.HasDescription "(Shift+G)"
L0.IsDependencyOf BasicSymbols
- STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext
+ STR.IsDefinedBy _ : DIA.Composite
@L0.orderedSet
_ : SYSDYN.SysdynTerminal
@MOD.terminal SYSDYN.ShadowSymbol SYSDYN.IsHeadOfTerminal
\r
SBC.VariableNodeType <T VP.NodeType\r
@L0.assert VP.HasContentType "Variable"\r
- \r
+\r
+SYSDYN.BrowseContextContribution : VP.BrowseContextContribution\r
+ VP.BrowseContextContribution.HasType SYSDYN.SysdynModel\r
+ VP.BrowseContextContribution.HasBrowseContext SBC\r
\r
////////////////////////////////\r
// From Project Viewpoint\r
public final Resource AvailableVariableIndexes;\r
public final Resource BasicExperiment;\r
public final Resource Bottom;\r
+ public final Resource BrowseContextContribution;\r
public final Resource Browser;\r
public final Resource Built$in_Functions;\r
public final Resource Built$in_Functions_Modelica_Array_Functions;\r
public static final String AvailableVariableIndexes = "http://www.simantics.org/Sysdyn-1.1/AvailableVariableIndexes";\r
public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.1/BasicExperiment";\r
public static final String Bottom = "http://www.simantics.org/Sysdyn-1.1/Bottom";\r
+ public static final String BrowseContextContribution = "http://www.simantics.org/Sysdyn-1.1/BrowseContextContribution";\r
public static final String Browser = "http://www.simantics.org/Sysdyn-1.1/Browser";\r
public static final String Built$in_Functions = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions";\r
public static final String Built$in_Functions_Modelica_Array_Functions = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Modelica%20Array%20Functions";\r
AvailableVariableIndexes = getResourceOrNull(graph, URIs.AvailableVariableIndexes);\r
BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
Bottom = getResourceOrNull(graph, URIs.Bottom);\r
+ BrowseContextContribution = getResourceOrNull(graph, URIs.BrowseContextContribution);\r
Browser = getResourceOrNull(graph, URIs.Browser);\r
Built$in_Functions = getResourceOrNull(graph, URIs.Built$in_Functions);\r
Built$in_Functions_Modelica_Array_Functions = getResourceOrNull(graph, URIs.Built$in_Functions_Modelica_Array_Functions);\r
org.eclipse.ui.forms;bundle-version="3.5.2",
org.simantics.scenegraph.swing;bundle-version="1.0.0",
org.eclipse.nebula.widgets.tablecombo;bundle-version="1.0.0",
- org.simantics.fmu;bundle-version="1.0.0",
org.simantics.jfreechart;bundle-version="1.0.0",
org.simantics.db.indexing;bundle-version="1.1.0",
org.simantics.workbench,
name="Trend"\r
restorable="true">\r
</view>\r
- <view\r
+ <!--<view\r
category="org.simantics.sysdyn.ui.category"\r
class="org.simantics.sysdyn.ui.browser.SysdynBrowser"\r
icon="platform:/plugin/com.famfamfam.silk/icons/chart_organisation.png"\r
id="org.simantics.sysdyn.ui.browser"\r
name="Model Browser"\r
restorable="true">\r
- </view>\r
+ </view>-->\r
<view\r
allowMultiple="false"\r
category="org.simantics.sysdyn.ui.category"\r
name="Values"\r
restorable="true">\r
</view>\r
- <view\r
+ <!--<view\r
category="org.simantics.sysdyn.ui.category"\r
class="org.simantics.sysdyn.ui.browser.SysdynModelBrowser"\r
icon="platform:/plugin/com.famfamfam.silk/icons/chart_organisation.png"\r
<description>\r
Structural model browser view for Sysdyn.\r
</description>\r
- </view>\r
+ </view>-->\r
</extension>\r
<extension\r
point="org.eclipse.ui.perspectives">\r
relative="org.simantics.sysdyn.ui.trend.view">\r
</view>\r
<view\r
- id="org.simantics.sysdyn.ui.browser"\r
+ id="org.simantics.modeling.ui.browser"\r
ratio="0.25f"\r
relationship="left"\r
relative="org.eclipse.ui.editorss">\r
id="org.simantics.diagram.symbollibrary"\r
minimized="false"\r
relationship="stack"\r
- relative="org.simantics.sysdyn.ui.browser">\r
+ relative="org.simantics.modeling.ui.browser">\r
</view>\r
<view\r
id="org.simantics.sysdyn.ui.values.view"\r
id="org.simantics.workbench.search.browser"\r
minimized="false"\r
relationship="stack"\r
- relative="org.simantics.sysdyn.ui.browser">\r
+ relative="org.simantics.modeling.ui.browser">\r
</view>\r
<!--\r
<view\r
relative="org.simantics.sysdyn.ui.trend.view">\r
</view>\r
<view\r
- id="org.simantics.sysdyn.ui.browser"\r
+ id="org.simantics.modeling.ui.browser"\r
minimized="true"\r
ratio="0.25f"\r
relationship="left"\r
id="org.simantics.diagram.symbollibrary"\r
minimized="true"\r
relationship="stack"\r
- relative="org.simantics.sysdyn.ui.browser">\r
+ relative="org.simantics.modeling.ui.browser">\r
</view>\r
<view\r
id="org.simantics.sysdyn.ui.values.view"\r
id="org.simantics.workbench.search.browser"\r
minimized="false"\r
relationship="stack"\r
- relative="org.simantics.sysdyn.ui.browser">\r
+ relative="org.simantics.modeling.ui.browser">\r
</view>\r
</perspectiveExtension>\r
<perspectiveExtension\r
relative="org.simantics.sysdyn.ui.trend.view">\r
</view>\r
<view\r
- id="org.simantics.sysdyn.ui.browser"\r
+ id="org.simantics.modeling.ui.browser"\r
minimized="true"\r
ratio="0.25f"\r
relationship="left"\r
id="org.simantics.diagram.symbollibrary"\r
minimized="false"\r
relationship="stack"\r
- relative="org.simantics.sysdyn.ui.browser">\r
+ relative="org.simantics.modeling.ui.browser">\r
</view>\r
<view\r
id="org.simantics.sysdyn.ui.values.view"\r
id="org.simantics.workbench.search.browser"\r
minimized="false"\r
relationship="stack"\r
- relative="org.simantics.sysdyn.ui.browser">\r
+ relative="org.simantics.modeling.ui.browser">\r
</view>\r
</perspectiveExtension>\r
</extension>\r
</extension>\r
<extension\r
point="org.eclipse.ui.menus">\r
- <menuContribution\r
+ <!--<menuContribution\r
locationURI="menu:sFile?after=import.ext">\r
<command commandId="org.eclipse.ui.file.import" />\r
<command commandId="org.eclipse.ui.file.export" />\r
- </menuContribution>\r
+ </menuContribution>-->\r
<menuContribution\r
locationURI="toolbar:org.eclipse.ui.main.toolbar">\r
<toolbar\r
package org.simantics.sysdyn.ui.project;\r
\r
import java.io.File;\r
-import java.io.IOException;\r
import java.util.HashMap;\r
\r
import org.eclipse.core.runtime.Platform;\r
import org.simantics.db.request.Read;\r
import org.simantics.db.service.GraphChangeListenerSupport;\r
import org.simantics.db.service.VirtualGraphSupport;\r
-import org.simantics.fmu.FMUControlJNI;\r
import org.simantics.issues.common.IssueUtils;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService;\r
import org.simantics.ui.workbench.IEditorNamingService;\r
-import org.simantics.utils.FileUtils;\r
import org.simantics.utils.ui.BundleUtils;\r
\r
public class SysdynProject extends AbstractProjectFeature {\r
\r
cleanProjectFolder(session, project.get());\r
\r
- // Clean all temporary files possibly left by previous sysdyn instances\r
- clearFMUTempDirectory();\r
-\r
\r
// Issues\r
try {\r
}\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
@Override\r
public void deconfigure() throws ProjectException {\r
org.simantics.spreadsheet;bundle-version="1.1.0",
org.eclipse.jface.text;bundle-version="3.6.1",
org.simantics.spreadsheet.ontology;bundle-version="1.2.0",
- org.simantics.fmu;bundle-version="1.0.0",
org.simantics.issues;bundle-version="1.1.0",
org.simantics.issues.common;bundle-version="1.1.0",
org.simantics.jfreechart;bundle-version="1.0.0",
\r
import org.osgi.framework.BundleActivator;\r
import org.osgi.framework.BundleContext;\r
+import org.simantics.sysdyn.manager.InternalGameExperimentFactory;\r
+import org.simantics.sysdyn.solver.SolverSettings.SolverType;\r
+import org.simantics.sysdyn.solver.Solvers;\r
\r
public class Activator implements BundleActivator {\r
\r
modelsDir.mkdir();\r
}\r
plugin = this;\r
+ Solvers.registerGameExperimentFactory(SolverType.INTERNAL, new InternalGameExperimentFactory());\r
}\r
\r
@Override\r
public void stop(BundleContext context) throws Exception {\r
+ Solvers.unregisterGameExperimentFactory(SolverType.INTERNAL);\r
File modelsDir = Activator.getBundleContext().getDataFile("models");\r
if (modelsDir.exists()) {\r
recursiveDelete(modelsDir);\r
}\r
plugin = null;\r
-\r
}\r
\r
public static Activator getDefault() {\r
--- /dev/null
+package org.simantics.sysdyn.manager;\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public class InternalGameExperimentFactory implements SysdynExperimentFactory {\r
+\r
+ @Override\r
+ public SysdynExperiment create(Resource experiment, Resource model) {\r
+ return new SysdynGameExperimentInternal(experiment, model);\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.manager;\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public interface SysdynExperimentFactory {\r
+\r
+ SysdynExperiment create(Resource experiment, Resource model);\r
+ \r
+}\r
+++ /dev/null
-/*******************************************************************************\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.manager;\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.simulation.SimulationJob.HeadlessModelicaMonitor;\r
-import org.simantics.sysdyn.solver.ISolver;\r
-import org.simantics.sysdyn.solver.ModelicaSolver;\r
-\r
-/**\r
- * Game experiment\r
- * @author Teemu Lempinen\r
- *\r
- */\r
-public class SysdynGameExperiment 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 SysdynGameExperiment(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, SysdynGameExperiment.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(SysdynGameExperiment.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
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.procedure.AsyncListener;\r
import org.simantics.db.request.Read;\r
-import org.simantics.fmu.FMUJNIException;\r
import org.simantics.simulation.experiment.ExperimentState;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.solver.ISolver;\r
public HashMap<String, Integer> subscriptionIndexes;\r
protected double[] currentValues; // Current values from FMU. Updated with updateSubscriptions\r
\r
- TDoubleArrayList[] results;\r
+ protected TDoubleArrayList[] results;\r
\r
public String[] subscription;\r
\r
return null;\r
}\r
\r
- public void setSubscribedResults(IProgressMonitor monitor, double time) throws FMUJNIException {\r
+ public void setSubscribedResults(IProgressMonitor monitor, double time) throws Exception {\r
\r
monitor.subTask("Get results (time = " + time + ")");\r
currentValues = getSolver().getSubscribedResults(currentValues);\r
protected void onPublishResults() {\r
try {\r
setSubscribedResults(new NullProgressMonitor(), getSolver().getTime());\r
- } catch (FMUJNIException e) {\r
+ } catch (Exception e) {\r
Logger.defaultLogError(e);\r
}\r
((MemoryResult)getCurrentResult()).setResult(new GameResult(this, this.results, this.subscription));\r
*******************************************************************************/\r
package org.simantics.sysdyn.manager;\r
\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.HashMap;\r
import org.simantics.sysdyn.representation.expressions.StockExpression;\r
import org.simantics.sysdyn.solver.SolverSettings;\r
import org.simantics.sysdyn.solver.SolverSettings.SolverType;\r
+import org.simantics.sysdyn.solver.Solvers;\r
+\r
+import gnu.trove.set.hash.THashSet;\r
\r
/**\r
* Maintains a Java representation of system dynamic model.\r
if(g.isInstanceOf(experiment, sr.PlaybackExperiment)) {\r
exp = new SysdynPlaybackExperiment(experiment, modelResource);\r
} else if(g.isInstanceOf(experiment, sr.GameExperiment)) {\r
- if (SolverType.INTERNAL.equals(SolverSettings.getSelectedSolverType())) {\r
- exp = new SysdynGameExperimentInternal(experiment, modelResource);\r
- }\r
- else {\r
- exp = new SysdynGameExperiment(experiment, modelResource);\r
- }\r
+ exp = Solvers.instantiateGameExperiment(SolverSettings.getSelectedSolverType(), experiment, modelResource);\r
+// if (SolverType.INTERNAL.equals()) {\r
+// exp = new SysdynGameExperimentInternal(experiment, modelResource);\r
+// }\r
+// else {\r
+// exp = new SysdynGameExperiment(experiment, modelResource);\r
+// }\r
} else if(g.isInstanceOf(experiment, sr.SensitivityAnalysisExperiment)) {\r
exp = new SysdynSensitivityAnalysisExperiment(experiment, modelResource);\r
} else if(g.isInstanceOf(experiment, sr.BasicExperiment)) {\r
+++ /dev/null
-package org.simantics.sysdyn.solver;\r
-\r
-import org.simantics.fmu.FMUJNIException;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
-import org.simantics.sysdyn.solver.SolverSettings.SolverType;\r
-\r
-public class ModelicaSolver implements ISolver {\r
- \r
- SysdynGameExperiment exp;\r
- \r
- public ModelicaSolver(SysdynGameExperiment 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
--- /dev/null
+package org.simantics.sysdyn.solver;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\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 Solvers {\r
+\r
+ private Map<SolverSettings.SolverType,SysdynExperimentFactory> gameExperimentFactories = new HashMap<>();\r
+\r
+ private static Solvers INSTANCE;\r
+ \r
+ private Solvers() {\r
+ \r
+ }\r
+ \r
+ public static synchronized Solvers getInstance() {\r
+ \r
+ if(INSTANCE == null) {\r
+ INSTANCE = new Solvers();\r
+ }\r
+ return INSTANCE;\r
+ \r
+ }\r
+ \r
+ public static synchronized SysdynExperiment instantiateGameExperiment(SolverSettings.SolverType solver, Resource experiment, Resource model) throws Exception {\r
+\r
+ Solvers s = getInstance();\r
+ SysdynExperimentFactory factory = s.gameExperimentFactories.get(solver);\r
+ if(factory == null) throw new Exception("No game experiment factory registered as " + solver);\r
+ return factory.create(experiment, model);\r
+ \r
+ }\r
+ \r
+ public static synchronized void registerGameExperimentFactory(SolverSettings.SolverType solver, SysdynExperimentFactory factory) {\r
+ \r
+ Solvers s = getInstance();\r
+ s.gameExperimentFactories.put(solver, factory);\r
+ \r
+ }\r
+ \r
+ public static synchronized void unregisterGameExperimentFactory(SolverSettings.SolverType solver) {\r
+ \r
+ Solvers s = getInstance();\r
+ s.gameExperimentFactories.remove(solver);\r
+ \r
+ }\r
+ \r
+}\r