Search in sources :

Example 1 with SymbolStateVar1

use of gov.sandia.n2a.backend.xyce.netlist.SymbolStateVar1 in project n2a by frothga.

the class XyceBackendData method analyze.

public void analyze(EquationSet s) {
    if (Device.isXyceDevice(s)) {
        deviceSymbol = new Device(s);
    }
    class ContainsOperator implements Visitor {

        @SuppressWarnings("rawtypes")
        public Class targetClass;

        boolean found;

        public boolean visit(Operator op) {
            if (found)
                return false;
            if (op.getClass().equals(targetClass)) {
                found = true;
                return false;
            }
            return true;
        }

        public boolean check(EquationEntry e) {
            found = false;
            e.expression.visit(this);
            return found;
        }
    }
    ContainsOperator containsPulse = new ContainsOperator();
    containsPulse.targetClass = Pulse.class;
    ContainsOperator containsSinewave = new ContainsOperator();
    containsSinewave.targetClass = Sinewave.class;
    ContainsVariable containsT = new ContainsVariable(new Variable("$t"));
    for (Variable v : s.variables) {
        // in a static (no structural dynamics) simulation, no $variable needs to be computed at runtime
        if (v.name.startsWith("$"))
            continue;
        // Constants are already subbed in. "initOnly" values are defined during init cycle, and can now be subbed during code generation.
        if (v.hasAttribute("constant") || v.hasAttribute("initOnly"))
            continue;
        for (EquationEntry eq : v.equations) {
            // don't need to write out equations defining dynamics already defined by a device
            if (Device.isXyceDevice(s) && Device.ignoreEquation(eq))
                continue;
            Symbol handler = null;
            if (eq.variable.order > 1) {
                Backend.err.get().println("Support for higher order differential equations not implemented yet (" + eq + ")");
                throw new Backend.AbortRun();
            } else if (eq.variable.order == 1) {
                handler = new SymbolStateVar1(eq);
            } else // The following are all order 0
            if (containsPulse.check(eq)) {
                handler = new SymbolPulse(eq);
            } else if (containsSinewave.check(eq)) {
                handler = new SymbolSinewave(eq);
            } else // TODO: this doesn't seem like an adequate test. Why would having a $t be the only reason to generate a zero-order symbol?
            if (containsT.check(eq.expression)) {
                handler = new SymbolStateVar0(eq);
            } else if (isExplicitInit(eq)) {
                handler = new SymbolConstantIC(eq);
            } else {
                // The RHS expression depends on state variables, so we create a netlist .func for it.
                handler = new SymbolFunc(eq);
            }
            equationSymbols.put(eq, handler);
            // May set the handler for v several times, but only the last one is kept. Multiple handlers should agree on symbol for reference. Better yet is to handle multiple equations together.
            variableSymbols.put(v.name, handler);
        }
    }
}
Also used : Operator(gov.sandia.n2a.language.Operator) AccessVariable(gov.sandia.n2a.language.AccessVariable) Variable(gov.sandia.n2a.eqset.Variable) Visitor(gov.sandia.n2a.language.Visitor) SymbolStateVar0(gov.sandia.n2a.backend.xyce.netlist.SymbolStateVar0) SymbolStateVar1(gov.sandia.n2a.backend.xyce.netlist.SymbolStateVar1) Device(gov.sandia.n2a.backend.xyce.netlist.Device) Symbol(gov.sandia.n2a.backend.xyce.netlist.Symbol) SymbolPulse(gov.sandia.n2a.backend.xyce.netlist.SymbolPulse) SymbolFunc(gov.sandia.n2a.backend.xyce.netlist.SymbolFunc) SymbolSinewave(gov.sandia.n2a.backend.xyce.netlist.SymbolSinewave) EquationEntry(gov.sandia.n2a.eqset.EquationEntry) SymbolConstantIC(gov.sandia.n2a.backend.xyce.netlist.SymbolConstantIC)

Aggregations

Device (gov.sandia.n2a.backend.xyce.netlist.Device)1 Symbol (gov.sandia.n2a.backend.xyce.netlist.Symbol)1 SymbolConstantIC (gov.sandia.n2a.backend.xyce.netlist.SymbolConstantIC)1 SymbolFunc (gov.sandia.n2a.backend.xyce.netlist.SymbolFunc)1 SymbolPulse (gov.sandia.n2a.backend.xyce.netlist.SymbolPulse)1 SymbolSinewave (gov.sandia.n2a.backend.xyce.netlist.SymbolSinewave)1 SymbolStateVar0 (gov.sandia.n2a.backend.xyce.netlist.SymbolStateVar0)1 SymbolStateVar1 (gov.sandia.n2a.backend.xyce.netlist.SymbolStateVar1)1 EquationEntry (gov.sandia.n2a.eqset.EquationEntry)1 Variable (gov.sandia.n2a.eqset.Variable)1 AccessVariable (gov.sandia.n2a.language.AccessVariable)1 Operator (gov.sandia.n2a.language.Operator)1 Visitor (gov.sandia.n2a.language.Visitor)1