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);
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 (result != null) {
temp.applyResult(v, result);
} else if (// No condition fired, and we need to provide some default value.
v.reference.variable == v && v.equations.size() > 0) {
if (// not buffered
v.readIndex == v.writeIndex) {
// This is a pure temporary, so set value to default for use by later equations. Note that readTemp==writeTemp==true.
if (v.readTemp)
temp.set(v, v.type);
} else // buffered
{
// Not an accumulator, so copy its value
if (!v.externalWrite)
temp.set(v, temp.get(v));
}
}
}
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);
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class Population method init.
public void init(Simulator simulator) {
InstanceTemporaries temp = new InstanceInit(this, simulator);
InternalBackendData bed = temp.bed;
resolve(bed.globalReference);
Part instance = null;
if (bed.singleton) {
instance = (Part) valuesObject[bed.instances];
((Part) container).event.enqueue(instance);
instance.resolve();
}
for (Variable v : bed.globalInit) {
Type result = v.eval(temp);
if (result != null && v.writeIndex >= 0)
temp.setFinal(v, result);
// No need to handle references to external variables. These should all be classified as local rather than global equations.
}
// However, there may be external references to our variables. For example, instances of another part might adjust our $n'.
// zero external buffered variables that may be written before first finish()
clearExternalWriteBuffers(bed.globalBufferedExternalWrite);
for (Variable v : bed.globalBufferedExternalWrite) if (v.assignment == Variable.REPLACE)
temp.set(v, temp.get(v));
if (bed.index != null && !bed.singleton) {
// Using floats directly as index counter limits us to 24 bits, or about 16 million. Internal is not intended for large simulations, so this limitation is acceptable.
valuesFloat[bed.indexNext] = 0;
// indexAvailable is initially null
}
// it still cannot set its own population size.
if (bed.singleton) {
instance.init(simulator);
} else {
if (equations.connectionBindings == null) {
int requestedN = 1;
if (// n should be a constant holding a scalar. eval() just retrieves this.
bed.n.hasAttribute("constant"))
// n should be a constant holding a scalar. eval() just retrieves this.
requestedN = (int) ((Scalar) bed.n.eval(this)).value;
else
requestedN = (int) ((Scalar) get(bed.n)).value;
resize(simulator, requestedN);
} else {
// queue to evaluate our connections
simulator.connect(this);
}
}
}
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(false)) {
v.addDependencyOn(index);
}
container = container.container;
}
}
Aggregations