use of gov.sandia.n2a.backend.xyce.netlist.SymbolFunc 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);
}
}
}
Aggregations