Search in sources :

Example 1 with UnresolvedVariable

use of gov.sandia.n2a.eqset.EquationSet.UnresolvedVariable in project n2a by frothga.

the class ExportJob method makeExecutable.

/**
 *        Make eqset minimally executable.
 */
public static void makeExecutable(EquationSet equations, boolean findConstants) {
    // This name should be unique enough that we don't have to check.
    EquationSet fakePart = new EquationSet(equations, "N2A_fakePart");
    // Always added, even if we don't need it.
    equations.parts.add(fakePart);
    fakeConnectionTarget(equations);
    try {
        equations.resolveConnectionBindings();
    }// Still try to finish rest of compilation. Maybe only one or two minor parts were affected.
     catch (Exception e) {
    }
    try {
        equations.addGlobalConstants();
        // $connect, $index, $init, $n, $t, $t', $type
        equations.addSpecials();
        equations.resolveLHS();
        equations.fillIntegratedVariables();
        equations.findIntegrated();
        LinkedList<UnresolvedVariable> unresolved = new LinkedList<UnresolvedVariable>();
        equations.resolveRHS(unresolved);
        if (// Make one attempt to fake the variables
        unresolved.size() > 0) {
            for (UnresolvedVariable uv : unresolved) {
                if (!uv.name.startsWith("A.") && !uv.name.startsWith("B."))
                    continue;
                String name = uv.name.substring(2);
                Variable v = Variable.from(name + "=0");
                if (fakePart.add(v)) {
                    v.reference = new VariableReference();
                    v.reference.variable = v;
                }
            }
            // Creates excess dependency counts on connection bindings, but is otherwise OK to run again.
            equations.resolveRHS();
        }
        equations.findExternal();
        equations.sortParts();
        equations.determineUnits();
        // This can hurt the analysis. It simplifies expressions and substitutes constants, breaking some dependency chains.
        if (findConstants)
            equations.findConstants();
        equations.determineTraceVariableName();
        equations.determineTypes();
        equations.clearVariables();
    }// It may still be possible to complete the export.
     catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) Variable(gov.sandia.n2a.eqset.Variable) UnresolvedVariable(gov.sandia.n2a.eqset.EquationSet.UnresolvedVariable) AccessVariable(gov.sandia.n2a.language.AccessVariable) VariableReference(gov.sandia.n2a.eqset.VariableReference) UnresolvedVariable(gov.sandia.n2a.eqset.EquationSet.UnresolvedVariable) UnconvertibleException(javax.measure.UnconvertibleException) IncommensurableException(javax.measure.IncommensurableException) LinkedList(java.util.LinkedList)

Aggregations

EquationSet (gov.sandia.n2a.eqset.EquationSet)1 UnresolvedVariable (gov.sandia.n2a.eqset.EquationSet.UnresolvedVariable)1 Variable (gov.sandia.n2a.eqset.Variable)1 VariableReference (gov.sandia.n2a.eqset.VariableReference)1 AccessVariable (gov.sandia.n2a.language.AccessVariable)1 LinkedList (java.util.LinkedList)1 IncommensurableException (javax.measure.IncommensurableException)1 UnconvertibleException (javax.measure.UnconvertibleException)1