Search in sources :

Example 61 with Variable

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

Example 62 with Variable

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

Example 63 with Variable

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

Aggregations

Variable (gov.sandia.n2a.eqset.Variable)63 AccessVariable (gov.sandia.n2a.language.AccessVariable)38 EquationSet (gov.sandia.n2a.eqset.EquationSet)25 EquationEntry (gov.sandia.n2a.eqset.EquationEntry)20 Scalar (gov.sandia.n2a.language.type.Scalar)18 Operator (gov.sandia.n2a.language.Operator)17 ArrayList (java.util.ArrayList)17 Type (gov.sandia.n2a.language.Type)12 Visitor (gov.sandia.n2a.language.Visitor)12 ConnectionBinding (gov.sandia.n2a.eqset.EquationSet.ConnectionBinding)11 MNode (gov.sandia.n2a.db.MNode)9 VariableReference (gov.sandia.n2a.eqset.VariableReference)9 Constant (gov.sandia.n2a.language.Constant)9 MPart (gov.sandia.n2a.eqset.MPart)7 EventTarget (gov.sandia.n2a.backend.internal.InternalBackendData.EventTarget)6 Output (gov.sandia.n2a.language.function.Output)6 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)6 List (java.util.List)6 IncommensurableException (javax.measure.IncommensurableException)6 UnconvertibleException (javax.measure.UnconvertibleException)6