示例#1
0
            public void AddNode(ref NetList argData, int mode)
            {
                Console.WriteLine("Adding node {0}", argData.Label);
                Console.WriteLine("Type : {0}", argData.getComponentType());
                NetListNode toAdd = new NetListNode();

                toAdd.data.GetNetlist(argData);
                if (mode == NEW_ENTRY)
                {
                    NetListCount++;
                }
                switch (argData.getComponentType())
                {
                case 'R':
                    if (mode == NEW_ENTRY)
                    {
                        ++ResistorCount;
                    }
                    Console.WriteLine("Index of {0} before GetIndex(): {1}", toAdd.data.Label, toAdd.data.Index);
                    toAdd.data.GetIndex(ResistorCount);
                    Console.WriteLine("Index of {0} after GetIndex(): {1}", toAdd.data.Label, toAdd.data.Index);
                    break;

                case 'V':
                    if (mode == NEW_ENTRY)
                    {
                        ++VoltageSourceCount;
                    }
                    Console.WriteLine("Index of {0} before GetIndex(): {1}", toAdd.data.Label, toAdd.data.Index);
                    toAdd.data.GetIndex(VoltageSourceCount);
                    Console.WriteLine("Index of {0} after GetIndex(): {1}", toAdd.data.Label, toAdd.data.Index);
                    break;

                case 'C':
                    if (mode == NEW_ENTRY)
                    {
                        ++CurrentSourceCount;
                    }
                    Console.WriteLine("Index of {0} before GetIndex(): {1}", toAdd.data.Label, toAdd.data.Index);
                    toAdd.data.GetIndex(CurrentSourceCount);
                    Console.WriteLine("Index of {0} after GetIndex(): {1}", toAdd.data.Label, toAdd.data.Index);
                    break;
                }
                if (head == null)
                {
                    head = toAdd;
                    tail = toAdd;
                }
                else
                {
                    tail.next = toAdd;
                    tail      = toAdd;
                }
            }
示例#2
0
            public static void Main(string[] args)
            {
                LinkedListNetList NetListObj        = new LinkedListNetList();
                LinkedListNetList ResistorList      = new LinkedListNetList();
                LinkedListNetList VoltageSourceList = new LinkedListNetList();
                LinkedListNetList CurrentSourceList = new LinkedListNetList();

                // Console.Write("Number of elements: ");
                // string NetListNumString = Console.ReadLine();
                // int NetListNum = Convert.ToInt32(NetListNumString);
                int NetListNum = 5;

                string[] NetListStringArray = new string[] { "V1 1 0 15", "R1 1 2 2700", "R2 2 0 5000", "R35 2 3 1000000", "RZ 3 0 10000" };
                for (int i = 0; i < NetListNum; i++)
                {
                    // NetListStringArray[i] = Console.ReadLine();
                    // for (int i = 0; i < args.Length; i++) // extracting NetList from input and storing in linked list
                    string[] parts      = NetListStringArray[i].Split(' ');
                    string   Type       = parts[0];
                    string   Node1str   = parts[1];
                    string   Node2str   = parts[2];
                    string   Valuestr   = parts[3];
                    int      Node1      = Convert.ToInt32(Node1str);
                    int      Node2      = Convert.ToInt32(Node2str);
                    int      Value      = Convert.ToInt32(Valuestr);
                    NetList  newElement = new NetList();
                    newElement.GetNetlist(Type, Node1, Node2, Value);
                    NetListObj.AddNode(ref newElement, NEW_ENTRY);
                    switch (newElement.getComponentType())
                    {
                    case 'R':
                        Console.WriteLine("newElement read resistor");
                        ResistorList.AddNode(ref newElement, OLD_ENTRY);
                        break;

                    case 'V':
                        Console.WriteLine("newElement read voltage");
                        VoltageSourceList.AddNode(ref newElement, OLD_ENTRY);
                        break;

                    case 'C':
                        Console.WriteLine("newElement read current");
                        CurrentSourceList.AddNode(ref newElement, OLD_ENTRY);
                        break;

                    default:
                        //
                        break;
                    }
                }
                Console.WriteLine("Read all netlist...");
                NetListObj.PrintLinkedListNetList();
                VoltageSourceList.PrintLinkedListNetList();
                ResistorList.PrintLinkedListNetList();
                // asdasd
                int nodeNum    = NetListObj.NodeCount();           // counts non-redundant nodes
                int voltageNum = VoltageSourceList.VoltageCount(); // counts individual voltage nodes from list

                Console.WriteLine("{0} {1}", nodeNum, voltageNum);
                double[,] matrixA     = new double[nodeNum + voltageNum, nodeNum + voltageNum];
                double[,] matrixG     = new double[nodeNum, nodeNum];
                double[,] matrixB     = new double[nodeNum, voltageNum];
                double[,] matrixC     = new double[voltageNum, nodeNum];
                double[,] matrixD     = new double[voltageNum, voltageNum];  // matrixD is zero, no dependent sources assumed
                double[,] matrixX     = new double[nodeNum + voltageNum, 1]; // unknown
                double[,] matrixZ     = new double[nodeNum + voltageNum, 1];
                double[,] matrixI     = new double[nodeNum, 1];
                double[,] matrixE     = new double[voltageNum, 1];
                double[,] matrixAsub1 = new double[nodeNum, nodeNum + voltageNum];
                double[,] matrixAsub2 = new double[voltageNum, nodeNum + voltageNum];
                double[,] matrixAinv  = new double[nodeNum + voltageNum, nodeNum + voltageNum];
                Console.WriteLine("Init matrix done");
                matrixG = GetMatrixG(nodeNum, nodeNum, NetListObj);
                Console.WriteLine("MatrixG done");
                PrintMatrix(matrixG);
                matrixB = GetMatrixB(nodeNum, voltageNum, NetListObj);
                Console.WriteLine("MatrixB done");
                PrintMatrix(matrixB);
                matrixC = TransposeMatrix(nodeNum, voltageNum, matrixB);
                Console.WriteLine("MatrixC done");
                matrixI = GetMatrixI(nodeNum, 1, CurrentSourceList);
                Console.WriteLine("MatrixI done");
                matrixAsub1 = ConcatenateMatrix(matrixG, matrixB, HORIZONTAL);
                Console.WriteLine("MatrixAsub1 done");
                matrixAsub2 = ConcatenateMatrix(matrixC, matrixD, HORIZONTAL);
                Console.WriteLine("MatrixAsub2 done");
                matrixA = ConcatenateMatrix(matrixAsub1, matrixAsub2, VERTICAL); // matrixA done
                Console.WriteLine("MatrixA done");
                PrintMatrix(matrixA);
                matrixZ    = ConcatenateMatrix(matrixI, matrixE, VERTICAL); // matrixZ done
                matrixAinv = InverseMatrix(matrixA);
                matrixX    = ProductMatrix(matrixAinv, matrixZ);
                Console.WriteLine("MatrixX");
            }