}\r
}\r
\r
- public static SimulationLocation createInputFiles(File simulationDir, String modelName, String modelText, HashMap<String, Double> inits) throws IOException {\r
+ public static SimulationLocation createInputFiles(File simulationDir, String modelName, String modelText, HashMap<String, String> inits) throws IOException {\r
modelName = modelName.replace(" ", "");\r
File modelFile = new File(simulationDir, modelName + ".mo");\r
File scriptFile = new File(simulationDir, modelName + ".mos");\r
\r
}\r
\r
- public static SimulationResult runModelica(SimulationLocation simulationLocation, IModelicaMonitor monitor, HashMap<String, Double> inits) throws IOException {\r
+ public static SimulationResult runModelica(SimulationLocation simulationLocation, IModelicaMonitor monitor, HashMap<String, String> inits) throws IOException {\r
\r
try {\r
\r
return null;\r
}\r
\r
- private static void writeInits(SimulationLocation simulationLocation, HashMap<String, Double> inits) {\r
+ private static void writeInits(SimulationLocation simulationLocation, HashMap<String, String> inits) {\r
\r
HashMap<String, String> initials = new HashMap<String, String>();\r
HashMap<Integer, String> order = new HashMap<Integer, String>();\r
String key = nn[1].trim();\r
String value = nn[0].trim();\r
if(inits.containsKey(key)) {\r
- value = inits.get(key).toString();\r
+ value = inits.get(key);\r
}\r
initials.put(key, value);\r
order.put(orderNumber, key);\r
\r
import org.simantics.browsing.ui.SelectionProcessor;\r
import org.simantics.browsing.ui.swt.ComparableTabContributor;\r
+import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
SysdynResource sr = SysdynResource.getInstance(backend);\r
DiagramResource dr = DiagramResource.getInstance(backend);\r
ModelingResources mr = ModelingResources.getInstance(backend);\r
+ Builtins b = backend.getBuiltins();\r
Collection<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
if (backend.isInstanceOf(r, dr.Element)) {\r
Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
new EquationTab(),\r
2,\r
r,\r
- "Equation"));\r
+ "Equation"));\r
if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) {\r
tabs.add(new ComparableTabContributor(\r
new LookupTableTab(),\r
r,\r
"Input"));\r
}\r
- if (backend.isInstanceOf(r, sr.Configuration))\r
- return Collections.singleton(\r
- new ComparableTabContributor(\r
- new ConfigurationTab(),\r
- 0,\r
- r,\r
- "Configuration Properties"));\r
+ if (backend.isInstanceOf(r, sr.Configuration) || (backend.isInstanceOf(r, sr.SysdynModel))) {\r
+ Resource model;\r
+ if (backend.isInstanceOf(r, sr.Configuration))\r
+ model = backend.getPossibleObject(r, b.IsConfigurationOf);\r
+ else\r
+ model = r;\r
+ if (model != null)\r
+ return Collections.singleton(\r
+ new ComparableTabContributor(\r
+ new ConfigurationTab(),\r
+ 0,\r
+ model,\r
+ "Model Properties"));\r
+ }\r
if (backend.isInstanceOf(r, sr.Module)){\r
tabs.add(new ComparableTabContributor(\r
new ModuleTab(),\r
r = backend.getPossibleObject(r, mr.SymbolToComponentType);\r
if(r != null)\r
return Collections.singleton(\r
- new ComparableTabContributor(\r
- new ModuleTypeTab(),\r
- 0,\r
- r,\r
- "Module Type Properties"));\r
+ new ComparableTabContributor(\r
+ new ModuleTypeTab(),\r
+ 0,\r
+ r,\r
+ "Module Type Properties"));\r
}\r
} catch (ServiceException e) {\r
e.printStackTrace();\r
import java.util.Set;\r
import java.util.concurrent.CopyOnWriteArrayList;\r
\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\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.SysdynSchema;\r
import org.simantics.sysdyn.representation.expressions.ParameterExpression;\r
this.configurationResource = configurationResource; \r
}\r
\r
- public synchronized void simulate(IModelicaMonitor monitor) throws IOException {\r
+ public synchronized void simulate(IModelicaMonitor monitor, IProgressMonitor progressMonitor) throws IOException {\r
\r
try {\r
ModelicaWriter writer = new ModelicaWriter();\r
for(Configuration c : modules) {\r
writer.write(c);\r
}\r
+ \r
+ progressMonitor.worked(20);\r
\r
String modelText = writer.toString();\r
\r
- HashMap<String, Double> inits = getInits(configuration, "");\r
-\r
- inits.put("startTime", configuration.startTime);\r
- inits.put("stopTime", configuration.stopTime);\r
- if(configuration.tolerance != null) {\r
- inits.put("tolerance", configuration.tolerance);\r
- }\r
+ HashMap<String, String> inits = getInits(configuration, "");\r
+ \r
+ Model model = configuration.getModel();\r
\r
+ inits.put("startTime", model.getStartTime().toString());\r
+ inits.put("stopTime", model.getStopTime().toString());\r
+ if(model.getSolver() != null)\r
+ inits.put("solver", model.getSolver());\r
+ if(model.getTolerance() != null)\r
+ inits.put("tolerance", model.getTolerance().toString());\r
\r
SimulationLocation simulationLocation = ModelicaManager.createInputFiles(\r
simulationDir,\r
writer.toString(), \r
inits); \r
\r
+ progressMonitor.worked(20);\r
+ \r
if (simulationLocation == null || !modelText.equals(previousModelStructure)) {\r
previousModelStructure = modelText;\r
System.out.println("== Modelica == ");\r
ModelicaManager.buildModel(simulationLocation, monitor);\r
\r
} \r
+ \r
+ progressMonitor.worked(20);\r
\r
if(simulationLocation != null)\r
result = ModelicaManager.runModelica(\r
monitor,\r
inits\r
);\r
+ \r
+ progressMonitor.worked(20);\r
\r
sysdynResult.setResult(result);\r
+ \r
+ progressMonitor.worked(20);\r
+ \r
} catch(Exception e) {\r
e.printStackTrace();\r
result = null;\r
return results;\r
}\r
\r
- private HashMap<String, Double> getInits(Configuration configuration, String prefix) {\r
- HashMap<String, Double> inits = new HashMap<String, Double>();\r
+ private HashMap<String, String> getInits(Configuration configuration, String prefix) {\r
+ HashMap<String, String> inits = new HashMap<String, String>();\r
for (IElement element : configuration.getElements()) {\r
if (element instanceof Module) {\r
Module module = (Module) element;\r
} else if (element instanceof IndependentVariable) {\r
IndependentVariable variable = (IndependentVariable) element;\r
if (variable.getExpression() instanceof ParameterExpression) {\r
- inits.put(prefix + variable.getName(), ((ParameterExpression)variable.getExpression()).getValue());\r
+ inits.put(prefix + variable.getName(), "" + ((ParameterExpression)variable.getExpression()).getValue());\r
}\r
}\r
}\r
@GraphType("http://www.simantics.org/Sysdyn-1.0/Configuration")\r
public class Configuration {\r
\r
- @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasStartTime")\r
- public Double startTime = 0.0;\r
- \r
- @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasStopTime")\r
- public Double stopTime = 10.0;\r
- \r
- @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasTolerance")\r
- public Double tolerance;\r
- \r
@RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
private String name;\r
\r
\r
@RelatedElement("http://www.simantics.org/Structural-1.0/Defines")\r
private ModuleType moduleType;\r
+ \r
+ @RelatedElement("http://www.simantics.org/Simulation-1.0/IsConfigurationOf")\r
+ private Model model;\r
\r
@RelatedElements(\r
value = "http://www.simantics.org/Layer0-1.0/ConsistsOf",\r
return moduleType;\r
}\r
\r
+ public Model getModel() {\r
+ return model;\r
+ }\r
+ \r
\r
}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/SysdynModel")\r
+public class Model {\r
+\r
+ @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasStartTime")\r
+ private Double startTime = 0.0;\r
+ \r
+ @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasStopTime")\r
+ private Double stopTime = 10.0;\r
+ \r
+ @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasTolerance")\r
+ private Double tolerance;\r
+ \r
+ @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasSolver")\r
+ private String solver;\r
+\r
+ public Double getStartTime() {\r
+ return startTime;\r
+ }\r
+\r
+ public Double getStopTime() {\r
+ return stopTime;\r
+ }\r
+\r
+ public Double getTolerance() {\r
+ return tolerance;\r
+ }\r
+\r
+ public String getSolver() {\r
+ return solver;\r
+ }\r
+ \r
+ \r
+}\r
addLinkType(MappingSchemas.fromAnnotations(g, Module.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, Input.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, ModuleType.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Model.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, NormalExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, ParameterExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, StockExpression.class));\r
\r
@Override\r
protected IStatus run(IProgressMonitor monitor) {\r
+ monitor.beginTask("Simulate " + model.getConfiguration().getName(), 100);\r
this.monitor.clearConsole();\r
try {\r
model.update();\r
- model.simulate(this.monitor);\r
+ model.simulate(this.monitor, monitor);\r
+ monitor.worked(50);\r
} catch (Exception e) {\r
e.printStackTrace();\r
return new Status(\r
Status.ERROR, \r
"org.simantics.sysdyn.ui", \r
- "Simulation failed: " + e.getMessage());\r
+ "Simulation failed: \n" + e.getMessage());\r
} \r
+ monitor.done(); \r
return Status.OK_STATUS;\r
}\r
+ \r
+ @Override\r
+ public boolean belongsTo(Object family) {\r
+ return "SimulationJob".equals(family);\r
+ }\r
+\r
\r
private class ModelicaMonitor implements IModelicaMonitor {\r
\r