Пример #1
0
        public void QuickSketch(string title)
        {
            force_extrema_update();
            DistributionSketchSettings S = DistributionSketchSettings.Fancy();
            DistributionSketch2D       f = new DistributionSketch2D(this, S);

            f.CreateSketch(false);
            bool oktowrite = !File.Exists(Paths.ImageRepo + "\\" + title + ".bmp");

            if (oktowrite)
            {
                f.SaveImage(title, false);
            }
            else
            {
                int n = 0;
                oktowrite = !File.Exists(Paths.ImageRepo + "\\" + title + n.ToString() + ".bmp");
                while (!oktowrite)
                {
                    n++;
                    oktowrite = !File.Exists(Paths.ImageRepo + "\\" + title + n.ToString() + ".bmp");
                }
                f.SaveImage(title + n.ToString(), false);
            }
        }
Пример #2
0
        public void QuickSketch(string title, bool using_full_path)
        {
            force_extrema_update();
            DistributionSketchSettings S = DistributionSketchSettings.Fancy();
            DistributionSketch2D       f = new DistributionSketch2D(this, S);

            f.CreateSketch(false);
            f.SaveImage(title, using_full_path);
        }
Пример #3
0
        static void Main(string[] args)
        {
            NCGrid_Distribution        funcp    = new NCGrid_Distribution(new RBounds2D(0, 10, 0, 10), 400, 400);
            NCGrid_Distribution        func     = ExactFunctionGeneratorVB2D.GenerateFunctionToGrid("(-1*x) + (2*y)", funcp);
            DistributionSketchSettings settings = DistributionSketchSettings.Fancy();
            int n = 10;

            settings.XLabelCount    = n;
            settings.YLabelCount    = n;
            settings.XGridlineCount = n;
            settings.YGridlineCount = n;
            DistributionSketch2D sktch = new DistributionSketch2D(func, settings);

            sktch.CreateSketch(true);
            sktch.SaveImage(@"C:\Users\Will\Desktop\output.png", true);
        }
        public static void quickPlot(string vb_eval, string title, RBounds2D bounds)
        {
            int n = 100;

            GenerateFunction(vb_eval, bounds, n, n, title);
            NCGrid_Distribution p = NCGrid_Distribution.from_file(title, false);

            File.Delete(Paths.DistributionRepo + "\\" + title + ".dist");
            DistributionSketchSettings S = DistributionSketchSettings.Fancy();

            S.HasHeatmap = true;
            S.HasInfo    = false;
            S.Mode       = SketchMode.DISTRIBUTION_ONLY;
            DistributionSketch2D sk = new DistributionSketch2D(p, S);

            sk.CreateSketch(false);
            sk.SaveImage(title, false);
        }
Пример #5
0
        public virtual void create_animation(string output_title, bool enable_console_output, bool using_full_path, bool allow_overwrite, bool use_floating_color_scale, DistributionSketchSettings S)
        {
            string absolute_video_output_path = video_default_repo + "\\" + output_title + ".avi";

            if (using_full_path)
            {
                absolute_video_output_path = output_title;
            }
            if (File.Exists(absolute_video_output_path) && !allow_overwrite)
            {
                throw new Exception("Error: File exists and overwrite permission not granted.");
            }
            Directory.CreateDirectory(AbsoluteDataSetLocation + "\\images");
            string[]      allfiles      = Directory.GetFiles(absolute_set_location);
            List <string> distrib_files = new List <string>();
            int           q             = 0;

            foreach (string i in allfiles)
            {
                if (i.EndsWith(".dist"))
                {
                    distrib_files.Add(i);
                    NCGrid_Distribution  n  = NCGrid_Distribution.from_file(i, true);
                    DistributionSketch2D sk = new DistributionSketch2D(n, S);
                    if (!use_floating_color_scale)
                    {
                        sk.override_colormap_limits(info);
                    }
                    sk.CreateSketch(true);
                    sk.SaveImage(AbsoluteDataSetLocation + "\\images\\render" + bufferint(q++, 5) + ".bmp", true);
                }
            }
            AVIWriter V = new AVIWriter("wmv3");

            string[]      filenames = Directory.GetFiles(AbsoluteDataSetLocation + "\\images");
            List <string> bmpnames  = new List <string>();

            foreach (string i in filenames)
            {
                if (i.EndsWith(".bmp"))
                {
                    bmpnames.Add(i);
                }
            }
            if (bmpnames.Count != 0)
            {
                Bitmap first = (Bitmap)Bitmap.FromFile(bmpnames[0]);
                V.Open(absolute_video_output_path, first.Width, first.Height);
                V.FrameRate = 50;
                V.AddFrame(first);
                int ct = bmpnames.Count;
                for (int i = 1; i < bmpnames.Count; i++)
                {
                    Bitmap butt = (Bitmap)Bitmap.FromFile(bmpnames[i]);
                    if (enable_console_output)
                    {
                        Console.WriteLine(i.ToString() + " of " + ct.ToString() + " frames stacked" + "(" + (i * 100 / ct).ToString() + "%)");
                    }
                    V.AddFrame(butt);
                    butt.Dispose();
                }
                V.Close();
                first.Dispose();
                if (enable_console_output)
                {
                    Console.WriteLine("AVI successfully created on " + DateTime.Now.ToString() + " in directory " + absolute_video_output_path);
                }
                string[] imagenames = Directory.GetFiles(AbsoluteDataSetLocation + "\\images");
                foreach (string g in imagenames)
                {
                    File.Delete(g);
                }
                Directory.Delete(AbsoluteDataSetLocation + "\\images");
            }
            else
            {
                Console.WriteLine("No bitmap images found in the current directory.");
            }
        }
Пример #6
0
        static void testfunction()
        {
            Console.WriteLine("Press enter to begin, or enter \"c\" to clear repos.");
            if (Console.ReadLine() == "c")
            {
                RepoManagement.ClearRepo(Paths.DistributionRepo, Paths.ImageRepo);
            }
            DateTime then = DateTime.Now;

            Console.WriteLine("Solving...");
            double              L          = 10;
            double              H          = 10;
            int                 n          = 38;
            RBounds2D           bounds     = new RBounds2D(0, L, 0, H);
            NCGrid_Distribution dist       = new NCGrid_Distribution(bounds, n, n);
            BoundaryConditions  conditions = new BoundaryConditions(bounds, n, n, BoundaryConditions.BoundaryConditionType.Dirichlet);
            double              dx         = L / (n - 1);
            double              max        = 5;
            string              fxn        = string.Format("{0}*Sin({1}*x/{2})*(Exp({1}*y/{2}) - Exp(-1*{1}*y/{2}))/(Exp({1}*{3}/{2}) - Exp(-1*{1}*{3}/{2}))", max, Math.PI, L, H);

            conditions.SetConstant(0, BoundaryConditions.Direction.Negative_X);
            conditions.SetConstant(0, BoundaryConditions.Direction.Negative_Y);
            conditions.SetConstant(0, BoundaryConditions.Direction.Positive_Y);
            for (int i = 0; i < n; i++)
            {
                double x = i * dx;
                double z = max * Math.Sin(Math.PI * x / L);
                conditions[i, BoundaryConditions.Direction.Positive_Y] = z;
            }
            int solcount = 50;

            double[] errors              = new double[solcount];
            double[] iteration           = new double[solcount];
            DistributionSketchSettings S = DistributionSketchSettings.Fancy();

            S.SetFigureTitle("Temperature Distribution");
            for (int i = 0; i < solcount; i++)
            {
                Console.WriteLine(i.ToString() + " of " + solcount.ToString() + " iterations processed.");
                iteration[i] = i;
                BVPLinear2D problem = new BVPLinear2D(conditions, LinearOperatorOrder2.Laplace, dist);
                problem.EnableConsoleOutput();
                NCGrid_Distribution soln     = problem.Solve(Matrix.SystemSolvingScheme.Kaczmarz);
                NCGrid_Distribution analytic = ExactFunctionGeneratorVB2D.GenerateFunctionToGrid(fxn, soln);
                soln.ApplyMeshMorphGA(15);
                errors[i] = ErrorEstimation.NormDifference(soln, analytic);
                string title = "iterative-" + i.ToString();
                soln.WriteToFile(title);
                DistributionSketch2D sketch = new DistributionSketch2D(soln, S);
                dist = soln.Clone();
                sketch.CreateSketch(true);
                sketch.SaveImage(title + "-plot", false);
            }
            List <string> filestuff = new List <string>();

            for (int i = 0; i < iteration.Length; i++)
            {
                filestuff.Add(iteration[i].ToString() + "," + errors[i].ToString());
            }
            File.WriteAllLines(@"C:\Users\Will\Desktop\Folders\MATH435\repo\curves-1d\errors-temp.csv", filestuff.ToArray());
            Console.WriteLine("Done.");
            Console.ReadLine();
        }
Пример #7
0
        static void testfunction3()
        {
            Console.WriteLine("Press enter to begin, or enter \"c\" to clear repos.");
            if (Console.ReadLine() == "c")
            {
                RepoManagement.ClearRepo(Paths.DistributionRepo, Paths.ImageRepo);
            }
            DateTime then = DateTime.Now;

            Console.WriteLine("Solving...");
            double              L          = 10;
            double              H          = 10;
            int                 n          = 26;
            RBounds2D           bounds     = new RBounds2D(0, L, 0, H);
            NCGrid_Distribution dist       = new NCGrid_Distribution(bounds, n, n);
            BoundaryConditions  conditions = new BoundaryConditions(bounds, n, n, BoundaryConditions.BoundaryConditionType.Dirichlet);
            double              dx         = L / (n - 1);
            double              omega      = 4;
            double              max        = 8;

            conditions.SetConstant(0, BoundaryConditions.Direction.Negative_X);
            conditions.SetConstant(0, BoundaryConditions.Direction.Negative_Y);
            for (int i = 0; i < n; i++)
            {
                double x      = i * dx;
                double y      = i * dx;
                double ybound = max / (1 + Math.Exp(-1 * (omega * x / L)));
                double xbound = max / (1 + Math.Exp(-1 * (omega * y / H)));
                conditions[i, BoundaryConditions.Direction.Positive_Y] = ybound;
                conditions[i, BoundaryConditions.Direction.Positive_X] = xbound;
            }
            int solcount = 15;
            LinearOperatorOrder2       op = LinearOperatorOrder2.Laplace;
            DistributionSketchSettings S  = DistributionSketchSettings.Fancy();

            S.SetFigureTitle("Double Logistic Boundary");
            for (int i = 0; i < solcount; i++)
            {
                Console.WriteLine(i.ToString() + " of " + solcount.ToString() + " iterations processed.");
                BVPLinear2D problem = new BVPLinear2D(conditions, op, dist);
                problem.EnableConsoleOutput();
                NCGrid_Distribution soln = problem.SolveSRDD();
                string title             = "iterative-" + i.ToString();
                soln.WriteToFile(title);
                DistributionSketch2D sketch = new DistributionSketch2D(soln, S);
                dist = soln.Clone();
                sketch.CreateSketch(true);
                sketch.SaveImage(title + "-plot", false);
                //dist.ApplyMeshMorphGA(2, 0.0019);
                Random R = new Random();
                for (int h = 1; h < dist.Xcount - 1; h++)
                {
                    for (int k = 1; k < dist.Ycount - 1; k++)
                    {
                        double  ddx  = (0.5 - R.NextDouble()) * dx * 0.6;
                        double  ddy  = (0.5 - R.NextDouble()) * dx * 0.6;
                        Vector3 move = new Vector3(ddx, ddy, 0);
                        dist[h, k] = dist[h, k] + move;
                    }
                }
            }
            Console.WriteLine("Done.");
            Console.ReadLine();
        }