public static NCGrid_Distribution NiceFunction(string vb_syntax_eval, RBounds2D bounds, int xcount, int ycount, bool keepfile, string title) { ExactFunctionGeneratorVB2D.GenerateFunction(vb_syntax_eval, bounds, xcount, ycount, title); NCGrid_Distribution n = NCGrid_Distribution.from_file(title, false); return(n); }
public static NCGrid_Distribution from_file(string title, bool using_full_path) { string path = Paths.DistributionRepo + "\\" + title + ".dist"; if (using_full_path) { path = title; } string[] contents = File.ReadAllLines(path); int length = contents.Length; RBounds2D new_bounds = RBounds2D.fromstring(contents[0]); string[] numbers = contents[1].Split(':'); int nx, ny; if (!(int.TryParse(numbers[1], out nx) && int.TryParse(numbers[3], out ny))) { throw new Exception("File format error"); } NCGrid_Distribution created = new NCGrid_Distribution(new_bounds, nx, ny); for (int q = additional_file_lines; q < contents.Length; q++) { int qprime = q - additional_file_lines; int i = qprime % nx; int j = (qprime - i) / nx; created[i, j] = NCAMRNode.fromstring(contents[q]); } return(created); }
public static NCGrid_Distribution NiceFunction(string vb_syntax_eval, RBounds2D bounds, int xcount, int ycount) { ExactFunctionGeneratorVB2D.GenerateFunction(vb_syntax_eval, bounds, xcount, ycount, "temp"); NCGrid_Distribution n = NCGrid_Distribution.from_file("temp", false); string to_delete = Paths.DistributionRepo + "\\temp.dist"; File.Delete(to_delete); return(n); }
public NCGrid_Distribution(RBounds2D _bounds, int xcount, int ycount, double presetvalue) { bounds = _bounds; x_node_count = xcount; y_node_count = ycount; nodes = new NCAMRNode[x_node_count, y_node_count]; generate_nodes(presetvalue); minval = presetvalue; maxval = presetvalue; }
public NCGrid_Distribution(RBounds2D _bounds, int xcount, int ycount) { bounds = _bounds; x_node_count = xcount; y_node_count = ycount; nodes = new NCAMRNode[x_node_count, y_node_count]; generate_nodes(0); minval = 0; maxval = 0; }
public BoundaryConditions(RBounds2D _bounds, int _xcount, int _ycount, BoundaryConditionType _type) { xcount = _xcount; ycount = _ycount; positive_x_vals = new double[xcount]; positive_y_vals = new double[xcount]; negative_x_vals = new double[ycount]; negative_y_vals = new double[ycount]; bounds = _bounds; SetAllBoundaryConditionTypes(_type); }
public Plot2D(double[] x, double[] y, Plot2DSettings S) { settings = S; if (x.Length != y.Length) { throw new Exception("Error: Array dimensions are inconsistent."); } xvals = x; yvals = y; canvas = new Bitmap(S.ImageWidth, S.ImageHeight); x_pixel_count = canvas.Width; y_pixel_count = canvas.Height; double ymax = double.NegativeInfinity; double ymin = double.PositiveInfinity; double xmax = double.NegativeInfinity; double xmin = double.PositiveInfinity; for (int i = 0; i < x.Length; i++) { if (x[i] > xmax) { xmax = x[i]; } if (x[i] < xmin) { xmin = x[i]; } if (y[i] > ymax) { ymax = y[i]; } if (y[i] < ymin) { ymin = y[i]; } } double deltax = xmax - xmin; double deltay = ymax - ymin; double xbar = (xmax + xmin) * 0.5; double ybar = (ymax + ymin) * 0.5; double xscl = 1.0; double yscl = 1.0; double newdeltax = xscl * deltax; double newdeltay = yscl * deltay; xmax = xbar + 0.5 * newdeltax; xmin = xbar - 0.5 * newdeltax; ymax = ybar + 0.5 * newdeltay; ymin = ybar - 0.5 * newdeltay; sketch_bounds = new RBounds2D(xmin, xmax, ymin, ymax); get_positions(); }
static void run_presentation_transient(int numframes) { double t = 0; double dt = 0.1; int n = 25; double L = 10; double H = 10; RBounds2D domain = new RBounds2D(0, L, 0, H); NCGrid_Distribution soln = new NCGrid_Distribution(domain, n, n); double max1 = 4; double max2 = 3; double max3 = 5; double max4 = 2; double omega1 = 1; double omega2 = 0.6; double omega3 = 0.2; double omega4 = 1.2; double phi1 = -0.4; double phi2 = -0.9; double phi3 = 1.3; double phi4 = 0.2; double dx = L / (n - 1); double dy = H / (n - 1); double refinestep = 0.1; int refinecount = 3; for (int i = 0; i < numframes; i++) { BoundaryConditions cond = new BoundaryConditions(soln, BoundaryConditions.BoundaryConditionType.Dirichlet); t += dt; for (int q = 0; q < n; q++) { double x = q * dx; double y = q * dy; cond[q, BoundaryConditions.Direction.Negative_X] = max1 * Math.Sin(4 * Math.PI * x / L) * Math.Sin(omega1 * t - phi1); cond[q, BoundaryConditions.Direction.Negative_Y] = max2 * Math.Sin(2 * Math.PI * y / L) * Math.Sin(omega2 * t - phi2); cond[q, BoundaryConditions.Direction.Positive_X] = max3 * Math.Sin(3 * Math.PI * x / L) * Math.Sin(omega3 * t - phi3); cond[q, BoundaryConditions.Direction.Positive_Y] = max4 * Math.Sin(5 * Math.PI * y / L) * Math.Sin(omega4 * t - phi4); } BVPLinear2D problem = new BVPLinear2D(cond, LinearOperatorOrder2.Laplace, soln); NCGrid_Distribution sol = problem.SolveKaczMarzExt(100, 10, 20); sol.ApplyMeshMorphGA(refinestep); for (int z = 0; z < refinecount - 1; z++) { problem = new BVPLinear2D(cond, LinearOperatorOrder2.Laplace, soln); sol = problem.Solve(Matrix.SystemSolvingScheme.Kaczmarz); sol.ApplyMeshMorphGA(refinestep); } sol.WriteToFile("longtransient_" + i.ToString()); sol.QuickSketch("sol_" + bufferint(i, 4)); } }
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); }
public static void GenerateFunction(string vb_syntax_eval, RBounds2D bounds, int xcount, int ycount, string name) { string[] vbsraw = File.ReadAllLines(script_template); vbsraw[0] = String.Format(vbsraw[0], ycount); vbsraw[1] = String.Format(vbsraw[1], xcount); vbsraw[2] = String.Format(vbsraw[2], name); vbsraw[3] = String.Format(vbsraw[3], bounds.Xmin); vbsraw[4] = String.Format(vbsraw[4], bounds.Xmax); vbsraw[5] = String.Format(vbsraw[5], bounds.Ymin); vbsraw[6] = String.Format(vbsraw[6], bounds.Ymax); vbsraw[14] = String.Format(vbsraw[14], (2 + xcount * ycount)); vbsraw[25] = String.Format(vbsraw[25], vb_syntax_eval); vbsraw[50] = String.Format(vbsraw[50], (2 + xcount * ycount)); string newname = @"C:\Users\Will\Desktop\Folders\MATH435\repo\visual-basic-templates\TEMPORARY.vbs"; File.WriteAllLines(newname, vbsraw); run_script(newname); }
public BoundaryConditions(NCGrid_Distribution boundary_of, BoundaryConditionType _type) { bounds = boundary_of.Bounds; SetAllBoundaryConditionTypes(_type); xcount = boundary_of.Xcount; ycount = boundary_of.Ycount; positive_x_vals = new double[xcount]; positive_y_vals = new double[xcount]; negative_x_vals = new double[ycount]; negative_y_vals = new double[ycount]; for (int i = 0; i < xcount; i++) { positive_x_vals[i] = boundary_of[i, ycount - 1].Value; negative_x_vals[i] = boundary_of[i, 0].Value; } for (int j = 0; j < ycount; j++) { positive_y_vals[j] = boundary_of[xcount - 1, j].Value; negative_y_vals[j] = boundary_of[0, j].Value; } }
public BoundaryConditions(string title, bool using_full_path) { string path = bc_repo + "//" + title + ".bc"; if (using_full_path) { path = title; } string[] contents = File.ReadAllLines(path); bounds = RBounds2D.fromstring(contents[0]); if (!(int.TryParse(contents[1].Split(':')[1], out xcount) && int.TryParse(contents[1].Split(':')[3], out ycount))) { throw new Exception("Error: Improper file format."); } int px_offset = 3; int nx_offset = px_offset + 1 + xcount; int py_offset = nx_offset + 1 + xcount; int ny_offset = py_offset + 1 + ycount; int terminal = ny_offset + 1 + ycount; positive_x_vals = new double[xcount]; positive_y_vals = new double[xcount]; negative_x_vals = new double[ycount]; negative_y_vals = new double[ycount]; positive_x = ConditionTypeFromString(contents[px_offset - 1].Split(':')[1]); negative_x = ConditionTypeFromString(contents[nx_offset - 1].Split(':')[1]); positive_y = ConditionTypeFromString(contents[py_offset - 1].Split(':')[1]); negative_y = ConditionTypeFromString(contents[ny_offset - 1].Split(':')[1]); for (int i = px_offset; i < nx_offset - 1; i++) { double z; if (!double.TryParse(contents[i], out z)) { throw new Exception("Error: Improper file format"); } positive_x_vals[i - px_offset] = z; } for (int i = nx_offset; i < py_offset - 1; i++) { double z; if (!double.TryParse(contents[i], out z)) { throw new Exception("Error: Improper file format"); } negative_x_vals[i - nx_offset] = z; } for (int i = py_offset; i < ny_offset - 1; i++) { double z; if (!double.TryParse(contents[i], out z)) { throw new Exception("Error: Improper file format"); } positive_y_vals[i - py_offset] = z; } for (int i = ny_offset; i < terminal - 1; i++) { double z; if (!double.TryParse(contents[i], out z)) { throw new Exception("Error: Improper file format"); } negative_y_vals[i - ny_offset] = z; } }
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(); }
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(); }
public void OverrideBounds(RBounds2D newbounds) { sketch_bounds = newbounds; get_positions(); }
public static void quickPlot(string vb_eval, string title) { quickPlot(vb_eval, title, RBounds2D.Square(10)); }