use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class XyceBackend method getOutputVariables.
@Override
public ParameterDomain getOutputVariables(MNode model) {
try {
MNode n = (MNode) model;
if (n == null)
return null;
EquationSet s = new EquationSet(n);
if (s.name.length() < 1)
s.name = "Model";
s.resolveLHS();
return s.getOutputParameters();
} catch (Exception error) {
return null;
}
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class MPart method clearRedundantOverrides.
/**
* Clears all top-level document nodes which exactly match the value they override.
* This is a utility function to support import and copy/paste. In general, internal
* models are kept in a clean state by set().
* @return true if the entire tree from this node down is free of top-level nodes.
*/
public synchronized boolean clearRedundantOverrides() {
boolean overrideNecessary = false;
for (MNode c : this) {
if (!((MPart) c).clearRedundantOverrides())
overrideNecessary = true;
}
if (overrideNecessary)
return false;
if (source != original && source.get().equals(original.get())) {
source.getParent().clear(source.key());
source = original;
}
return !isFromTopDocument();
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class MPart method move.
public synchronized void move(String fromIndex, String toIndex) {
if (toIndex.equals(fromIndex))
return;
// By definition, no top-level document nodes are allowed to remain at the destination. However, underrides may exist.
clear(toIndex);
MPart fromPart = (MPart) child(fromIndex);
if (fromPart == null)
return;
// We only move top-document nodes.
if (!fromPart.isFromTopDocument())
return;
MNode fromDoc = source.child(fromIndex);
MNode toPart = child(toIndex);
if (// No node at the destination, so merge at level of top-document.
toPart == null) {
MPersistent toDoc = (MPersistent) source.set(toIndex, "");
toDoc.merge(fromDoc);
MPart c = new MPart(this, null, toDoc);
children.put(toIndex, c);
// The sub-tree is empty, so all injected nodes are new. They don't really underride anything.
c.underrideChildren(null, toDoc);
c.expand();
} else // Some existing underrides, so merge in collated tree. This is more expensive because it involves multiple calls to set().
{
toPart.merge(fromDoc);
}
clear(fromIndex);
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class MPart method dump.
/**
* For debugging the assembled tree.
*/
public synchronized void dump(String space) {
String index = key();
String value = get();
if (value.isEmpty()) {
System.out.print(String.format("%s%s", space, index));
} else {
String newLine = String.format("%n");
value = value.split(newLine, 2)[0].trim();
System.out.print(String.format("%s%s=%s", space, index, value));
}
System.out.println("\t" + dumpHash(container) + "\t" + dumpHash(this) + "\t" + isFromTopDocument() + "\t" + dumpHash(source) + "\t" + dumpHash(original) + "\t" + dumpHash(inheritedFrom));
String space2 = space + " ";
for (MNode c : this) ((MPart) c).dump(space2);
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class MPart method underrideChildren.
/**
* Injects inherited equations as children of this node.
* Handles recursion down our containment hierarchy.
* See note on underride(MPart,MPersistent). This is safe to run more than once for a given $inherit statement.
* @param newSource The current node in the source document which matches this node in the MPart tree.
*/
public synchronized void underrideChildren(MPart from, MPersistent newSource) {
if (newSource.size() == 0)
return;
if (children == null)
children = new TreeMap<String, MNode>(comparator);
for (MNode n : newSource) {
String key = n.key();
MPersistent p = (MPersistent) n;
MPart c = (MPart) children.get(key);
if (c == null) {
c = new MPart(this, from, p);
children.put(key, c);
c.underrideChildren(from, p);
} else {
c.underride(from, p);
}
}
}
Aggregations