Search in sources :

Example 61 with EquationSet

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);
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet)

Example 62 with EquationSet

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);
    }
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) Variable(gov.sandia.n2a.eqset.Variable) Instance(gov.sandia.n2a.language.type.Instance) ArrayList(java.util.ArrayList) Scalar(gov.sandia.n2a.language.type.Scalar) Type(gov.sandia.n2a.language.Type) EventSource(gov.sandia.n2a.backend.internal.InternalBackendData.EventSource) EventTarget(gov.sandia.n2a.backend.internal.InternalBackendData.EventTarget)

Example 63 with EquationSet

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);
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet)

Aggregations

EquationSet (gov.sandia.n2a.eqset.EquationSet)63 Variable (gov.sandia.n2a.eqset.Variable)25 AccessVariable (gov.sandia.n2a.language.AccessVariable)24 ConnectionBinding (gov.sandia.n2a.eqset.EquationSet.ConnectionBinding)16 ArrayList (java.util.ArrayList)16 EquationEntry (gov.sandia.n2a.eqset.EquationEntry)12 Operator (gov.sandia.n2a.language.Operator)12 MNode (gov.sandia.n2a.db.MNode)11 MPart (gov.sandia.n2a.eqset.MPart)10 Constant (gov.sandia.n2a.language.Constant)10 Scalar (gov.sandia.n2a.language.type.Scalar)10 IncommensurableException (javax.measure.IncommensurableException)9 UnconvertibleException (javax.measure.UnconvertibleException)9 AbortRun (gov.sandia.n2a.plugins.extpoints.Backend.AbortRun)8 VariableReference (gov.sandia.n2a.eqset.VariableReference)7 Type (gov.sandia.n2a.language.Type)7 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)7 EventTarget (gov.sandia.n2a.backend.internal.InternalBackendData.EventTarget)6 Visitor (gov.sandia.n2a.language.Visitor)6 EventSource (gov.sandia.n2a.backend.internal.InternalBackendData.EventSource)5