Exemplo n.º 1
0
        public async void button1_Click(object sender, EventArgs e)
        {
            HankelTuple = HankelTupleClear;
            ClearSeries();
            toolStripStatusLabel1.Text = "Чтение данных и генерация переменных";

            int k = Convert.ToInt32(numericUpDown1.Value);

            CreateArrays(k);

            double cor = GetCorner();

            beg = textBox2.Text.ToDouble();
            end = textBox3.Text.ToDouble();
            Waves.Circle circle = sourceIt.GetCircle;

            double h = (end - beg) / (k - 1);

            Waves.Normal2D[] norms = sourceIt.Norms;
            Waves.Normal2D   N     = circle.GetNormal(cor);
            double           w     = textBox7.Text.ToDouble();

            prbar = new int[k]; timer1.Enabled = true;
            int ind = listBox1.SelectedIndex;

            toolStripStatusLabel1.Text = "Мемоизация PMRSN (занимает неопределённое время)"; timer2.Start();
            DateTime t1 = DateTime.Now;

            ShowCancelControls();

            source = new System.Threading.CancellationTokenSource();
            System.Threading.CancellationToken token = source.Token;
            await Task.Run(() =>
            {
                for (int ie = 0; ie < xval.Length; ie++)
                {
                    xval[ie] = beg + ie *h;
                }

                switch (ind)
                {
                case 0:
                    Parallel.For(0, k, (int i) =>
                    {
                        if (token.IsCancellationRequested)
                        {
                            toolStripStatusLabel1.Text = "Асинхронная операция была отменена"; return;
                        }
                        SetIElemForAll(i, GetTupF(N.Position.x + N.n.x *xval[i], N.Position.y + N.n.y *xval[i], w, norms), cor);
                    });
                    break;

                case 1:
                    Parallel.For(0, k, (int i) =>
                    {
                        if (token.IsCancellationRequested)
                        {
                            toolStripStatusLabel1.Text = "Асинхронная операция была отменена"; return;
                        }
                        SetIElemForAll(i, GetTupF(N.Position.x + N.n.x *w, N.Position.y + N.n.y *w, xval[i], norms), cor);
                    });
                    break;

                case 3:
                    Parallel.For(0, k, (int i) =>
                    {
                        if (token.IsCancellationRequested)
                        {
                            toolStripStatusLabel1.Text = "Асинхронная операция была отменена"; return;
                        }
                        Complex[] tmp2 = u(N.Position.x + N.n.x *w, N.Position.y + N.n.y *w, xval[i] /** ThU / SpU*/, norms).ToComplex();
                        SetIElemForAll(i, new Complex[3], tmp2, cor);
                    });
                    Setzlim(uRvalRes, uRzRes);
                    break;

                default:
                    beg = 0;
                    end = pimult2;
                    Parallel.For(0, k, (int i) =>
                    {
                        if (token.IsCancellationRequested)
                        {
                            toolStripStatusLabel1.Text = "Асинхронная операция была отменена"; return;
                        }
                        xval[i] = beg + i *h;
                        SetIElemForAll(i, GetTupF(norms[i].Position.x, norms[i].Position.y, w, norms), norms[i].Corner);
                    });
                    break;
                }
            });

            if (ind == 3 && checkBox13.Checked)
            {
                DrawUXW(N.Position.x + N.n.x * w, N.Position.y + N.n.y * w, 0, norms, cor);
            }

            HideCancelControls();

            switch (ind)
            {
            case 0:
                chart1.Titles[0].Text = $"(x,y): [{N.Position.x}; {N.Position.y}]...[{N.Position.x + N.n.x * xval[k - 1]}; {N.Position.y + N.n.y * xval[k - 1]}], w = {w}";
                break;

            case 1:
                chart1.Titles[0].Text = $"(x,y) = ({N.Position.x + N.n.x * w}; {N.Position.y + N.n.y * w}), w = {beg} ... {end}";
                break;

            case 3:
                chart1.Titles[0].Text = $"(x,y) = ({N.Position.x + N.n.x * w}; {N.Position.y + N.n.y * w}), t = {beg} ... {end}";
                break;

            default:
                chart1.Titles[0].Text = $"(x,y) in ({sourceIt.Center}; {sourceIt.radius}), w = {w}";
                break;
            }

            timer2.Stop();
            timer1.Stop();
            toolStripStatusLabel1.Text = $"Вычисления закончены. Время: {DateTime.Now - t1}";
            Expendator.WriteInFile($"ur, uz (last)", new Vectors(xval), new Vectors(uRval), new Vectors(uIval), new Vectors(umodval), new Vectors(uRz), new Vectors(uIz), new Vectors(uAz));
            pictureBox1.Hide();
            progressBar1.Value = progressBar1.Maximum;
            ReDraw();

            HankelTuple = HankelTupleWith;
        }
Exemplo n.º 2
0
 public void WriteInFile(string filename, string shortname, string savename) => Expendator.WriteInFile(filename, new string[]
 {
     shortname,
     savename,
     Title,
     XLabel, Ylabel, Zlabel
 });
Exemplo n.º 3
0
        private async Task MakeDiffAsync(bool Normalize)
        {
            var ar = Enumerable.Range(0, sourcesCount).ToArray();

            all = CountOfEdges;
            int[] tmp = new int[all];
            save = 0;
            timer1.Start();
            await Task.Run(() =>
            {
                Parallel.For(0, sourcesCount, (int i) =>
                {
                    var args    = ar.Where(n => n != i).ToArray();
                    var ArNames = new List <string>(args.Length);

                    for (int j = 0; j < sourcesCount - 1; j++)
                    {
                        double max;
                        if (Normalize)
                        {
                            max = 0;
                            using (StreamReader f0 = new StreamReader(Path.Combine(fwithout[i], ArraysNames[args[j]])))
                                using (StreamReader f1 = new StreamReader(Path.Combine(fwith[i], ArraysNames[args[j]])))
                                {
                                    string s = f0.ReadLine();
                                    while (s != null && s.Length > 0)
                                    {
                                        double t = Convert.ToDouble(f1.ReadLine().Replace('.', ',')) - Convert.ToDouble(s.Replace('.', ','));
                                        if (max < t *t)
                                        {
                                            max = t *t;
                                        }
                                        s = f0.ReadLine();
                                    }
                                }
                            max = Math.Sqrt(max);
                        }
                        else
                        {
                            max = 1.0;
                        }
                        //Debug.WriteLine(max);
                        using (StreamWriter res = new StreamWriter(Path.Combine(fdiff[i], ArraysNames[args[j]])))
                        {
                            using (StreamReader f0 = new StreamReader(Path.Combine(fwithout[i], ArraysNames[args[j]])))
                                using (StreamReader f1 = new StreamReader(Path.Combine(fwith[i], ArraysNames[args[j]])))
                                {
                                    string s = f0.ReadLine();
                                    while (s != null && s.Length > 0)
                                    {
                                        double t = Convert.ToDouble(f1.ReadLine().Replace('.', ',')) - Convert.ToDouble(s.Replace('.', ','));
                                        res.WriteLine((t / max).ToString().Replace(',', '.'));
                                        s = f0.ReadLine();
                                    }
                                }
                        }

                        ArNames.Add(ArraysNames[args[j]]);

                        tmp[i * (sourcesCount - 1) + j]++;
                        save = tmp.Sum();
                    }

                    ArNames.Insert(0, timefile);
                    Expendator.WriteInFile(Path.Combine(fdiff[i], "DefNames.txt"), ArNames.Select(s => s.Replace(".txt", "")).ToArray());
                    InteractFlags(fdiff[i]);
                    File.Copy(Expendator.GetResource("GraficFunc.r"), Path.Combine(fdiff[i], "GraficFunc.r"), true);
                });
            });

            save = 0;
            Timer1_Tick(new object(), new EventArgs());
            timer1.Stop();
        }
Exemplo n.º 4
0
        private static async Task GetDataToFileAsync(string shortname, string savename, Func <double, double, double> F, double[] x, double[] y, IProgress <int> progress, System.Threading.CancellationToken token, StringsForGrafic forGrafic, bool parallel = true)
        {
            int lenx = x.Length;
            int leny = y.Length;

            int[] k = new int[lenx * leny];
            double[,] ur = new double[lenx, leny];

            void InnerLoop(int i)
            {
                for (int j = 0; j < leny; j++)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    ur[i, j]        = F(x[i], y[j]);
                    k[i * leny + j] = 1;
                }
                progress.Report(k.Sum());
            }

            await Task.Run(() =>
            {
                //нахождение массивов
                if (parallel)
                {
                    Parallel.For(0, lenx, (int i) =>
                    {
                        InnerLoop(i);
                    });
                }
                else
                {
                    for (int i = 0; i < lenx; i++)
                    {
                        InnerLoop(i);
                    }
                }
            });


            var filenames = new string[]
            {
                $"{shortname}(args).txt",
                $"{shortname}(vals).txt",
                $"{shortname}(info).txt"
            };

            Expendator.WriteInFile("3D Grafics Data Adress.txt", filenames);

            forGrafic.WriteInFile(filenames[2], shortname, savename);

            if (lenx == leny)
            {
                using (StreamWriter xs = new StreamWriter(filenames[0]))
                {
                    xs.WriteLine("x y");
                    for (int i = 0; i < lenx; i++)
                    {
                        xs.WriteLine($"{x[i]} {y[i]}");
                    }
                }

                using (StreamWriter ts = new StreamWriter(filenames[1]))
                {
                    ts.WriteLine("vals");
                    for (int i = 0; i < lenx; i++)
                    {
                        for (int j = 0; j < lenx; j++)
                        {
                            if (Double.IsNaN(ur[i, j]))
                            {
                                ts.WriteLine("NA");
                            }
                            else
                            {
                                ts.WriteLine($"{ur[i, j]}");
                            }
                        }
                    }
                }
            }
            else
            {
                double max = 0, a = 0, b = 0;
                for (int i = 0; i < lenx; i++)
                {
                    for (int j = 0; j < leny; j++)
                    {
                        if (ur[i, j] > max)
                        {
                            max = ur[i, j];
                            a   = x[i];
                            b   = y[j];
                        }
                    }
                }
                Expendator.WriteInFile(savename + "(MaxCoordinate).txt", new string[]
                {
                    "a b",
                    $"{a.ToRString()} {b.ToRString()}".Replace(',', '.'),
                    $"maximum is {max}".Replace(',', '.'),
                    $"omega = {1.0 / (a * 1000)}"
                });
            }
        }
 /// <summary>
 /// Записать коллекцию параметров в файл
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="list"></param>
 public static void WriteInFile(string filename, IEnumerable <EllipseParam> list) => Expendator.WriteInFile(filename, list.Select(l => l.ToString()).ToArray());