From: villberg Date: Mon, 30 Jun 2014 06:41:30 +0000 (+0000) Subject: refs #5042 X-Git-Tag: v1.29.0~254 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=0a42341d212ee1b27d06e6fc1b6f4b71592bce62;p=simantics%2Fsysdyn.git refs #5042 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29763 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java index db001506..68a0504b 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java @@ -13,18 +13,23 @@ package fi.semantum.sysdyn.solver; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.Map; public class Array implements IExpression { public static final Array FULL = new Array(); - private ArrayList elements = new ArrayList(); + final private ArrayList elements; public Array() { - + elements = new ArrayList(); } + public Array(int size) { + elements = new ArrayList(size); + } + public Array addElement(Object element) { if(element instanceof Constant) addElement(((Constant)element).value); else elements.add(element); @@ -70,7 +75,7 @@ public class Array implements IExpression { return elements.get(index); } - public Collection elements() { + public List elements() { return elements; } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ElementwiseProduct.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ElementwiseProduct.java index e3198cfe..f87529c5 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ElementwiseProduct.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ElementwiseProduct.java @@ -12,6 +12,7 @@ package fi.semantum.sysdyn.solver; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.Map; public class ElementwiseProduct implements IExpression { @@ -36,26 +37,24 @@ public class ElementwiseProduct implements IExpression { if(left instanceof Array && right instanceof Array) { Array la = (Array)left; Array ra = (Array)right; - Collection lae = la.elements(); - Collection rae = ra.elements(); + List lae = la.elements(); + List rae = ra.elements(); if(lae.size() != rae.size()) throw new UnsupportedOperationException(); - Iterator li = lae.iterator(); - Iterator ri = rae.iterator(); - Array result = new Array(); - for(int i=0;i lae = la.elements(); - Iterator li = lae.iterator(); - Array result = new Array(); - for(int i=0;i lae = la.elements(); + Array result = new Array(lae.size()); + for(Object o : lae) { + Double ld = (Double)o; result.addElement(ld*rd); } return result; diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java index b65afaff..e03b297d 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java @@ -42,6 +42,9 @@ public class Solver { private NodeCache cache; private boolean ready; + private boolean dirty; + private boolean started; + public Solver() { defaultStep = 0.1; start = 0; @@ -105,23 +108,27 @@ public class Solver { }); } + + private SimpleNode n; + private String codeCache = null; public void prepare(String input) throws Exception { long startNanos = System.nanoTime(); -// LineReader reader = new LineReader(input, cache); -// reader.parse(); -// -// model = reader.model; + if(!input.equals(codeCache)) { - StringReader reader = new StringReader(input); - ModelParser modelParser = new ModelParser(reader); - SimpleNode n = (SimpleNode)modelParser.stored_definition(); + StringReader reader = new StringReader(input); + ModelParser modelParser = new ModelParser(reader); + n = (SimpleNode)modelParser.stored_definition(); + + } + Parser parser = new Parser(); model = new Model(new Globals(), "", false); parser.walk(n, 0, model); - + codeCache = input; + env = new Environment(model, defaultStep, start); int size = model.prepare(); @@ -237,6 +244,8 @@ public class Solver { env.initial = false; ready = true; + started = false; + dirty = false; long endNanos = System.nanoTime(); @@ -252,15 +261,67 @@ public class Solver { return env.getValueArray(); } + public void aboutToRun() { + + if(!started && dirty) { + + // Solve all algebraic equations + Assignment[] assignments = model.assignmentArray; + for(int i=0;i String -> () deleteIC :: Variable -> String -> () + setPublishResults :: Variable -> Boolean -> () \ No newline at end of file diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/OldSysdynExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/OldSysdynExperiment.java index 326e8cbe..d9218f28 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/OldSysdynExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/OldSysdynExperiment.java @@ -86,6 +86,8 @@ public class OldSysdynExperiment extends SysdynExperiment { protected static String omcHome = null; public static OldSysdynExperiment INSTANCE; + + boolean publishResults = true; public OldSysdynExperiment(Resource experiment, Resource model) { super(experiment, model); @@ -822,6 +824,11 @@ public class OldSysdynExperiment extends SysdynExperiment { public void resultsChanged() { resultsChanged(false); } + + public void setPublishResults(boolean value) { + publishResults = value; + if(publishResults) resultsChanged(true); + } public void resultsChanged(boolean force) { long time = System.nanoTime(); @@ -841,6 +848,7 @@ public class OldSysdynExperiment extends SysdynExperiment { */ @Override public void updateSubscriptions() { + if(!publishResults) return; for(VariableValueSubscription subscription : getListenerSnapshot()) subscription.update(); skippedVariableUpdate = false; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java index 78d7902c..aaa959a5 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java @@ -35,6 +35,22 @@ import org.simantics.utils.DataContainer; public class SysdynExperiments { + public static void setPublishResults(ReadGraph graph, Variable variable, boolean value) throws DatabaseException { + + final IProject project = Simantics.getProject(); + if (project == null) return; + + final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + if(experimentManager == null) return; + + IExperiment exp = experimentManager.getExperiment(variable.getName(graph)); + if(exp instanceof OldSysdynExperiment) { + OldSysdynExperiment experiment = (OldSysdynExperiment)exp; + experiment.setPublishResults(value); + } + + } + public static String activateExperiment(IProgressMonitor monitor, final IProject project, final IExperimentManager manager, final Resource experimentResource) { if(monitor == null) monitor = new NullProgressMonitor(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/solver/InternalSolver.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/solver/InternalSolver.java index 6835e191..e7cd7bf1 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/solver/InternalSolver.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/solver/InternalSolver.java @@ -197,6 +197,7 @@ public class InternalSolver implements ISolver { @Override public void prepareToStep() throws Exception { + solver.aboutToRun(); } @Override