]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
New "Model" concept in representation
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 12 Aug 2010 09:38:35 +0000 (09:38 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 12 Aug 2010 09:38:35 +0000 (09:38 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17144 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java
org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java

index 5c0f5f9cddc3a18b8c4949a42afe9ce46a9edcac..51e9ca7f2a89b9664013d9b12026e381a289e3fd 100644 (file)
@@ -74,7 +74,7 @@ public class ModelicaManager {
         }\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
@@ -131,7 +131,7 @@ public class ModelicaManager {
 \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
@@ -157,7 +157,7 @@ public class ModelicaManager {
         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
@@ -177,7 +177,7 @@ public class ModelicaManager {
                     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
index 267cae3571fbe5481ec53e99960b119f7f6564f3..ae744d8db081985748abc4a46cc78ae5da9f94f9 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Collections;
 \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
@@ -27,6 +28,7 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
             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
@@ -44,7 +46,7 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                         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
@@ -66,13 +68,20 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                         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
@@ -131,11 +140,11 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                 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
index ba42c8d8b9ef884589853bf8f135ccafea8be672..594cc680c10ee60a8d71375c1a6d7b7b11bca1ac 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Map;
 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
@@ -46,6 +47,7 @@ import org.simantics.sysdyn.modelica.ModelicaWriter;
 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
@@ -153,7 +155,7 @@ public class SysdynModel implements IMappingListener, IModel {
         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
@@ -161,17 +163,21 @@ public class SysdynModel implements IMappingListener, IModel {
             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
@@ -179,6 +185,8 @@ public class SysdynModel implements IMappingListener, IModel {
                     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
@@ -188,6 +196,8 @@ public class SysdynModel implements IMappingListener, IModel {
                 ModelicaManager.buildModel(simulationLocation, monitor);\r
 \r
             }  \r
+            \r
+            progressMonitor.worked(20);\r
 \r
             if(simulationLocation != null)\r
                 result = ModelicaManager.runModelica(\r
@@ -195,8 +205,13 @@ public class SysdynModel implements IMappingListener, IModel {
                         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
@@ -333,8 +348,8 @@ public class SysdynModel implements IMappingListener, IModel {
         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
@@ -343,7 +358,7 @@ public class SysdynModel implements IMappingListener, IModel {
             } 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
index 87e6fbe055d471b51865bc3f139cd59e42b0b458..670689df0b42cd60d5f44a0f93ba0f12e6d33d12 100644 (file)
@@ -24,15 +24,6 @@ import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;
 @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
@@ -41,6 +32,9 @@ public class Configuration {
     \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
@@ -88,5 +82,9 @@ public class Configuration {
        return moduleType;\r
     }\r
     \r
+    public Model getModel() {\r
+        return model;\r
+    }\r
+    \r
     \r
 }\r
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 (file)
index 0000000..35f0b26
--- /dev/null
@@ -0,0 +1,38 @@
+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
index c837a3caba25699578b6acd91ac3ac6f1e8d4e39..30536878b27580964de0e9b73bbf98f405672395 100644 (file)
@@ -36,6 +36,7 @@ public class SysdynSchema extends SimpleSchema {
             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
index 172d3275cb999b063f09513ec8526c39a03eec99..a81688a33770ce62bb41504d509ed9698f235023 100644 (file)
@@ -36,19 +36,28 @@ public class SimulationJob extends Job {
 \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