Esempio n. 1
0
        private void Search()
        {
            int i = c;

            double[] res;
            bool     b;

            while (true)
            {
                res = Expendator.Seq(tmin, tmax, i);
                b   = false;
                for (int k = 0; k < mas.Length; k++)
                {
                    if (res.Contains(mas[k]))
                    {
                        b = true;
                        break;
                    }
                }
                if (!b)
                {
                    if (res.Where((double n) => n >= dtmin && n <= dtmax).Count() >= count)
                    {
                        label8.Text = $"Число точек: {i}; шаг: {res[1] - res[0]}";
                        tcount      = i;
                        return;
                    }
                }

                i++;
            }
        }
        private static int GetTrack(int min, int max, int count, double val)
        {
            val = min + (max - min) * val;

            var arr = Expendator.Seq(min, max, count);

            return(Array.IndexOf(arr, Vectors.Create(arr).BinaryApproxSearch(val)));
        }
        public void Vg()
        {
            var arr = Expendator.Seq(абКонсоль.wbeg, абКонсоль.wend, 300);

            using (StreamWriter f = new StreamWriter("Vg.txt"))
            {
                foreach (var p in arr)
                {
                    f.WriteLine($"{p} {Functions.Vg(p)}");
                }
            }
        }
        public Point[] GetPointArray(int count)
        {
            double cost = Math.Cos(tau), sint = Math.Sin(tau);
            var    angles = Expendator.Seq(0, 2 * Math.PI, count, false);

            Point[] res = new Point[count];
            for (int i = 0; i < angles.Length; i++)
            {
                double sinf = Math.Sin(angles[i]), cosf = Math.Cos(angles[i]);
                res[i] = new Point(xM.x + a * cost * cosf - b * sint * sinf, xM.y + a * sint * cosf + b * cost * sinf);
            }
            return(res);
        }
        public async Task ManyPZAsync(Source[] sources, string path)
        {
            ZlimsCalculate(sources.Length, path);
            groupBox2.Hide();
            groupBox6.Hide();
            GetFields();

            Metrics(path);

            double th = (tmax - tmin) / (tcount - 1);

            all = tcount;
            timer1.Start();
            IProgress <int> progress = new Progress <int>((p) => { save = p; });

            toolStripStatusLabel1.Text = "Вычисления запущены";
            System.Threading.CancellationToken token = source.Token;

            StreamWriter ts  = new StreamWriter(Path.Combine(path, "textnames.txt"));
            StreamWriter pds = new StreamWriter(Path.Combine(path, "pdfnames.txt"));
            string       gl  = $"{Source.ToString(sources)}, (xmin, xmax, count, ymin, ymax) = ({xmin}, {xmax}, {count}dot{count2}, {ymin}, {ymax})";

            Expendator.WriteStringInFile(Path.Combine(path, "SurfaceMain.txt"), gl);

            double[] xmas = Expendator.Seq(xmin, xmax, count);
            double[] ymas = Expendator.Seq(ymin, ymax, count2);

            Func <Point, bool> Filt = (Point point) =>
            {
                for (int q = 0; q < sources.Length; q++)
                {
                    if (sources[q].Filter(point))
                    {
                        return(true);
                    }
                }
                return(false);
            };
            const string filename = "3D ur, uz.txt";

            async Task SlowUxtAsync()
            {
                double[,] ur = new double[count, count2], uz = new double[count, count2];
                for (int i = 0; i < tcount; i++)
                {
                    double t = tmin + i * th;
                    if (t == 0)
                    {
                        continue;
                    }

                    toolStripStatusLabel1.Text = $"Построение графика при t = {t.ToString(3)}";
                    string tit = $"{Source.ToString(sources)}, t = {t.ToString(4)}, (xmin, xmax, count, ymin, ymax) = ({xmin}, {xmax}, {count}dot{count2}, {ymin}, {ymax})";

                    ts.WriteLine(tit + ".txt");
                    pds.WriteLine($"3D ur, uz(title , {tit} ).pdf");
                    button2.Show();

                    await Task.Run(() =>
                                   МатКлассы.Waves.Circle.FieldToFile(filename, path,
                                                                      (double x, double y) => Uxt(x, y, t, sources),
                                                                      xmas, ymas, ref ur, ref uz,
                                                                      token,
                                                                      Filt,
                                                                      tit,
                                                                      true)
                                   );

                    if (source.IsCancellationRequested)
                    {
                        return;
                    }

                    if (checkBox1.Checked)
                    {
                        await Task.Run(() => StartProcess("3Duxt.r", tit, false, path));
                    }

                    filenames[i] = "3D " + tit + " .png";
                    save         = i + 1;
                    if (source.IsCancellationRequested)
                    {
                        return;
                    }
                }

                ur = null; uz = null;
            }

            async Task FastUxtAsync()
            {
                save = 0;
                string[] tsmas = new string[tcount], pdsmas = new string[tcount];
                toolStripStatusLabel1.Text = $"Построение u(x,t) с усиленным параллелизмом";
                int[] kmas = new int[tcount];

                await Task.Run(() =>
                {
                    OtherMethods.CalcUXT(xmas, ymas, sources);

                    Parallel.For(0, tcount, (int i) =>
                    {
                        double t = tmin + i *th;
                        if (t != 0)
                        {
                            string tit = $"{Source.ToString(sources)}, t = {t.ToString(4)}, (xmin, xmax, count, ymin, ymax) = ({xmin}, {xmax}, {count}, {ymin}, {ymax})";

                            tsmas[i]     = tit + ".txt";
                            pdsmas[i]    = $"3D ur, uz(title , {tit} ).pdf";
                            filenames[i] = "3D " + tit + " .png";

                            МатКлассы.Waves.Circle.FieldToFile(path, (double x, double y) => Uxt(x, y, t, sources),
                                                               xmas, ymas,
                                                               token,
                                                               Filt,
                                                               tit);

                            if (source.IsCancellationRequested)
                            {
                                return;
                            }
                        }
                        kmas[i] = 1;

                        save = kmas.Sum();
                        if (source.IsCancellationRequested)
                        {
                            return;
                        }
                    }
                                 );
                });

                tsmas  = tsmas.Where(n => n != null).ToArray();
                pdsmas = pdsmas.Where(n => n != null).ToArray();
                for (int i = 0; i < tsmas.Length; i++)
                {
                    ts.WriteLine(tsmas[i]);
                    pds.WriteLine(pdsmas[i]);
                }
            }

            WriteXY(filename, path, xmas, ymas);
            //выбор параллельного или последовательного методов
            if (даToolStripMenuItem.Checked)
            {
                await FastUxtAsync();
            }
            else
            {
                await SlowUxtAsync();
            }

            Timer1_Tick(new object(), new EventArgs());
            checkBox1.Hide();
            timer1.Stop();
            FilenamesArrayToFile(path);
            ts.Close();
            pds.Close();
            button2.Hide();

            await AnimateAsync(gl, path);
        }