Example #1
0
 public static ScopeFrame GetScopeFrame(this ICircuitElement elem, double time)
 {
     return(new ScopeFrame {
         time = time,
         current = elem.getCurrent(),
         voltage = elem.getVoltageDelta(),
     });
 }
Example #2
0
 public static string GetCurrentString(this ICircuitElement elem)
 {
     return(SIUnits.Current(elem.getCurrent()));
 }
            public bool findPath(int n1, int depth)
            {
                if (n1 == dest)
                {
                    return(true);
                }

                if (depth-- == 0)
                {
                    return(false);
                }

                if (used[n1])
                {
                    return(false);
                }

                used[n1] = true;
                for (int i = 0; i != sim.elements.Count; i++)
                {
                    ICircuitElement ce = sim.getElm(i);
                    if (ce == firstElm)
                    {
                        continue;
                    }

                    if (type == PathType.INDUCT)
                    {
                        if (ce is CurrentSource)
                        {
                            continue;
                        }
                    }

                    if (type == PathType.VOLTAGE)
                    {
                        if (!(ce.isWire() || ce is Voltage))
                        {
                            continue;
                        }
                    }

                    if (type == PathType.SHORT && !ce.isWire())
                    {
                        continue;
                    }

                    if (type == PathType.CAP_V)
                    {
                        if (!(ce.isWire() || ce is CapacitorElm || ce is Voltage))
                        {
                            continue;
                        }
                    }

                    if (n1 == 0)
                    {
                        // look for posts which have a ground connection;
                        // our path can go through ground
                        for (int z = 0; z != ce.getLeadCount(); z++)
                        {
                            if (ce.leadIsGround(z) && findPath(ce.getLeadNode(z), depth))
                            {
                                used[n1] = false;
                                return(true);
                            }
                        }
                    }

                    int j;
                    for (j = 0; j != ce.getLeadCount(); j++)
                    {
                        if (ce.getLeadNode(j) == n1)
                        {
                            break;
                        }
                    }

                    if (j == ce.getLeadCount())
                    {
                        continue;
                    }

                    if (ce.leadIsGround(j) && findPath(0, depth))
                    {
                        // System.out.println(ce + " has ground");
                        used[n1] = false;
                        return(true);
                    }

                    if (type == PathType.INDUCT && ce is InductorElm)
                    {
                        double c = ce.getCurrent();
                        if (j == 0)
                        {
                            c = -c;
                        }

                        // System.out.println("matching " + c + " to " + firstElm.getCurrent());
                        // System.out.println(ce + " " + firstElm);
                        if (Math.Abs(c - firstElm.getCurrent()) > 1e-10)
                        {
                            continue;
                        }
                    }

                    for (int k = 0; k != ce.getLeadCount(); k++)
                    {
                        if (j == k)
                        {
                            continue;
                        }

                        // System.out.println(ce + " " + ce.getNode(j) + "-" + ce.getNode(k));
                        if (ce.leadsAreConnected(j, k) && findPath(ce.getLeadNode(k), depth))
                        {
                            // System.out.println("got findpath " + n1);
                            used[n1] = false;
                            return(true);
                        }
                        // System.out.println("back on findpath " + n1);
                    }
                }

                used[n1] = false;
                // System.out.println(n1 + " failed");
                return(false);
            }