Пример #1
0
    private static void diffusivity_1d_pwc_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    diffusivity_1d_pwc_test tests diffusivity_1d_pwc.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    24 March 2019
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        string        command_filename = "diffusivity_1d_pwc_commands.txt";
        List <string> command_unit     = new();
        string        data_filename    = "diffusivity_1d_pwc_data.txt";
        List <string> data_unit        = new();

        double[] vc =
        {
            1.0, 1.5, 3.0, 1.2, 1.0, 0.8, 0.2, 0.4, 0.8, 1.0
        }

        ;
        double[] xc =
        {
            -0.9, -0.5, -0.45, -0.1, 0.2, 0.3, 0.32, 0.7, 0.85
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("diffusivity_1d_pwc_test");
        Console.WriteLine("  Test diffusivity_1d_pwc.");
        //
        //  Set up the spatial grid.
        //
        int nc = 10;
        //
        //  Sample the diffusivity.
        //
        int    np    = 100;
        double x_min = -1.0;
        double x_max = +1.0;

        double[] xp = typeMethods.r8vec_linspace_new(np, x_min, x_max);
        //
        //  Compute the diffusivity field.
        //
        double[] vp = Stochastic.diffusivity_1d_pwc(nc, xc, vc, np, xp);
        //
        //  Create data file.
        //
        for (int j = 0; j < np; j++)
        {
            data_unit.Add("  " + xp[j].ToString(CultureInfo.InvariantCulture).PadLeft(14)
                          + "  " + vp[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 vp_max = typeMethods.r8vec_max(np, vp);

        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_pwc.png'");
        command_unit.Add("set xlabel '<---X--->'");
        command_unit.Add("set ylabel '<---Rho(X)--->'");
        command_unit.Add("set yrange [0.0:" + vp_max + "]");
        command_unit.Add("set title 'PWC 1D 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 + "'");
    }