use of gov.sandia.n2a.language.operator.LE in project n2a by frothga.
the class EquationSet method determineDuration.
/**
* Infers length of simulation based on contents of equation set, particularly
* an expression for top-level $p that involves $t.
* Depends on results of: determineTypes() -- to set up Variable.type member with usable values
*/
public void determineDuration() {
Variable p = find(new Variable("$p", 0));
if (p != null && p.equations.size() == 1) {
Operator expression = p.equations.first().expression;
Operator variable = null;
Operator value = null;
if (// only true if expression is not null
expression instanceof LT || expression instanceof LE) {
OperatorBinary comparison = (OperatorBinary) expression;
variable = comparison.operand0;
value = comparison.operand1;
} else if (expression instanceof GT || expression instanceof GE) {
OperatorBinary comparison = (OperatorBinary) expression;
variable = comparison.operand1;
value = comparison.operand0;
}
if (variable instanceof AccessVariable && ((AccessVariable) variable).name.equals("$t")) {
Instance instance = new Instance() {
// all AccessVariable objects will reach here first, and get back the Variable.type field
public Type get(VariableReference r) throws EvaluationException {
return r.variable.type;
}
};
Type result = value.eval(instance);
if (result instanceof Scalar)
setNamedValue("duration", new Double(((Scalar) result).value).toString());
}
}
}
Aggregations