Пример #1
0
    private static void diffusivity_2d_bnt_contour()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    diffusivity_2d_bnt_contour displays contour plots of a 2D stochastic diffusivity function.
    //
    //  Discussion:
    //
    //    The diffusivity function is computed by diffusivity_2d_bnt.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Ivo Babuska, Fabio Nobile, Raul Tempone,
    //    A stochastic collocation method for elliptic partial differential equations
    //    with random input data,
    //    SIAM Journal on Numerical Analysis,
    //    Volume 45, Number 3, 2007, pages 1005-1034.
    //
    {
        string        command_filename = "diffusivity_2d_bnt_commands.txt";
        List <string> command_unit     = new();
        string        data_filename    = "diffusivity_2d_bnt_data.txt";
        List <string> data_unit        = new();
        int           m  = 4;
        int           nx = 41;
        int           ny = 31;

        Console.WriteLine("");
        Console.WriteLine("diffusivity_2d_bnt_contour");
        Console.WriteLine("  Display contour or surface plots of the stochastic");
        Console.WriteLine("  diffusivity function defined by diffusivity_2d_bnt.");
        Console.WriteLine("");
        Console.WriteLine("  The first plot uses uniform random values for OMEGA.");
        Console.WriteLine("  The second uses Gaussian (normal) random values.");
        //
        //  Set the spatial grid.
        //
        double[] xvec = typeMethods.r8vec_linspace_new(nx, -1.5, 0.0);
        double[] yvec = typeMethods.r8vec_linspace_new(ny, -0.4, 0.8);

        double[] xmat = new double[nx * ny];
        double[] ymat = new double[nx * ny];
        typeMethods.r8vec_mesh_2d(nx, ny, xvec, yvec, ref xmat, ref ymat);
        //
        //  Sample OMEGA.
        //
        int seed = 123456789;

        double[] omega = UniformRNG.r8vec_uniform_01_new(m, ref seed);
        //
        //  Compute the diffusivity field.
        //
        double dc0 = 10.0;
        int    n   = nx * ny;

        double[] dc = Stochastic.diffusivity_2d_bnt(dc0, omega, n, xmat, ymat);
        //
        //  Create a data file.
        //
        for (int j = 0; j < ny; j++)
        {
            for (int i = 0; i < nx; i++)
            {
                data_unit.Add("  " + xmat[i + j * nx].ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + ymat[i + j * nx].ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + dc[i + j * nx].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.
        //

        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_2d_bnt.png'");
        command_unit.Add("set xlabel '<---X--->'");
        command_unit.Add("set ylabel '<---Y--->'");
        command_unit.Add("set zlabel '<---DC(X,Y)--->'");
        command_unit.Add("set title 'BNT Stochastic diffusivity function'");
        command_unit.Add("set contour");
        command_unit.Add("set timestamp");
        command_unit.Add("set cntrparam levels 10");
        command_unit.Add("#set view map");
        command_unit.Add("set view 75, 75");
        command_unit.Add("unset key");
        command_unit.Add("splot '" + data_filename + "'");

        File.WriteAllLines(command_filename, command_unit);

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