Exemplo n.º 1
0
            static public double[,] GetMatrixB(int row, int col, LinkedListNetList argList)
            {
                Console.WriteLine("MatrixB argList:");
                argList.PrintLinkedListNetList();
                double[,] returnMatrix = new double[row, col]; // default elements set to zero
                NetListNode testNode = argList.head;

                while (testNode != null)
                {
                    if (testNode.data.getComponentType() == 'V')
                    {   // minus one since Matrix index starts from zero
                        Console.WriteLine("Voltage found in MatB arglist");
                        testNode.data.PrintNetList();
                        if (testNode.data.Node1 != 0)
                        {
                            returnMatrix[testNode.data.Node1 - 1, testNode.data.Index - 1] = 1;
                        }
                        else
                        {
                            returnMatrix[testNode.data.Node1 - 1, testNode.data.Index - 1] = 0;
                        }
                        if (testNode.data.Node2 != 0)
                        {
                            returnMatrix[testNode.data.Node2 - 1, testNode.data.Index - 1] = -1;
                        }
                        else
                        {
                            returnMatrix[testNode.data.Node1 - 1, testNode.data.Index - 1] = 0;
                        }
                    }
                    testNode = testNode.next;
                }
                return(returnMatrix);
            }
Exemplo n.º 2
0
            static public double[,] GetMatrixE(int row, int col, LinkedListNetList argList)
            {
                double[,] returnMatrix = new double[row, col]; // default elements set to zero
                NetListNode testNode = argList.head;

                while (testNode != null)
                {
                    // minus one since Matrix index starts from zero
                    returnMatrix[testNode.data.Index - 1, 1] = testNode.data.Value;
                    testNode = testNode.next;
                }
                return(returnMatrix);
            }
Exemplo n.º 3
0
            static public double[,] GetMatrixG(int row, int col, LinkedListNetList argList)
            {
                Console.WriteLine("MatrixG argList:");
                argList.PrintLinkedListNetList();
                double[,] returnMatrix = new double[row, col]; // default elements set to zero
                NetListNode testNode = argList.head;

                while (testNode != null)
                {
                    if (testNode.data.getComponentType() == 'R')
                    {   // minus one since Matrix index starts from zero
                        Console.WriteLine("Resistor found in MatG arglist");
                        if (testNode.data.Node1 > 0)
                        {
                            // Console.WriteLine("Value of conductance: {0}", 1 / testNode.data.Value);
                            // Console.WriteLine("Value of resistance: {0}", testNode.data.Value);
                            returnMatrix[testNode.data.Node1 - 1, testNode.data.Node1 - 1] = returnMatrix[testNode.data.Node1 - 1, testNode.data.Node1 - 1] + (1 / testNode.data.Value);
                        }
                        if (testNode.data.Node2 > 0)
                        {
                            // Console.WriteLine("Value of conductance: {0}", 1 / testNode.data.Value);
                            // Console.WriteLine("Value of resistance: {0}", testNode.data.Value);
                            returnMatrix[testNode.data.Node2 - 1, testNode.data.Node2 - 1] = returnMatrix[testNode.data.Node2 - 1, testNode.data.Node2 - 1] + (1 / testNode.data.Value);
                        }
                        if (testNode.data.Node1 > 0 && testNode.data.Node2 > 0)
                        {
                            // Console.WriteLine("Nodes not zero");
                            // Console.WriteLine("Value of conductance: {0}", 1 / testNode.data.Value);
                            // Console.WriteLine("Value of resistance: {0}", testNode.data.Value);
                            returnMatrix[testNode.data.Node1 - 1, testNode.data.Node2 - 1] -= (1 / testNode.data.Value);
                            returnMatrix[testNode.data.Node2 - 1, testNode.data.Node1 - 1] -= (1 / testNode.data.Value);
                        }
                    }
                    testNode = testNode.next;
                }
                return(returnMatrix);
            }
Exemplo n.º 4
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");
            }