From: lempinen Date: Thu, 5 Aug 2010 12:44:24 +0000 (+0000) Subject: Another example model (simulation not working) X-Git-Tag: simantics-1.2.0~133 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1719b7cb976b7629188cf0d5d9a34b1f2ca6e7f0;p=simantics%2Fsysdyn.git Another example model (simulation not working) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16964 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java index da9f555a..e95f4987 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java @@ -21,6 +21,8 @@ import org.simantics.db.exception.DatabaseException; public class SysdynResource { public final Resource Admin1; + public final Resource Admin1; + public final Resource Admin2; public final Resource Admin2; public final Resource Auxiliary; public final Resource AuxiliarySymbol; @@ -41,7 +43,6 @@ public class SysdynResource { public final Resource DiagramToCompositeMapping; public final Resource Experiment; public final Resource Expression; - public final Resource FirstModule; public final Resource Flow; public final Resource FlowConnection; public final Resource GameExperiment; @@ -86,7 +87,6 @@ public class SysdynResource { public final Resource RefersTo; public final Resource Result; public final Resource RootConfigurationDiagram; - public final Resource SecondModule; public final Resource SimulateOnChangeExperiment; public final Resource Stock; public final Resource StockExpression; @@ -100,11 +100,18 @@ public class SysdynResource { public final Resource ValveSymbol; public final Resource Variable; public final Resource WithLookupExpression; + public final Resource WorkModelConfigurationDiagram; + public final Resource WorkModuleConfigurationDiagram; + public final Resource WorkSymbol; + public final Resource WorkforceModuleConfigurationDiagram; + public final Resource WorkforceSymbol; public final Resource angle; public static class URIs { + public static final String Admin1 = "http://www.simantics.org/Sysdyn-1.0/Admin1"; public static final String Admin1 = "http://www.simantics.org/Sysdyn-1.0/Admin1"; public static final String Admin2 = "http://www.simantics.org/Sysdyn-1.0/Admin2"; + public static final String Admin2 = "http://www.simantics.org/Sysdyn-1.0/Admin2"; public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary"; public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"; public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment"; @@ -124,7 +131,6 @@ public class SysdynResource { public static final String DiagramToCompositeMapping = "http://www.simantics.org/Sysdyn-1.0/DiagramToCompositeMapping"; public static final String Experiment = "http://www.simantics.org/Sysdyn-1.0/Experiment"; public static final String Expression = "http://www.simantics.org/Sysdyn-1.0/Expression"; - public static final String FirstModule = "http://www.simantics.org/Sysdyn-1.0/FirstModule"; public static final String Flow = "http://www.simantics.org/Sysdyn-1.0/Flow"; public static final String FlowConnection = "http://www.simantics.org/Sysdyn-1.0/FlowConnection"; public static final String GameExperiment = "http://www.simantics.org/Sysdyn-1.0/GameExperiment"; @@ -169,7 +175,6 @@ public class SysdynResource { public static final String RefersTo = "http://www.simantics.org/Sysdyn-1.0/RefersTo"; public static final String Result = "http://www.simantics.org/Sysdyn-1.0/Result"; public static final String RootConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/RootConfigurationDiagram"; - public static final String SecondModule = "http://www.simantics.org/Sysdyn-1.0/SecondModule"; public static final String SimulateOnChangeExperiment = "http://www.simantics.org/Sysdyn-1.0/SimulateOnChangeExperiment"; public static final String Stock = "http://www.simantics.org/Sysdyn-1.0/Stock"; public static final String StockExpression = "http://www.simantics.org/Sysdyn-1.0/StockExpression"; @@ -183,6 +188,11 @@ public class SysdynResource { public static final String ValveSymbol = "http://www.simantics.org/Sysdyn-1.0/ValveSymbol"; public static final String Variable = "http://www.simantics.org/Sysdyn-1.0/Variable"; public static final String WithLookupExpression = "http://www.simantics.org/Sysdyn-1.0/WithLookupExpression"; + public static final String WorkModelConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/WorkModelConfigurationDiagram"; + public static final String WorkModuleConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/WorkModuleConfigurationDiagram"; + public static final String WorkSymbol = "http://www.simantics.org/Sysdyn-1.0/WorkSymbol"; + public static final String WorkforceModuleConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/WorkforceModuleConfigurationDiagram"; + public static final String WorkforceSymbol = "http://www.simantics.org/Sysdyn-1.0/WorkforceSymbol"; public static final String angle = "http://www.simantics.org/Sysdyn-1.0/angle"; } @@ -197,6 +207,8 @@ public class SysdynResource { public SysdynResource(ReadGraph graph) { Admin1 = getResourceOrNull(graph, URIs.Admin1); + Admin1 = getResourceOrNull(graph, URIs.Admin1); + Admin2 = getResourceOrNull(graph, URIs.Admin2); Admin2 = getResourceOrNull(graph, URIs.Admin2); Auxiliary = getResourceOrNull(graph, URIs.Auxiliary); AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol); @@ -217,7 +229,6 @@ public class SysdynResource { DiagramToCompositeMapping = getResourceOrNull(graph, URIs.DiagramToCompositeMapping); Experiment = getResourceOrNull(graph, URIs.Experiment); Expression = getResourceOrNull(graph, URIs.Expression); - FirstModule = getResourceOrNull(graph, URIs.FirstModule); Flow = getResourceOrNull(graph, URIs.Flow); FlowConnection = getResourceOrNull(graph, URIs.FlowConnection); GameExperiment = getResourceOrNull(graph, URIs.GameExperiment); @@ -262,7 +273,6 @@ public class SysdynResource { RefersTo = getResourceOrNull(graph, URIs.RefersTo); Result = getResourceOrNull(graph, URIs.Result); RootConfigurationDiagram = getResourceOrNull(graph, URIs.RootConfigurationDiagram); - SecondModule = getResourceOrNull(graph, URIs.SecondModule); SimulateOnChangeExperiment = getResourceOrNull(graph, URIs.SimulateOnChangeExperiment); Stock = getResourceOrNull(graph, URIs.Stock); StockExpression = getResourceOrNull(graph, URIs.StockExpression); @@ -276,6 +286,11 @@ public class SysdynResource { ValveSymbol = getResourceOrNull(graph, URIs.ValveSymbol); Variable = getResourceOrNull(graph, URIs.Variable); WithLookupExpression = getResourceOrNull(graph, URIs.WithLookupExpression); + WorkModelConfigurationDiagram = getResourceOrNull(graph, URIs.WorkModelConfigurationDiagram); + WorkModuleConfigurationDiagram = getResourceOrNull(graph, URIs.WorkModuleConfigurationDiagram); + WorkSymbol = getResourceOrNull(graph, URIs.WorkSymbol); + WorkforceModuleConfigurationDiagram = getResourceOrNull(graph, URIs.WorkforceModuleConfigurationDiagram); + WorkforceSymbol = getResourceOrNull(graph, URIs.WorkforceSymbol); angle = getResourceOrNull(graph, URIs.angle); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java index f3abe32e..21aef064 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -24,20 +24,21 @@ import org.simantics.sysdyn.representation.Stock; import org.simantics.sysdyn.representation.IndependentVariable; import org.simantics.sysdyn.representation.Variable; import org.simantics.sysdyn.representation.expressions.IExpression; -import org.simantics.sysdyn.representation.expressions.WithLookupExpression; public class ModelicaWriter { StringBuilder b = new StringBuilder(); String app; boolean initialEquations = false; - boolean insertInterpolate = false; + boolean functionsWritten = false; public void write(Configuration conf) { writeConfiguration(conf); - if(insertInterpolate) + if(!functionsWritten) { + + // THIS INTERPOLATE DOESN'T WORK PROPERLY b.append( "\nfunction Interpolate\n" + " input Real table[:, 2];\n" + @@ -54,7 +55,23 @@ public class ModelicaWriter { " yp := table[i,2] + (xp - table[i,1]) * (table[i+1,2] - table[i,2]) / (table[i+1,1] - table[i,1]);\n" + " end if;\n" + " end for;\n" + - " end Interpolate;\n"); + "end Interpolate;\n"); + + b.append( + "function xidz\n" + + " input Real first;\n" + + " input Real second;\n" + + " input Real x;\n" + + " output Real answer;\n" + + "algorithm\n" + + " if second > 0.0 or second < 0.0 then\n" + + " answer := first / second;\n" + + " else\n" + + " answer := x;\n" + + " end if;\n" + + "end xidz;\n\n\n"); + functionsWritten = true; + } } private void writeConfiguration(Configuration configuration) { @@ -68,7 +85,7 @@ public class ModelicaWriter { ArrayList inputDependencies = new ArrayList(); ArrayList outputDependencies = new ArrayList(); HashMap> moduleInputs = new HashMap>(); - + // Initialize lists for(IElement element : configuration.getElements()) { if(element instanceof IndependentVariable) { @@ -98,31 +115,30 @@ public class ModelicaWriter { ModuleType mt = configuration.getModuleType(); String className = mt != null ? (mt.getName().replace(" ", "")) : (configuration.getName().replace(" ", "")); b.append("class ").append(className).append('\n'); - + b.append("// Variable definitions\n"); for(IndependentVariable variable : variables) { IExpression expr = variable.getExpression(); - if(expr != null && insertInterpolate == false) { + if(expr != null) { app = expr.getDeclaration(variable); if (app != null) b.append(app); - if (expr instanceof WithLookupExpression) insertInterpolate = true; } } - + if(!modules.isEmpty()) { b.append("// Module definitions\n"); for(Module m : modules) { b.append(" " + m.getType().getName() + " " + m.getName() + ";\n"); } } - + if(!inputs.isEmpty()) { b.append("// Input definitions\n"); for(Input i : inputs) { b.append(" " + i.getType() + " " + i.getName() + ";\n"); } } - + for(Stock stock : stocks) { IExpression expr = stock.getExpression(); if(expr != null) { @@ -166,21 +182,21 @@ public class ModelicaWriter { b.append(" " + module.getName() + "." + reference.getName() + " = " + variable.getName() + ";\n"); moduleInputs.get(module.getName()).remove(reference); } - + b.append("// Default values for inputs in modules\n"); for(String moduleLabel : moduleInputs.keySet()) { for(Input input : moduleInputs.get(moduleLabel)) { b.append(" " + moduleLabel + "." + input.getName() + " = " + input.getDefaultInputValue() + ";\n"); } } - + b.append("end ").append(className).append(";\n\n"); // for(Module m : modules) { // writeConfiguration(m.getConfiguration()); // } - + } public String escape(String name) { diff --git a/sysdyn_ontologies/sysdyn.graph b/sysdyn_ontologies/sysdyn.graph index ce872424..78f3a9b7 100644 --- a/sysdyn_ontologies/sysdyn.graph +++ b/sysdyn_ontologies/sysdyn.graph @@ -453,132 +453,626 @@ DependencyConnection 0 then 0 else WorkAllocation" : L0.String + ErrorsGenerated @ "ErrorsGenerated" : Valve + tag(MOD.Mapped) + HasExpression _ : NormalExpression + HasEquation "(1-WorkQuality)*WorkingSpeed" : L0.String + ErrorsFoundRate @ "ErrorsFoundRate" : Valve + tag(MOD.Mapped) HasExpression _ : NormalExpression - HasEquation "2+2" : L0.String - FirstModuleStock @ "Stock1" : Stock + HasEquation "Errors/ErrorsFoundTime" : L0.String + + ## Stocks + WorkToDo @ "WorkToDo" : Stock + tag(MOD.Mapped) + HasExpression _ : StockExpression + HasInitialEquation "ProjectWorkAmount" : L0.String + WorkDone @ "WorkDone" : Stock + tag(MOD.Mapped) HasExpression _ : StockExpression - HasInitialEquation "0" : L0.String - FirstModuleCloud : Cloud - FirstModuleOutput1 @ "Valve" : Valve - HasUnit "s" : L0.String + HasInitialEquation "0" : L0.String + Errors @ "Errors" : Stock + tag(MOD.Mapped) + HasExpression _ : StockExpression + HasInitialEquation "0" : L0.String + + ## Auxiliaries + TimeToDeadline @ "TimeToDeadline" : Auxiliary + tag(MOD.Mapped) HasExpression _ : NormalExpression - HasEquation "Aux1 + Aux2" : L0.String - tag(IsOutput) - _ : Flow - HasHead FirstModuleOutput1 - HasTail FirstModuleCloud - _ : Flow - HasHead FirstModuleStock - HasTail FirstModuleOutput1 - _ : Dependency - HasHead FirstModuleOutput1 - HasTail FirstModuleInput1 - _ : Dependency - HasHead FirstModuleOutput1 - HasTail FirstModuleInput2 - _ : Dependency - HasHead Moduuli2 - HasTail FirstModuleOutput1 - RefersTo SecondModuleInput1 - -Module2 @ "SecondModule" 0 then 0 else if TimeToDeadline < 0.0 or TimeToDeadline > 0.0 then WorkToDo / TimeToDeadline else MaximumWorkingSpeed" : L0.String + WorkAllocation @ "WorkAllocation" : Auxiliary + tag(MOD.Mapped) HasExpression _ : NormalExpression - HasEquation "2+2" : L0.String - SecondModuleInput2 @ "Aux2" : Auxiliary - HasUnit "s" : L0.String + HasEquation "xidz(first = RequiredWorkingSpeed, second = RequiredWorkingSpeed + RequiredWorkingSpeedOtherProjectsInput, x = 0.0) * PossibleWorkingSpeedInput" : L0.String + ProjectIsReady @ "ProjectIsReady" : Auxiliary + tag(MOD.Mapped) + HasExpression _ : NormalExpression + HasEquation "if ProjectReadyness >= 1 then 1 else 0" : L0.String + ProjectReadyness @ "ProjectReadyness" : Auxiliary + tag(MOD.Mapped) HasExpression _ : NormalExpression - HasEquation "2+2" : L0.String - SecondModuleStock @ "Stock1" : Stock + HasEquation "WorkDone/ProjectWorkAmount" : L0.String + ErrorsFoundTime @ "ErrorsFoundTime" : Auxiliary + tag(MOD.Mapped) + HasExpression _ : WithLookupExpression + HasEquation "ProjectReadyness" : L0.String + HasLookup "{{0,5},{0.5,3},{1,0.5},{2,0.5}}" : L0.String + + ## Inputs + WorkCompletionTimeInput @ "WorkCompletionTimeInput" : Input + tag(MOD.Mapped) + PossibleWorkingSpeedInput @ "PossibleWorkingSpeedInput" : Input + tag(MOD.Mapped) + RequiredWorkingSpeedOtherProjectsInput @ "RequiredWorkingSpeedOtherProjectsInput" : Input + tag(MOD.Mapped) + + c31 : Cloud + + d31 : Dependency + conf_dep(TimeToDeadline, WorkCompletionTimeInput) + d32 : Dependency + conf_dep(RequiredWorkingSpeed, MaximumWorkingSpeed) + d33 : Dependency + conf_dep(RequiredWorkingSpeed, TimeToDeadline) + d34 : Dependency + conf_dep(RequiredWorkingSpeed, ProjectIsReady) + d35 : Dependency + conf_dep(RequiredWorkingSpeed, WorkToDo) + d36 : Dependency + conf_dep(WorkAllocation, RequiredWorkingSpeedOtherProjectsInput) + d37 : Dependency + conf_dep(WorkAllocation, PossibleWorkingSpeedInput) + d38 : Dependency + conf_dep(WorkAllocation, RequiredWorkingSpeed) + d39 : Dependency + conf_dep(ProjectIsReady, ProjectReadyness) + d40 : Dependency + conf_dep(ProjectReadyness, WorkDone) + d41 : Dependency + conf_dep(ProjectReadyness, ProjectWorkAmount) + d42 : Dependency + conf_dep(WorkingSpeed, WorkAllocation) + d43 : Dependency + conf_dep(WorkingSpeed, ProjectIsReady) + d44 : Dependency + conf_dep(ErrorsGenerated, WorkingSpeed) + d45 : Dependency + conf_dep(ErrorsGenerated, WorkQuality) + d46 : Dependency + conf_dep(ErrorsFoundRate, Errors) + d47 : Dependency + conf_dep(ErrorsFoundRate, ErrorsFoundTime) + d48 : Dependency + conf_dep(ErrorsFoundTime, ProjectReadyness) + f31 : Flow + conf_dep(WorkingSpeed, WorkToDo) + f32 : Flow + conf_dep(WorkDone, WorkingSpeed) + f33 : Flow + conf_dep(ErrorsGenerated, c31) + f34 : Flow + conf_dep(Errors, ErrorsGenerated) + f35 : Flow + conf_dep(ErrorsFoundRate, Errors) + f36 : Flow + conf_dep(ErrorsFoundRate, WorkDone) + f37 : Flow + conf_dep(WorkToDo, ErrorsFoundRate) + +WorkModuleConfigurationDiagram : ConfigurationDiagram