>-- SYSDYN.SysdynModel.tolerance --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.SysdynModel.solver --> L0.String <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.SysdynModel.variableFilter --> L0.String <R L0.HasProperty : L0.FunctionalRelation
+ >-- SYSDYN.SysdynModel.fmuFile --> L0.ByteArray <R L0.HasProperty
+// >-- SYSDYN.SysdynModel.exeFile --> L0.ByteArray <R L0.HasProperty
@L0.assert SYSDYN.SysdynModel.startTime 0.0
@L0.assert SYSDYN.SysdynModel.stopTime 10.0
@L0.assert SYSDYN.SysdynModel.solver "euler"
public final Resource LookupExpression;\r
public final Resource LookupExpression_lookup;\r
public final Resource LookupExpression_lookup_Inverse;\r
+ public final Resource Migration;\r
+ public final Resource Migration_from1$6to1$7;\r
+ public final Resource Migration_from1$6to1$7_Ontologies;\r
+ public final Resource Migration_from1$6to1$7_OrderedSetsToLists;\r
+ public final Resource Migration_from1$6to1$7_Spreadsheets;\r
+ public final Resource Migration_from1$6to1$7_SysdynChanges;\r
+ public final Resource Migration_fromFunctionLibrary1;\r
+ public final Resource Migration_fromModel1;\r
+ public final Resource Migration_fromModule1;\r
public final Resource ModelBrowser;\r
public final Resource ModelingActionContext;\r
public final Resource ModelingActionContext_Actions;\r
public final Resource SysdynConnectionType;\r
public final Resource SysdynDiagramModelingRules;\r
public final Resource SysdynModel;\r
+ public final Resource SysdynModel_fmuFile;\r
+ public final Resource SysdynModel_fmuFile_Inverse;\r
public final Resource SysdynModel_outputInterval;\r
public final Resource SysdynModel_outputInterval_Inverse;\r
public final Resource SysdynModel_simulationStepLength;\r
public final Resource WithLookupExpression_maxY;\r
public final Resource WithLookupExpression_minX;\r
public final Resource WithLookupExpression_minY;\r
- public final Resource from1$6to1$7;\r
- public final Resource from1$6to1$7_Ontologies;\r
- public final Resource from1$6to1$7_OrderedSetsToLists;\r
- public final Resource from1$6to1$7_Spreadsheets;\r
- public final Resource from1$6to1$7_SysdynChanges;\r
\r
public static class URIs {\r
public static final String AdditionalSymbols = "http://www.simantics.org/Sysdyn-1.1/AdditionalSymbols";\r
public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.1/LookupExpression";\r
public static final String LookupExpression_lookup = "http://www.simantics.org/Sysdyn-1.1/LookupExpression/lookup";\r
public static final String LookupExpression_lookup_Inverse = "http://www.simantics.org/Sysdyn-1.1/LookupExpression/lookup/Inverse";\r
+ public static final String Migration = "http://www.simantics.org/Sysdyn-1.1/Migration";\r
+ public static final String Migration_from1$6to1$7 = "http://www.simantics.org/Sysdyn-1.1/Migration/from1.6to1.7";\r
+ public static final String Migration_from1$6to1$7_Ontologies = "http://www.simantics.org/Sysdyn-1.1/Migration/from1.6to1.7/Ontologies";\r
+ public static final String Migration_from1$6to1$7_OrderedSetsToLists = "http://www.simantics.org/Sysdyn-1.1/Migration/from1.6to1.7/OrderedSetsToLists";\r
+ public static final String Migration_from1$6to1$7_Spreadsheets = "http://www.simantics.org/Sysdyn-1.1/Migration/from1.6to1.7/Spreadsheets";\r
+ public static final String Migration_from1$6to1$7_SysdynChanges = "http://www.simantics.org/Sysdyn-1.1/Migration/from1.6to1.7/SysdynChanges";\r
+ public static final String Migration_fromFunctionLibrary1 = "http://www.simantics.org/Sysdyn-1.1/Migration/fromFunctionLibrary1";\r
+ public static final String Migration_fromModel1 = "http://www.simantics.org/Sysdyn-1.1/Migration/fromModel1";\r
+ public static final String Migration_fromModule1 = "http://www.simantics.org/Sysdyn-1.1/Migration/fromModule1";\r
public static final String ModelBrowser = "http://www.simantics.org/Sysdyn-1.1/ModelBrowser";\r
public static final String ModelingActionContext = "http://www.simantics.org/Sysdyn-1.1/ModelingActionContext";\r
public static final String ModelingActionContext_Actions = "http://www.simantics.org/Sysdyn-1.1/ModelingActionContext/Actions";\r
public static final String SysdynConnectionType = "http://www.simantics.org/Sysdyn-1.1/SysdynConnectionType";\r
public static final String SysdynDiagramModelingRules = "http://www.simantics.org/Sysdyn-1.1/SysdynDiagramModelingRules";\r
public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.1/SysdynModel";\r
+ public static final String SysdynModel_fmuFile = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/fmuFile";\r
+ public static final String SysdynModel_fmuFile_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/fmuFile/Inverse";\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 WithLookupExpression_maxY = "http://www.simantics.org/Sysdyn-1.1/WithLookupExpression/maxY";\r
public static final String WithLookupExpression_minX = "http://www.simantics.org/Sysdyn-1.1/WithLookupExpression/minX";\r
public static final String WithLookupExpression_minY = "http://www.simantics.org/Sysdyn-1.1/WithLookupExpression/minY";\r
- public static final String from1$6to1$7 = "http://www.simantics.org/Sysdyn-1.1/from1.6to1.7";\r
- public static final String from1$6to1$7_Ontologies = "http://www.simantics.org/Sysdyn-1.1/from1.6to1.7/Ontologies";\r
- public static final String from1$6to1$7_OrderedSetsToLists = "http://www.simantics.org/Sysdyn-1.1/from1.6to1.7/OrderedSetsToLists";\r
- public static final String from1$6to1$7_Spreadsheets = "http://www.simantics.org/Sysdyn-1.1/from1.6to1.7/Spreadsheets";\r
- public static final String from1$6to1$7_SysdynChanges = "http://www.simantics.org/Sysdyn-1.1/from1.6to1.7/SysdynChanges";\r
}\r
\r
public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
LookupExpression = getResourceOrNull(graph, URIs.LookupExpression);\r
LookupExpression_lookup = getResourceOrNull(graph, URIs.LookupExpression_lookup);\r
LookupExpression_lookup_Inverse = getResourceOrNull(graph, URIs.LookupExpression_lookup_Inverse);\r
+ Migration = getResourceOrNull(graph, URIs.Migration);\r
+ Migration_from1$6to1$7 = getResourceOrNull(graph, URIs.Migration_from1$6to1$7);\r
+ Migration_from1$6to1$7_Ontologies = getResourceOrNull(graph, URIs.Migration_from1$6to1$7_Ontologies);\r
+ Migration_from1$6to1$7_OrderedSetsToLists = getResourceOrNull(graph, URIs.Migration_from1$6to1$7_OrderedSetsToLists);\r
+ Migration_from1$6to1$7_Spreadsheets = getResourceOrNull(graph, URIs.Migration_from1$6to1$7_Spreadsheets);\r
+ Migration_from1$6to1$7_SysdynChanges = getResourceOrNull(graph, URIs.Migration_from1$6to1$7_SysdynChanges);\r
+ Migration_fromFunctionLibrary1 = getResourceOrNull(graph, URIs.Migration_fromFunctionLibrary1);\r
+ Migration_fromModel1 = getResourceOrNull(graph, URIs.Migration_fromModel1);\r
+ Migration_fromModule1 = getResourceOrNull(graph, URIs.Migration_fromModule1);\r
ModelBrowser = getResourceOrNull(graph, URIs.ModelBrowser);\r
ModelingActionContext = getResourceOrNull(graph, URIs.ModelingActionContext);\r
ModelingActionContext_Actions = getResourceOrNull(graph, URIs.ModelingActionContext_Actions);\r
SysdynConnectionType = getResourceOrNull(graph, URIs.SysdynConnectionType);\r
SysdynDiagramModelingRules = getResourceOrNull(graph, URIs.SysdynDiagramModelingRules);\r
SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
+ SysdynModel_fmuFile = getResourceOrNull(graph, URIs.SysdynModel_fmuFile);\r
+ SysdynModel_fmuFile_Inverse = getResourceOrNull(graph, URIs.SysdynModel_fmuFile_Inverse);\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
WithLookupExpression_maxY = getResourceOrNull(graph, URIs.WithLookupExpression_maxY);\r
WithLookupExpression_minX = getResourceOrNull(graph, URIs.WithLookupExpression_minX);\r
WithLookupExpression_minY = getResourceOrNull(graph, URIs.WithLookupExpression_minY);\r
- from1$6to1$7 = getResourceOrNull(graph, URIs.from1$6to1$7);\r
- from1$6to1$7_Ontologies = getResourceOrNull(graph, URIs.from1$6to1$7_Ontologies);\r
- from1$6to1$7_OrderedSetsToLists = getResourceOrNull(graph, URIs.from1$6to1$7_OrderedSetsToLists);\r
- from1$6to1$7_Spreadsheets = getResourceOrNull(graph, URIs.from1$6to1$7_Spreadsheets);\r
- from1$6to1$7_SysdynChanges = getResourceOrNull(graph, URIs.from1$6to1$7_SysdynChanges);\r
}\r
\r
public static SysdynResource getInstance(ReadGraph graph) {\r
@Override\r
public void save(final Resource expression, Map<String, Object> data) {\r
final String currentText = this.expression.getExpression();\r
- if(currentText != null) {\r
+ if(currentText != null && !currentText.equals(data.get("initialEquation"))) {\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
@Override\r
*******************************************************************************/\r
package org.simantics.sysdyn.manager;\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.util.ArrayList;\r
import java.util.HashMap;\r
import org.eclipse.core.runtime.IStatus;\r
import org.eclipse.core.runtime.Status;\r
import org.eclipse.core.runtime.jobs.Job;\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.AsyncReadGraph;\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.exception.DatabaseException;\r
import org.simantics.db.procedure.AsyncListener;\r
import org.simantics.db.request.Read;\r
SimulationLocation simulationLocation = createSimulationFiles(sysdynModel, modelText, inits, additionalScript, true);\r
progressMonitor.worked(1);\r
\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 (!simulationLocation.executableFile.isFile() || hasStructureChanged(modelText)) {\r
+ if (fmu == null && (!simulationLocation.executableFile.isFile() || hasStructureChanged(modelText))) {\r
progressMonitor.subTask("Build model");\r
buildModel(simulationLocation, modelText, monitor);\r
previousModelStructure = modelText;\r
+ \r
+ saveModelFmu(simulationLocation);\r
}\r
\r
progressMonitor.worked(1);\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 simulateDuration(double duration) {\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.IElement;\r
import org.simantics.sysdyn.representation.IndependentVariable;\r
+import org.simantics.sysdyn.representation.Model;\r
import org.simantics.sysdyn.representation.Module;\r
import org.simantics.sysdyn.representation.ParameterOverride;\r
import org.simantics.sysdyn.representation.Sheet;\r
*/\r
public synchronized boolean update(ReadGraph graph) throws DatabaseException {\r
if(mapping.isDomainModified()) {\r
- structureModified = true;\r
+ \r
+\r
\r
try {\r
- mapping.updateRange(graph);\r
+ Collection<Object> updated = mapping.updateRange(graph);\r
+ \r
+ for(Object o : updated) {\r
+ if(!(o instanceof Model)) {\r
+ setStructureModified(true);\r
+ break;\r
+ }\r
+ }\r
+ \r
} catch (MappingException e) {\r
SysdynConsole.INSTANCE.message(\r
"Error: Mapping is broken! Find the problem, " +\r
}\r
else\r
return false;\r
- }\r
+ } \r
\r
/**\r
* Update mapping.\r
return structureModified;\r
}\r
\r
- public void setStructureModeified(boolean structureModified) {\r
+ public void setStructureModified(boolean structureModified) {\r
this.structureModified = structureModified;\r
}\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.representation;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+\r
import java.util.ArrayList;\r
-import java.util.HashMap;\r
import java.util.HashSet;\r
\r
import org.simantics.Simantics;\r
@RelatedElement(Layer0.URIs.PartOf)\r
protected Book book;\r
\r
- HashMap<String, Object> cells = new HashMap<String, Object>();\r
- HashSet<String> usedRanges = new HashSet<String>();\r
+ THashMap<String, Object> cells = new THashMap<String, Object>();\r
+ THashSet<String> usedRanges = new THashSet<String>();\r
\r
Resource resource;\r
\r
\r
@UpdateMethod\r
public boolean updateCells(ReadGraph g, Resource r) throws DatabaseException {\r
- cells.clear();\r
- usedRanges.clear();\r
- this.resource = null;\r
-\r
if(g.hasStatement(r)) {\r
this.resource = r;\r
+ THashMap<String, Object> newCells = new THashMap<String, Object>();\r
+ \r
g.getObjects(r, Layer0.getInstance(g).ConsistsOf);\r
Variable v = g.adapt(r, Variable.class);\r
for(Variable child : v.getChildren(g)) {\r
try {\r
SpreadsheetUtils.decodeCellAbsolute(name);\r
Variant value = child.getPropertyValue(g, SheetVariables.CONTENT, Bindings.VARIANT);\r
- cells.put(name, value.getValue());\r
+ newCells.put(name, value.getValue());\r
} catch (CellParseException e) {\r
} catch (MissingVariableException e) {\r
System.out.println("missing content for: " + name);\r
}\r
}\r
+ \r
+ boolean update = false;\r
+ if(newCells.size() == this.cells.size()) {\r
+ // Cells are the same size. There might not be changes. Next up: content\r
+ for(String key : this.cells.keySet()) {\r
+ if(!this.cells.get(key).equals(newCells.get(key))) {\r
+ update = true;\r
+ break;\r
+ }\r
+ }\r
+ } else {\r
+ update = true;\r
+ }\r
+ \r
+ if(update) {\r
+ this.cells = newCells;\r
+ this.usedRanges.clear();\r
+ return true;\r
+ }\r
}\r
- return true;\r
+ return false;\r
}\r
\r
public String getStringRepresentation() {\r
}\r
\r
\r
- public HashMap<String, Object> getCells() {\r
+ public THashMap<String, Object> getCells() {\r
return cells;\r
}\r
\r
this.monitor.message("Simulate " + model.getConfiguration().getLabel());\r
try {\r
model.update();\r
- if(experiment instanceof SysdynExperiment)\r
+ if(experiment instanceof SysdynExperiment) {\r
((SysdynExperiment)experiment).simulate(this.monitor, monitor);\r
-// model.simulate(this.monitor, monitor, experiment);\r
+ model.setStructureModified(false);\r
+ }\r
} catch (Exception e) {\r
e.printStackTrace();\r
this.monitor.showConsole();\r