예제 #1
0
 public static void PrintMatrixInfo(CSRMatrix csr)
 {
     Console.WriteLine("------------------- Matrix Info -------------------");
     Console.WriteLine("Rows: " + csr.N.ToString());
     Console.WriteLine("Cols: " + csr.N.ToString());
     Console.WriteLine("NNZ: " + csr.NNZ.ToString());
 }
예제 #2
0
        public static void WriteKG(CSRMatrix csr, string path, bool symmetry)
        {
            //path += "/KG.mtx";
            StreamWriter sw = new StreamWriter(path);

            sw.WriteLine("%%MatrixMarket matrix coordinate real symmetric");
            var mat = csr.ToCOO(symmetry);

            sw.WriteLine(mat.Rows.ToString() + ' ' + mat.Cols.ToString() + ' ' + mat.NNZ.ToString());
            for (int i = 0; i < mat.NNZ; i++)
            {
                sw.WriteLine((mat.RowArray[i] + 1).ToString() + ' ' + (mat.ColArray[i] + 1).ToString() + ' ' + mat.ValueArray[i].ToString());
            }
            sw.Flush();
            sw.Close();
            sw.Dispose();
        }
예제 #3
0
        public static void TestCSR()
        {
            CSRMatrix csr = new CSRMatrix(6, 16);

            csr.Vals = new double[16] {
                10, 20, 20, 30, 35, 40, 35, 50, 60, 40, 70, 80, 90, 60, 90, 100
            };
            csr.Cols = new int[16] {
                0, 1, 0, 1, 2, 3, 1, 2, 5, 1, 3, 4, 5, 2, 4, 5
            };
            csr.Rows = new int[7] {
                0, 2, 6, 9, 11, 13, 16
            };

            csr.DeleteRowAndCol(2);
            FEIO.WriteKG(csr, "E:\\testCSR2.mtx", true);
        }
예제 #4
0
        /// <summary>
        /// Initialize the global stiffness matrix
        /// </summary>
        private void InitialzeKG()
        {
            // list non-anchored nodes and give them sequential ids
            ActiveNodes = Model.Nodes.FindAll(nd => nd.Active);
            int id = 0;

            foreach (Node nd in ActiveNodes)
            {
                nd.ActiveID = id++;
            }

            GetConnectedElements();
            GetAdjacentNodes();

            // count total number of neighbours in all nodes
            int count = 0;

            foreach (Node nd in ActiveNodes)
            {
                count += nd.Neighbours.Count;
            }

            // allocate CSR
            // each neighbor contributes 2 rows and 2 columns to CSR matrix, so NNZ = count * 4
            // the size of the matrix is (number of active nodes)*(2 coordinates)
            KG = new CSRMatrix(ActiveNodes.Count * DOF, count * DOF * DOF);

            // 3) create CSR indices
            count = 0;
            foreach (Node nd in ActiveNodes)
            {
                int row_nnz = nd.ComputePositionInKG(count, KG.Cols);
                KG.Rows[nd.ActiveID * DOF + 0] = count;
                KG.Rows[nd.ActiveID * DOF + 1] = count + row_nnz;
                if (DOF == 3)
                {
                    KG.Rows[nd.ActiveID * DOF + 2] = count + row_nnz * 2;
                }
                count += row_nnz * DOF;
            }
        }