Example #1
0
    public static void GenerateAndSolve(int blocks, int smallOrder, ref double msSharp, ref double msPlus)
    {
        try
        {
            {
                BlockMatrix       b        = new BlockMatrix(blocks, smallOrder);
                List <DiagMatrix> mainDiag = new List <DiagMatrix>();
                List <DiagMatrix> upDiag   = new List <DiagMatrix>();
                List <DiagMatrix> downDiag = new List <DiagMatrix>();
                downDiag.Add(null);
                List <List <double> > f = new List <List <double> >();

                for (int i = 0; i < blocks; ++i)
                {
                    List <double> diag = new List <double>();
                    for (int j = 0; j < smallOrder; ++j)
                    {
                        diag.Add(j + 1);
                    }
                    DiagMatrix d = new DiagMatrix(smallOrder, diag);
                    mainDiag.Add(d);

                    diag = new List <double>();
                    for (int j = 0; j < smallOrder; ++j)
                    {
                        diag.Add(j * 0.5 + i + 1);
                    }
                    d = new DiagMatrix(smallOrder, diag);
                    upDiag.Add(d);

                    diag = new List <double>();
                    for (int j = 0; j < smallOrder; ++j)
                    {
                        diag.Add(-j * i * 0.5);
                    }
                    d = new DiagMatrix(smallOrder, diag);
                    downDiag.Add(d);

                    diag = new List <double>();
                    for (int j = 0; j < smallOrder; ++j)
                    {
                        double value = -i * 1.2 + j * 4 - 10;
                        if (value == 0)
                        {
                            diag.Add(1);
                        }
                        else
                        {
                            diag.Add(value);
                        }
                    }
                    f.Add(diag);
                }

                b.setMainDiag(mainDiag);
                b.setUpDiag(upDiag);
                b.setDownDiag(downDiag);

                Stopwatch sw = new Stopwatch();
                sw.Start();
                b.solve(f);
                sw.Stop();
                msSharp = sw.Elapsed.TotalMilliseconds;
            }

            {
                int      totalOrder = blocks * smallOrder;
                double[] mainDiag   = new double[totalOrder];
                double[] upDiag     = new double[totalOrder];
                double[] downDiag   = new double[totalOrder];
                double[] f          = new double[totalOrder];
                double[] solution   = new double[totalOrder];
                double   time       = 0.0;

                int k = 0;
                for (int i = 0; i < blocks; ++i)
                {
                    for (int j = 0; j < smallOrder; ++j)
                    {
                        mainDiag[k] = j + 1;
                        upDiag[k]   = j * 0.5 + i + 1;
                        downDiag[k] = -j * i * 0.5;
                        double value = -i * 1.2 + j * 4 - 10;
                        if (value == 0)
                        {
                            f[k] = 1.0;
                        }
                        else
                        {
                            f[k] = value;
                        }
                        k++;
                    }
                }
                GlobalExportFunction(mainDiag, upDiag, downDiag, f, solution, blocks, smallOrder, ref time, null, false);
                msPlus = (double)time;
            }
        }
        catch (Exception)
        {
            Console.WriteLine("Ошибка в вычислениях");
        }
    }