From: villberg Date: Thu, 21 Aug 2014 08:23:13 +0000 (+0000) Subject: refs #5198 X-Git-Tag: v1.29.0~227 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=987be97cd93be0d5d6db24f1c88dcfffb23df97b;p=simantics%2Fsysdyn.git refs #5198 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30111 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 68a0504b..d0ceff4f 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 @@ -21,6 +21,8 @@ public class Array implements IExpression { public static final Array FULL = new Array(); final private ArrayList elements; + + boolean isVector = true; public Array() { elements = new ArrayList(); @@ -32,7 +34,15 @@ public class Array implements IExpression { public Array addElement(Object element) { if(element instanceof Constant) addElement(((Constant)element).value); - else elements.add(element); + else { + +// if(element instanceof Double) +// if(Double.isNaN((Double)element)) +// throw new IllegalStateException(); + + if(element instanceof Array) isVector = false; + elements.add(element); + } return this; } @@ -307,6 +317,29 @@ public class Array implements IExpression { return result; } + public Array sub(Array other) { + Array result = new Array(); + Collection lae = elements(); + Collection rae = other.elements(); + if(lae.size() != rae.size()) throw new IllegalStateException(); + Iterator li = lae.iterator(); + Iterator ri = rae.iterator(); + for(int i=0;i lae = elements(); @@ -329,6 +362,27 @@ public class Array implements IExpression { } return result; } + /* + * Both arrays are vectors + */ + public double inner(Array other) { + double result = 0; + Collection lae = elements(); + Collection rae = other.elements(); + if(lae.size() != rae.size()) throw new IllegalStateException(); + Iterator li = lae.iterator(); + Iterator ri = rae.iterator(); + for(int i=0;i rae = ra.elements(); + Array result = new Array(rae.size()); + for(Object o : rae) { + Double rd = (Double)o; + result.addElement(ld*rd); + } + return result; } else { throw new UnsupportedOperationException(); } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Model.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Model.java index e4b1337a..a5fde8b0 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Model.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Model.java @@ -122,20 +122,54 @@ class Model implements IFrame { } Variable[] parameters = fn.parameters(); + Object[] ps = new Object[parameters.length]; + int vectorDimension = 0; for(int i=0;i 0) { + + Array result = new Array(); + + for(int i=0;i 0 && loops++ < 50) { + StringBuilder errors = null; + + while(condition > 0 && loops++ < MAX_LOOPS) { + if(loops == MAX_LOOPS) errors = new StringBuilder(); + if(PRINT_EXCEPTIONS) { System.err.println("== LOOP " + loops + " =="); } @@ -164,14 +176,21 @@ public class Solver { for(ParameterDeclaration pd : model.parameters) { try { if(!pd.assigned) { - pd.variable.assign(env, null, pd.modification.evaluate(env)); + Object value = pd.modification.evaluate(env); + validate(pd.variable, value); + pd.variable.assign(env, null, value); pd.assigned = true; } } catch (Exception e) { + String error = " -" + pd.variable.toString() + ": " + e.getMessage(); + if(errors != null) { + errors.append(error); + errors.append("\n"); + } condition++; if(PRINT_EXCEPTIONS) { e.printStackTrace(); - System.err.println("failed to assign " + pd.variable.toString()); + System.err.println(error); } } } @@ -187,12 +206,16 @@ public class Solver { if(arg.name.endsWith("start")) { Object value = arg.modification.evaluate(env); if(vd.variable.base.dimension() == 1) { + validate(vd.variable, value); vd.variable.assign(env, null, value); } else { + validate(vd.variable, value); if(value instanceof Double) { Array array = new Array(); for(int i=0;i +| | { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } | @@ -641,7 +641,7 @@ void arithmetic_expression() : { void add_op() : { } { - "+" { jjtThis.op = "+";} | "-" { jjtThis.op = "-";} | ".+" | ".-" + "+" { jjtThis.op = "+";} | "-" { jjtThis.op = "-";} | ".+" { jjtThis.op = ".+";} | ".-" { jjtThis.op = ".-";} } @@ -652,7 +652,7 @@ void term() : { void mul_op() : { } { - "*" { jjtThis.op = "*";} | "/" { jjtThis.op = "/";} | ".*" { jjtThis.op = ".*";} | "./" { jjtThis.op = "./";} + ".*" { jjtThis.op = ".*";} | "./" { jjtThis.op = "./";} | "*" { jjtThis.op = "*";} | "/" { jjtThis.op = "/";} } void factor() : {