Search in sources :

Example 1 with MNode

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;
    }
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) MNode(gov.sandia.n2a.db.MNode) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with MNode

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();
}
Also used : MNode(gov.sandia.n2a.db.MNode)

Example 3 with MNode

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);
}
Also used : MPersistent(gov.sandia.n2a.db.MPersistent) MNode(gov.sandia.n2a.db.MNode)

Example 4 with MNode

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);
}
Also used : MNode(gov.sandia.n2a.db.MNode)

Example 5 with MNode

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);
        }
    }
}
Also used : MPersistent(gov.sandia.n2a.db.MPersistent) TreeMap(java.util.TreeMap) MNode(gov.sandia.n2a.db.MNode)

Aggregations

MNode (gov.sandia.n2a.db.MNode)63 Node (org.w3c.dom.Node)11 NameMap (gov.sandia.n2a.backend.neuroml.PartMap.NameMap)9 MVolatile (gov.sandia.n2a.db.MVolatile)5 MPart (gov.sandia.n2a.eqset.MPart)5 ArrayList (java.util.ArrayList)5 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)4 MPersistent (gov.sandia.n2a.db.MPersistent)3 EquationSet (gov.sandia.n2a.eqset.EquationSet)3 Variable (gov.sandia.n2a.eqset.Variable)3 AccessVariable (gov.sandia.n2a.language.AccessVariable)3 PanelReference (gov.sandia.n2a.ui.ref.PanelReference)3 Element (org.w3c.dom.Element)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 MDoc (gov.sandia.n2a.db.MDoc)2 ParseException (gov.sandia.n2a.language.ParseException)2 AddDoc (gov.sandia.n2a.ui.eq.undo.AddDoc)2 IOException (java.io.IOException)2 TreeMap (java.util.TreeMap)2 IncommensurableException (javax.measure.IncommensurableException)2