From: lempinen Date: Thu, 12 Aug 2010 09:38:35 +0000 (+0000) Subject: New "Model" concept in representation X-Git-Tag: simantics-1.2.0~111 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c7698ee6973a718d5fbf8d600da2dc1c4dd7c9a3;p=simantics%2Fsysdyn.git New "Model" concept in representation git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17144 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index 5c0f5f9c..51e9ca7f 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -74,7 +74,7 @@ public class ModelicaManager { } } - public static SimulationLocation createInputFiles(File simulationDir, String modelName, String modelText, HashMap inits) throws IOException { + public static SimulationLocation createInputFiles(File simulationDir, String modelName, String modelText, HashMap inits) throws IOException { modelName = modelName.replace(" ", ""); File modelFile = new File(simulationDir, modelName + ".mo"); File scriptFile = new File(simulationDir, modelName + ".mos"); @@ -131,7 +131,7 @@ public class ModelicaManager { } - public static SimulationResult runModelica(SimulationLocation simulationLocation, IModelicaMonitor monitor, HashMap inits) throws IOException { + public static SimulationResult runModelica(SimulationLocation simulationLocation, IModelicaMonitor monitor, HashMap inits) throws IOException { try { @@ -157,7 +157,7 @@ public class ModelicaManager { return null; } - private static void writeInits(SimulationLocation simulationLocation, HashMap inits) { + private static void writeInits(SimulationLocation simulationLocation, HashMap inits) { HashMap initials = new HashMap(); HashMap order = new HashMap(); @@ -177,7 +177,7 @@ public class ModelicaManager { String key = nn[1].trim(); String value = nn[0].trim(); if(inits.containsKey(key)) { - value = inits.get(key).toString(); + value = inits.get(key); } initials.put(key, value); order.put(orderNumber, key); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 267cae35..ae744d8d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -6,6 +6,7 @@ import java.util.Collections; import org.simantics.browsing.ui.SelectionProcessor; import org.simantics.browsing.ui.swt.ComparableTabContributor; +import org.simantics.db.Builtins; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; @@ -27,6 +28,7 @@ public class ResourceSelectionProcessor implements SelectionProcessor tabs = new ArrayList(); if (backend.isInstanceOf(r, dr.Element)) { Resource component = backend.getPossibleObject(r, mr.ElementToComponent); @@ -44,7 +46,7 @@ public class ResourceSelectionProcessor implements SelectionProcessor inits = getInits(configuration, ""); - - inits.put("startTime", configuration.startTime); - inits.put("stopTime", configuration.stopTime); - if(configuration.tolerance != null) { - inits.put("tolerance", configuration.tolerance); - } + HashMap inits = getInits(configuration, ""); + + Model model = configuration.getModel(); + inits.put("startTime", model.getStartTime().toString()); + inits.put("stopTime", model.getStopTime().toString()); + if(model.getSolver() != null) + inits.put("solver", model.getSolver()); + if(model.getTolerance() != null) + inits.put("tolerance", model.getTolerance().toString()); SimulationLocation simulationLocation = ModelicaManager.createInputFiles( simulationDir, @@ -179,6 +185,8 @@ public class SysdynModel implements IMappingListener, IModel { writer.toString(), inits); + progressMonitor.worked(20); + if (simulationLocation == null || !modelText.equals(previousModelStructure)) { previousModelStructure = modelText; System.out.println("== Modelica == "); @@ -188,6 +196,8 @@ public class SysdynModel implements IMappingListener, IModel { ModelicaManager.buildModel(simulationLocation, monitor); } + + progressMonitor.worked(20); if(simulationLocation != null) result = ModelicaManager.runModelica( @@ -195,8 +205,13 @@ public class SysdynModel implements IMappingListener, IModel { monitor, inits ); + + progressMonitor.worked(20); sysdynResult.setResult(result); + + progressMonitor.worked(20); + } catch(Exception e) { e.printStackTrace(); result = null; @@ -333,8 +348,8 @@ public class SysdynModel implements IMappingListener, IModel { return results; } - private HashMap getInits(Configuration configuration, String prefix) { - HashMap inits = new HashMap(); + private HashMap getInits(Configuration configuration, String prefix) { + HashMap inits = new HashMap(); for (IElement element : configuration.getElements()) { if (element instanceof Module) { Module module = (Module) element; @@ -343,7 +358,7 @@ public class SysdynModel implements IMappingListener, IModel { } else if (element instanceof IndependentVariable) { IndependentVariable variable = (IndependentVariable) element; if (variable.getExpression() instanceof ParameterExpression) { - inits.put(prefix + variable.getName(), ((ParameterExpression)variable.getExpression()).getValue()); + inits.put(prefix + variable.getName(), "" + ((ParameterExpression)variable.getExpression()).getValue()); } } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java index 87e6fbe0..670689df 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java @@ -24,15 +24,6 @@ import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; @GraphType("http://www.simantics.org/Sysdyn-1.0/Configuration") public class Configuration { - @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasStartTime") - public Double startTime = 0.0; - - @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasStopTime") - public Double stopTime = 10.0; - - @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasTolerance") - public Double tolerance; - @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") private String name; @@ -41,6 +32,9 @@ public class Configuration { @RelatedElement("http://www.simantics.org/Structural-1.0/Defines") private ModuleType moduleType; + + @RelatedElement("http://www.simantics.org/Simulation-1.0/IsConfigurationOf") + private Model model; @RelatedElements( value = "http://www.simantics.org/Layer0-1.0/ConsistsOf", @@ -88,5 +82,9 @@ public class Configuration { return moduleType; } + public Model getModel() { + return model; + } + } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java new file mode 100644 index 00000000..35f0b266 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java @@ -0,0 +1,38 @@ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; + +@GraphType("http://www.simantics.org/Sysdyn-1.0/SysdynModel") +public class Model { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasStartTime") + private Double startTime = 0.0; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasStopTime") + private Double stopTime = 10.0; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasTolerance") + private Double tolerance; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasSolver") + private String solver; + + public Double getStartTime() { + return startTime; + } + + public Double getStopTime() { + return stopTime; + } + + public Double getTolerance() { + return tolerance; + } + + public String getSolver() { + return solver; + } + + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java index c837a3ca..30536878 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java @@ -36,6 +36,7 @@ public class SysdynSchema extends SimpleSchema { addLinkType(MappingSchemas.fromAnnotations(g, Module.class)); addLinkType(MappingSchemas.fromAnnotations(g, Input.class)); addLinkType(MappingSchemas.fromAnnotations(g, ModuleType.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Model.class)); addLinkType(MappingSchemas.fromAnnotations(g, NormalExpression.class)); addLinkType(MappingSchemas.fromAnnotations(g, ParameterExpression.class)); addLinkType(MappingSchemas.fromAnnotations(g, StockExpression.class)); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java index 172d3275..a81688a3 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java @@ -36,19 +36,28 @@ public class SimulationJob extends Job { @Override protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask("Simulate " + model.getConfiguration().getName(), 100); this.monitor.clearConsole(); try { model.update(); - model.simulate(this.monitor); + model.simulate(this.monitor, monitor); + monitor.worked(50); } catch (Exception e) { e.printStackTrace(); return new Status( Status.ERROR, "org.simantics.sysdyn.ui", - "Simulation failed: " + e.getMessage()); + "Simulation failed: \n" + e.getMessage()); } + monitor.done(); return Status.OK_STATUS; } + + @Override + public boolean belongsTo(Object family) { + return "SimulationJob".equals(family); + } + private class ModelicaMonitor implements IModelicaMonitor {