use of gov.sandia.n2a.eqset.EquationSet in project n2a by frothga.
the class InternalBackend method createBackendData.
public static void createBackendData(EquationSet s) {
Object o = s.backendData;
if (!(o instanceof InternalBackendData)) {
InternalBackendData bed = new InternalBackendData(s);
s.backendData = bed;
// Chain backend data, rather than simply blowing it away. This works even if o is null.
bed.backendData = o;
}
for (EquationSet p : s.parts) createBackendData(p);
}
use of gov.sandia.n2a.eqset.EquationSet in project n2a by frothga.
the class Part method init.
/**
* Note: specifically for Parts, call resolve() separately before calling init().
* This is to accommodate the connection process, which must probe values in a part
* (which may include references) before calling init().
*/
public void init(Simulator simulator) {
InstanceTemporaries temp = new InstanceInit(this, simulator);
InternalBackendData bed = temp.bed;
// update $n and assign $index
((Population) container.valuesObject[bed.populationIndex]).insert(this);
// Note: these do not require resolve(). Instead, they access their target directly through the endpoints array.
if (bed.count != null) {
int length = bed.count.length;
for (int i = 0; i < length; i++) {
if (bed.count[i] >= 0) {
Part p = (Part) valuesObject[bed.endpoints + i];
p.valuesFloat[bed.count[i]]++;
}
}
}
// Initialize variables
// Note that some valuesObject entries could be left null. This is OK, because Instance.get() will return
// a zero-equivalent value if it finds null.
// So our intial values can be applied correctly.
clearExternalWriteInit(bed.localBufferedExternalWrite);
for (Variable v : bed.localInit) {
Type result = v.eval(temp);
if (result == null || v.reference.variable.writeIndex < 0)
continue;
// with its finish() step. It would be as if the part had an extra cycle inserted.
if (v.reference.variable == v)
temp.applyResultInit(v, result);
else
((Instance) valuesObject[v.reference.index]).applyResultInit(v.reference.variable, result);
}
if (bed.liveStorage == InternalBackendData.LIVE_STORED)
set(bed.live, new Scalar(1));
if (bed.lastT != null)
temp.setFinal(bed.lastT, new Scalar(simulator.currentEvent.t));
if (bed.type != null)
temp.setFinal(bed.type, new Scalar(0));
if (bed.setDt)
simulator.move(this, ((Scalar) bed.dt.type).value);
// Prepare variables that have a combiner, in case they get written before the first finish().
// skips REPLACE it because it is unnecessary when called from update(). Handle REPLACE separately ...
clearExternalWriteBuffers(bed.localBufferedExternalWrite);
// This must come after the variables are initialized. Otherwise, there is no point.
for (Variable v : bed.localBufferedExternalWrite) if (v.assignment == Variable.REPLACE)
temp.set(v, temp.get(v));
// Request event monitors
for (EventTarget et : bed.eventTargets) {
for (EventSource es : et.sources) {
Part source;
if (es.reference == null)
source = this;
else
source = (Part) valuesObject[es.reference.index];
@SuppressWarnings("unchecked") ArrayList<Instance> monitors = (ArrayList<Instance>) source.valuesObject[es.monitorIndex];
monitors.add(this);
}
}
if (equations.parts.size() > 0) {
// If there are parts at all, then orderedParts must be filled in correctly. Otherwise it may be null.
for (EquationSet s : equations.orderedParts) ((Population) valuesObject[s.priority]).init(simulator);
}
}
use of gov.sandia.n2a.eqset.EquationSet in project n2a by frothga.
the class BackendDataC method analyzeLastT.
public void analyzeLastT(EquationSet s) {
boolean hasIntegrated = localIntegrated.size() > 0;
for (EquationSet p : s.parts) {
if (hasIntegrated)
break;
hasIntegrated = ((BackendDataC) p.backendData).globalIntegrated.size() > 0;
}
boolean dtCanChange = dt != null && !dt.hasAny("constant", "initOnly") && (dt.equations.size() > 0 || dt.hasAttribute("externalWrite"));
// dt could also change if we use a variable-step integrator. There are currently no plans to implement one.
lastT = hasIntegrated && (eventTargets.size() > 0 || dtCanChange);
}
Aggregations