Пример #1
0
    private static void diffusivity_1d_xk_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    diffusivity_1d_xk_test tests diffusivity_1d_xk.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Dongbin Xiu, George Karniadakis,
    //    Modeling uncertainty in steady state diffusion problems via
    //    generalized polynomial chaos,
    //    Computer Methods in Applied Mechanics and Engineering,
    //    Volume 191, 2002, pages 4927-4948.
    //
    {
        string        command_filename = "diffusivity_1d_xk_commands.txt";
        List <string> command_unit     = new();
        string        data_filename    = "diffusivity_1d_xk_data.txt";
        List <string> data_unit        = new();

        Console.WriteLine("");
        Console.WriteLine("diffusivity_1d_xk_test");
        Console.WriteLine("  Plot the stochastic diffusivity function");
        Console.WriteLine("  defined by diffusivity_1d_xk.");
        //
        //  Set up the spatial grid.
        //
        int    n     = 51;
        double x_min = -1.0;
        double x_max = +1.0;

        double[] x = typeMethods.r8vec_linspace_new(n, x_min, x_max);
        //
        //  Sample the OMEGA values.
        //
        int m    = 5;
        int seed = 123456789;

        typeMethods.r8vecNormalData data = new();
        double[] omega = typeMethods.r8vec_normal_01_new(m, ref data, ref seed);
        //
        //  Compute the diffusivity field.
        //
        double dc0 = 10.0;

        double[] dc = Stochastic.diffusivity_1d_xk(dc0, m, omega, n, x);
        //
        //  Create data file.
        //
        for (int j = 0; j < n; j++)
        {
            data_unit.Add("  " + x[j].ToString(CultureInfo.InvariantCulture).PadLeft(14)
                          + "  " + dc[j].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        File.WriteAllLines(data_filename, data_unit);
        Console.WriteLine("");
        Console.WriteLine("  Created graphics data file '" + data_filename + "'");
        //
        //  Create the command file.
        //
        double dc_max = typeMethods.r8vec_max(n, dc);

        command_unit.Add("# " + command_filename + "");
        command_unit.Add("#");
        command_unit.Add("# Usage:");
        command_unit.Add("#  gnuplot < " + command_filename + "");
        command_unit.Add("#");
        command_unit.Add("set term png");
        command_unit.Add("set output 'diffusivity_1d_xk.png'");
        command_unit.Add("set xlabel '<---X--->'");
        command_unit.Add("set ylabel '<---DC(X)--->'");
        command_unit.Add("set yrange [0.0:" + dc_max + "]");
        command_unit.Add("set title 'XK Stochastic diffusivity function'");
        command_unit.Add("set grid");
        command_unit.Add("set style data lines");
        command_unit.Add("plot '" + data_filename + "' using 1:2 lw 3 linecolor rgb 'red'");

        File.WriteAllLines(command_filename, command_unit);

        Console.WriteLine("  Created graphics command file '" + command_filename + "'");
    }