Пример #1
0
    private static void diffusivity_2d_elman_contour()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    diffusivity_2d_elman_contour displays a contour plot of a 2D stochastic diffusivity function.
    //
    //  Discussion:
    //
    //    The diffusivity function is computed by DIFFUSIVITY_2D_ELMAN.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Howard Elman, Darran Furnaval,
    //    Solving the stochastic steady-state diffusion problem using multigrid,
    //    IMA Journal on Numerical Analysis,
    //    Volume 27, Number 4, 2007, pages 675-688.
    //
    {
        string        command_filename = "diffusivity_2d_elman_commands.txt";
        List <string> command_unit     = new();
        string        data_filename    = "diffusivity_2d_elman_data.txt";
        List <string> data_unit        = new();
        int           m_1d             = 5;
        int           nx = 51;
        int           ny = 51;

        Console.WriteLine("");
        Console.WriteLine("diffusivity_2d_elman_contour");
        Console.WriteLine("  Display contour or surface plots of the stochastic");
        Console.WriteLine("  diffusivity function defined by diffusivity_2d_elman.");
        //
        //  Set the spatial grid.
        //
        double a = 1.0;

        double[] xvec = typeMethods.r8vec_linspace_new(nx, -a, a);
        double[] yvec = typeMethods.r8vec_linspace_new(ny, -a, a);

        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;

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

        double[] dc = Stochastic.diffusivity_2d_elman(a, cl, dc0, m_1d, omega, nx, nx, 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_elman.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 'Elman 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 + "'");
    }