From: lempinen Date: Fri, 11 Jan 2013 10:35:59 +0000 (+0000) Subject: Preparing for new OpenModelica release (refs #3878) X-Git-Tag: simantics-1.10.1~83 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=23d8beba223a85ce2e01c5d6ebb74292d25f23d3;p=simantics%2Fsysdyn.git Preparing for new OpenModelica release (refs #3878) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26597 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 57baedc4..002c340a 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -386,28 +386,27 @@ public class ModelicaManager { s.close(); } - - public static void createFullMo(SimulationLocation simulationLocation, IModelicaMonitor monitor) throws ModelicaException { - // Create full .mo for parameter comparison - ArrayList parameters = new ArrayList(); - parameters.add(simulationLocation.fullMosFile.getAbsolutePath()); - Process process = runOMC(simulationLocation.simulationDir, monitor, parameters); + private static void trimExtraFromFullModel(SimulationLocation simulationLocation) { try { - process.waitFor(); - FileInputStream fs = new FileInputStream(simulationLocation.fullModel); InputStreamReader in = new InputStreamReader(fs); BufferedReader br = new BufferedReader(in); StringBuffer sb = new StringBuffer(); - boolean OMBlock = false; String textinLine; + boolean openmodelicaflag = false; + int breakpoint = 0; while((textinLine = br.readLine()) != null) { - if(textinLine.contains("OpenModelica")) - OMBlock = Boolean.FALSE.equals(OMBlock); - else - if(!OMBlock) - sb.append(textinLine + "\n"); // if you don’t put the \n you will have all the code on one line as fer said + if(openmodelicaflag == true) { + breakpoint = sb.length(); + openmodelicaflag = false; + } + + if(textinLine.contains("end OpenModelica;")) + openmodelicaflag = true; + + + sb.append(textinLine + "\n"); // if you don’t put the \n you will have all the code on one line as fer said } br.close(); @@ -416,15 +415,27 @@ public class ModelicaManager { FileWriter fstream = new FileWriter(simulationLocation.fullModel); BufferedWriter outobj = new BufferedWriter(fstream); - outobj.write(sb.toString()); + outobj.write(sb.substring(breakpoint)); outobj.close(); fstream.close(); - } catch (IOException e) { e.printStackTrace(); + } + } + + public static void createFullMo(SimulationLocation simulationLocation, IModelicaMonitor monitor) throws ModelicaException { + // Create full .mo for parameter comparison + ArrayList parameters = new ArrayList(); + parameters.add(simulationLocation.fullMosFile.getAbsolutePath()); + Process process = runOMC(simulationLocation.simulationDir, monitor, parameters); + try { + process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } + + trimExtraFromFullModel(simulationLocation); + } /** * Builds a model with omc. The location of required files is @@ -584,7 +595,7 @@ public class ModelicaManager { while ((line = in.readLine()) != null) { line = line.trim(); if(line.startsWith("parameter") && line.contains("=") && line.contains(";")) { - String[] split = line.split("="); + String[] split = line.split(" = "); name = split[0].trim(); name = name.substring(name.lastIndexOf(" ") + 1); value = split[1].trim(); @@ -623,15 +634,18 @@ public class ModelicaManager { ArrayList parameters = new ArrayList(); parameters.add(simulationLocation.fullMosFile.getAbsolutePath()); - Process process = runOMC(simulationLocation.simulationDir, monitor, parameters); + Process process = runOMC(simulationLocation.simulationDir, null, parameters); process.waitFor(); + trimExtraFromFullModel(simulationLocation); + // Create simulation files from the full description parameters.clear(); parameters.add("+s"); parameters.add(simulationLocation.fullModel.getAbsolutePath()); - Process p = runOMC(simulationLocation.fullModelDir, null, parameters); + Process p = runOMC(simulationLocation.fullModelDir, monitor, parameters); + p.waitFor(); // Find the new init file 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 bcf7d3a6..23359334 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -145,6 +145,7 @@ public class ModelicaWriter { * @param b String builder */ private static void writeConfiguration(Configuration configuration, HashSet sheetNames, StringBuilder b) { + boolean defTime = true; String app; // Lists for storing different configuration elements @@ -220,16 +221,17 @@ public class ModelicaWriter { if (app != null) b.append(app); } - - // Time variable for FMU (game) simulations - if(configuration.isGameConfiguration()) { - if(configuration.getModel() != null) - // Parameter for model root. Values changed in FMU simulator - b.append(" parameter Real time = 0;\n"); - else - // Continuous variable for module instances - b.append(" Real time;\n"); + if(defTime) { + // Time variable for FMU (game) simulations + if(configuration.isGameConfiguration()) { + if(configuration.getModel() != null) + // Parameter for model root. Values changed in FMU simulator + b.append(" parameter Real time = 0;\n"); + else + // Continuous variable for module instances + b.append(" Real time;\n"); + } } if(!modules.isEmpty()) { @@ -304,11 +306,13 @@ public class ModelicaWriter { } } - if(configuration.isGameConfiguration() && !modules.isEmpty()) { - b.append("// Time values for module\n"); - for(Module m : modules) { - b.append(" " + m.getName() + ".time = time;\n"); - } + if(defTime) { + if(configuration.isGameConfiguration() && !modules.isEmpty()) { + b.append("// Time values for module\n"); + for(Module m : modules) { + b.append(" " + m.getName() + ".time = time;\n"); + } + } } if(className != null) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/FormatUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/FormatUtils.java index 568774bc..0427225a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/FormatUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/FormatUtils.java @@ -11,6 +11,9 @@ *******************************************************************************/ package org.simantics.sysdyn.representation.utils; +import java.util.ArrayList; + +import org.simantics.sysdyn.representation.Enumeration; import org.simantics.sysdyn.representation.IndependentVariable; import org.simantics.sysdyn.representation.Variability; import org.simantics.sysdyn.representation.Variable; @@ -87,7 +90,7 @@ public class FormatUtils { refName + " >= 0 then ("; } - String conditionEnd = ") else pre(" + variable.getName() +")"; + String conditionEnd = ") else " + getZeros(variable); expression = condition + expression + conditionEnd; } @@ -95,4 +98,22 @@ public class FormatUtils { return expression; } + private static String getZeros(Variable variable) { + ArrayList enumerations = variable.getArrayIndexes(); + if(enumerations == null || enumerations.size() == 0) + return "0"; + else { + StringBuilder sb = new StringBuilder(); + sb.append("zeros("); + boolean first = true; + for(Enumeration e : enumerations) { + if(!first) + sb.append(", "); + first = false; + sb.append(e.getName() + ".size"); + } + sb.append(")"); + return sb.toString(); + } + } }