public BVPLinear2D(BoundaryConditions _conditions, LinearOperatorOrder2 _operator, NCGrid_Distribution _discretization) { lin_operator = _operator; discretization = _discretization; boundary_conditions = _conditions; bool[] all_necessary_compatibility_conditions = { boundary_conditions.Bounds.Xmax == discretization.Bounds.Xmax, boundary_conditions.Bounds.Xmin == discretization.Bounds.Xmin, boundary_conditions.Bounds.Ymax == discretization.Bounds.Ymax, boundary_conditions.Bounds.Ymin == discretization.Bounds.Ymin, boundary_conditions.Xcount == discretization.Xcount, boundary_conditions.Ycount == discretization.Ycount }; bool compatible = true; foreach (bool i in all_necessary_compatibility_conditions) { compatible = compatible && i; } if (!compatible) { throw new Exception("Error: Boundary conditions and initial discretization are incompatible."); } }
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(); }
static void testfunction2() { 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 omega = 4; double max = 8; string fxn = string.Format("{4}*Sin({0}*{1}*x/{2})*Exp(y/{3})", Math.PI, omega, L, H, max); ExactFunctionGeneratorVB2D.quickPlot(fxn, "analytic"); conditions.SetConstant(0, BoundaryConditions.Direction.Negative_X); conditions.SetConstant(0, BoundaryConditions.Direction.Positive_X); for (int i = 0; i < n; i++) { double x = i * dx; double z_neg = max * Math.Sin(Math.PI * omega * x / L); double z_pos = max * Math.E * Math.Sin(Math.PI * omega * x / L); conditions[i, BoundaryConditions.Direction.Positive_Y] = z_pos; conditions[i, BoundaryConditions.Direction.Negative_Y] = z_neg; } int solcount = 15; LinearOperatorOrder2 op = new LinearOperatorOrder2(0, 0, 0, 1 / (H * H), Math.PI * Math.PI * omega * omega / (L * L), 0); 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, op, dist); problem.EnableConsoleOutput(); NCGrid_Distribution soln = problem.SolveSRDD(); NCGrid_Distribution analytic = ExactFunctionGeneratorVB2D.GenerateFunctionToGrid(fxn, soln); soln.ApplyMeshMorphGA(15, 0.0000015); 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(); }