private static void test08() //****************************************************************************80 // // Purpose: // // TEST08 times WATHEN_GE/WATHEN_GB. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 June 2014 // // Author: // // John Burkardt // { int md = 0; int ml = 0; int mu = 0; int test; Console.WriteLine(""); Console.WriteLine("TEST08"); Console.WriteLine(" For various problem sizes,"); Console.WriteLine(" time the assembly and factorization of a Wathen system"); Console.WriteLine(" WATHEN_GE/WATHEN_GB"); Console.WriteLine(""); Console.WriteLine(" NX Elements Nodes Storage " + " Assembly Factor Error"); int nx = 1; int ny = 1; for (test = 1; test <= 6; test++) { // // Compute the number of unknowns. // int n = WathenMatrix.wathen_order(nx, ny); int storage_ge = n * n; // // Set up a random solution X1. // int seed = 123456789; double[] x1 = UniformRNG.r8vec_uniform_01_new(n, ref seed); // // Compute the matrix. // seed = 123456789; DateTime t0 = DateTime.Now; double[] a = WathenMatrix.wathen_ge(nx, ny, n, ref seed); TimeSpan t1 = DateTime.Now - t0; // // Compute the corresponding right hand side B. // double[] b = MatbyVector.mv_ge(n, n, a, x1); // // Solve the system. // int[] ipvt = new int[n]; double[] x2 = new double[n]; int i; for (i = 0; i < n; i++) { x2[i] = b[i]; } int job = 0; t0 = DateTime.Now; Matrix.dgefa(ref a, n, n, ref ipvt); Matrix.dgesl(a, n, n, ipvt, ref x2, job); TimeSpan t2 = DateTime.Now - t0; // // Compute the maximum solution error. // double e = typeMethods.r8vec_diff_norm_li(n, x1, x2); // // Report. // Console.WriteLine(""); Console.WriteLine(" WATHEN_GE " + nx.ToString(CultureInfo.InvariantCulture).PadLeft(6) + " " + (nx * ny).ToString(CultureInfo.InvariantCulture).PadLeft(4) + " " + n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + " " + storage_ge.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + t1.TotalSeconds.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + t2.TotalSeconds.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + e.ToString(CultureInfo.InvariantCulture).PadLeft(10) + ""); // // Compute the bandwidth. // WathenMatrix.wathen_bandwidth(nx, ny, ref ml, ref md, ref mu); int storage_gb = (2 * ml + mu + 1) * n; // // Set up a random solution X1. // seed = 123456789; x1 = UniformRNG.r8vec_uniform_01_new(n, ref seed); // // Compute the matrix. // seed = 123456789; t0 = DateTime.Now; a = WathenMatrix.wathen_gb(nx, ny, n, ref seed); t1 = DateTime.Now - t0; // // Compute the corresponding right hand side B. // b = MatbyVector.mv_gb(n, n, ml, mu, a, x1); // // Solve the system. // int lda = 2 * ml + mu + 1; ipvt = new int[n]; x2 = new double[n]; for (i = 0; i < n; i++) { x2[i] = b[i]; } job = 0; t0 = DateTime.Now; Matrix.dgbfa(ref a, lda, n, ml, mu, ref ipvt); Matrix.dgbsl(a, lda, n, ml, mu, ipvt, ref x2, job); t2 = DateTime.Now - t0; // // Compute the maximum solution error. // e = typeMethods.r8vec_diff_norm_li(n, x1, x2); // // Report. // Console.WriteLine(" WATHEN_GB " + nx.ToString(CultureInfo.InvariantCulture).PadLeft(6) + " " + (nx * ny).ToString(CultureInfo.InvariantCulture).PadLeft(4) + " " + n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + " " + storage_gb.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + t1.TotalSeconds.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + t2.TotalSeconds.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + e.ToString(CultureInfo.InvariantCulture).PadLeft(10) + ""); // // Ready for next iteration. // nx *= 2; ny *= 2; } }
private static void test115() //****************************************************************************80 // // Purpose: // // TEST115 assembles, factors and solves using WATHEN_GB and CG_GB. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 June 2014 // // Author: // // John Burkardt // { int i; int md = 0; int ml = 0; int mu = 0; Console.WriteLine(""); Console.WriteLine("TEST115"); Console.WriteLine(" Assemble, factor and solve a Wathen system"); Console.WriteLine(" using WATHEN_GB and CG_GB."); Console.WriteLine(""); const int nx = 4; const int ny = 4; Console.WriteLine(" Elements in X direction NX = " + nx + ""); Console.WriteLine(" Elements in Y direction NY = " + ny + ""); Console.WriteLine(" Number of elements = " + nx * ny + ""); // // Compute the number of unknowns. // int n = WathenMatrix.wathen_order(nx, ny); Console.WriteLine(" Number of nodes N = " + n + ""); // // Compute the bandwidth. // WathenMatrix.wathen_bandwidth(nx, ny, ref ml, ref md, ref mu); Console.WriteLine(" Lower bandwidth ML = " + ml + ""); Console.WriteLine(" Upper bandwidth MU = " + mu + ""); // // Set up a random solution X1. // int seed = 123456789; double[] x1 = UniformRNG.r8vec_uniform_01_new(n, ref seed); // // Compute the matrix. // seed = 123456789; double[] a = WathenMatrix.wathen_gb(nx, ny, n, ref seed); // // Compute the corresponding right hand side B. // double[] b = MatbyVector.mv_gb(n, n, ml, mu, a, x1); // // Solve the linear system. // double[] x2 = new double[n]; for (i = 0; i < n; i++) { x2[i] = 1.0; } ConjugateGradient.cg_gb(n, ml, mu, a, b, ref x2); // // Compute the maximum solution error. // double e = typeMethods.r8vec_diff_norm_li(n, x1, x2); Console.WriteLine(" Maximum solution error is " + e + ""); }
private static void test05() //****************************************************************************80 // // Purpose: // // TEST05 measures the storage needed for the Wathen system. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 June 2014 // // Author: // // John Burkardt // { int bd1 = 0; int bd2 = 0; int bl1 = 0; int bl2 = 0; int bu1 = 0; int bu2 = 0; int bw2 = 0; Console.WriteLine(""); Console.WriteLine("TEST05"); Console.WriteLine(" For various problem sizes and storage schemes,"); Console.WriteLine(" measure the storage used for the Wathen system."); Console.WriteLine(""); Console.WriteLine(" Predicted Observed"); Console.WriteLine(" GE Band Band " + "Band Sparse"); Console.WriteLine(" NX Elements Nodes storage width width " + " storage storage"); Console.WriteLine(""); int nx = 1; int ny = 1; for (int test = 1; test <= 6; test++) { // // Compute the number of unknowns. // int n = WathenMatrix.wathen_order(nx, ny); // // Predict the bandwidth. // WathenMatrix.wathen_bandwidth(nx, ny, ref bl1, ref bd1, ref bu1); int bw1 = bl1 + bd1 + bu1; // // Compute the matrix. // int seed = 123456789; double[] a = WathenMatrix.wathen_ge(nx, ny, n, ref seed); int storage_ge = n * n; Matrix.bandwidth(n, n, a, ref bw2, ref bl2, ref bd2, ref bu2); int storage_gb = (2 * bl2 + 1 + bu2) * n; int storage_sparse = Matrix.nonzeros(n, n, a); // // Report. // Console.WriteLine(nx.ToString(CultureInfo.InvariantCulture).PadLeft(6) + " " + (nx * ny).ToString(CultureInfo.InvariantCulture).PadLeft(4) + " " + n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + " " + storage_ge.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + bw1.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + bw2.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + storage_gb.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + storage_sparse.ToString(CultureInfo.InvariantCulture).PadLeft(8) + ""); // // Ready for next iteration. // nx *= 2; ny *= 2; } }