use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class NodeVariable method enforceOneLine.
/**
* Ensures that a variable either has multiple equations or a one-line expression,
* but not both.
* This method is independent of any given NodeVariable so it can be used at
* various points in processing.
*/
public static void enforceOneLine(MNode source) {
// Collect info
int equationCount = 0;
MNode equation = null;
for (MNode n : source) {
String key = n.key();
if (key.startsWith("@")) {
equation = n;
equationCount++;
}
}
String value = source.get();
if (value.startsWith("$kill"))
value = "";
Variable.ParsedValue pieces = new Variable.ParsedValue(value);
boolean empty = pieces.expression.isEmpty() && pieces.condition.isEmpty();
// Collapse or expand
if (equationCount > 0) {
if (!empty) {
// Expand
source.set(pieces.combiner);
// may override an existing equation
source.set("@" + pieces.condition, pieces.expression);
} else if (equationCount == 1) {
// Collapse
String key = equation.key();
source.clear(key);
if (key.equals("@"))
source.set(pieces.combiner + equation.get());
else
source.set(pieces.combiner + equation.get() + key);
}
}
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class Output method dependOnIndex.
public void dependOnIndex(Variable v, EquationSet container) {
while (container != null) {
Variable index = container.find(new Variable("$index"));
if (index != null && !container.isSingleton()) {
v.addDependencyOn(index);
}
container = container.container;
}
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class EventSpikeSingle method run.
public void run(Simulator simulator) {
setFlag();
simulator.integrate(target);
target.update(simulator);
boolean live = target.finish(simulator);
InternalBackendData bed = (InternalBackendData) target.equations.backendData;
for (Variable v : bed.eventReferences) ((Instance) target.valuesObject[v.reference.index]).finishEvent(v.reference.variable);
if (!live)
target.dequeue();
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class InternalBackendData method dumpVariableList.
public void dumpVariableList(String name, List<Variable> list) {
System.out.print(" " + name + ":");
for (Variable v : list) System.out.print(" " + v.nameString());
System.out.println();
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class Part method update.
public void update(Simulator simulator) {
InstanceTemporaries temp = new InstanceTemporaries(this, simulator, false);
for (Variable v : temp.bed.localUpdate) {
Type result = v.eval(temp);
// this is a "dummy" variable, so calling eval() was all we needed to do
if (v.reference.variable.writeIndex < 0)
continue;
if (// no condition matched
result == null) {
if (v.reference.variable != v || v.equations.size() == 0)
continue;
if (// not buffered
v.readIndex == v.writeIndex) {
// This is a pure temporary for which no equation fired, so set value to default for use by later equations. Note that readTemp==writeTemp==true.
if (v.readTemp)
temp.set(v, v.type);
continue;
}
// Variable is buffered
if (// not an accumulator
v.assignment == Variable.REPLACE) {
// so copy its value
temp.set(v, temp.get(v));
}
continue;
}
if (v.assignment == Variable.REPLACE) {
temp.set(v, result);
} else {
// the rest of these require knowing the current value of the working result, which is most likely external buffered
Type current = temp.getFinal(v.reference);
switch(v.assignment) {
case Variable.ADD:
temp.set(v, current.add(result));
break;
case Variable.MULTIPLY:
temp.set(v, current.multiply(result));
break;
case Variable.DIVIDE:
temp.set(v, current.divide(result));
break;
case Variable.MIN:
temp.set(v, current.min(result));
break;
case Variable.MAX:
temp.set(v, current.max(result));
break;
}
}
}
for (Variable v : temp.bed.localBufferedInternalUpdate) {
temp.setFinal(v, temp.getFinal(v));
}
int populations = equations.parts.size();
for (int i = 0; i < populations; i++) ((Population) valuesObject[i]).update(simulator);
}
Aggregations