/// <summary> /// Creation of DG fields. /// </summary> protected override void CreateFields() { int GridDeg; int D = this.GridData.SpatialDimension; if (this.Grid is GridCommons) { GridCommons _Grid = (GridCommons)this.Grid; GridDeg = _Grid.Cells.Select(cl => _Grid.GetRefElement(cl.Type).GetInterpolationDegree(cl.Type)).Max(); if (_Grid.GetRefElement(_Grid.Cells[0].Type) == Square.Instance || _Grid.GetRefElement(_Grid.Cells[0].Type) == Cube.Instance) { // hack: otherwise DG deg gets to large GridDeg = (int)Math.Round(Math.Pow(GridDeg, 1.0 / D)); } } else { GridDeg = 1; // aggregation grid } Basis b = new Basis(this.GridData, 2 + GridDeg); Console.WriteLine("Grid degree is " + GridDeg + " => Using DG order: " + b.Degree); f1 = new SinglePhaseField(b, "f1"); f2 = new SinglePhaseField(b, "f2"); Laplace_f1_Numerical = new SinglePhaseField(b, "Laplace_f1_Numerical"); Laplace_f2_Numerical = new SinglePhaseField(b, "Laplace_f2_Numerical"); Laplace_f1_Analytical = new SinglePhaseField(b, "Laplace_f1_Analytical"); Laplace_f2_Analytical = new SinglePhaseField(b, "Laplace_f2_Analytical"); f1Gradient_Analytical = new SinglePhaseField[D]; f2Gradient_Analytical = new SinglePhaseField[D]; f1Gradient_Numerical = new SinglePhaseField[D]; f2Gradient_Numerical = new SinglePhaseField[D]; for (int d = 0; d < D; d++) { f1Gradient_Analytical[d] = new SinglePhaseField(b, string.Format("df1_dx{0}_Analytical", d)); f2Gradient_Analytical[d] = new SinglePhaseField(b, string.Format("df2_dx{0}_Analytical", d)); f1Gradient_Numerical[d] = new SinglePhaseField(b, string.Format("df1_dx{0}_Numerical", d)); f2Gradient_Numerical[d] = new SinglePhaseField(b, string.Format("df2_dx{0}_Numerical", d)); } }
static void Plot2dGridGnuplot(GridCommons grd) { using (var gp = new Gnuplot()) { int J = grd.Cells.Length; double xmin = double.MaxValue, xmax = double.MinValue, ymin = double.MaxValue, ymax = double.MinValue; for (int j = 0; j < J; j++) { var Cell = grd.Cells[j]; var Kref = grd.GetRefElement(Cell.Type); int[] R; if (Kref.GetType() == typeof(Triangle)) { R = new int[] { 0, 1, 2, 0 }; } else if (Kref.GetType() == typeof(Square)) { R = new int[] { 0, 1, 3, 2, 0 }; } else { throw new NotSupportedException(); } int I = 4; int K = 20; NodeSet LocNodes = new NodeSet(Kref, I * K * (R.Length - 1), 2); var vtx = Kref.Vertices; double alpha = 1.0 / (K - 1); for (int iFace = 0; iFace < R.Length - 1; iFace++) { for (int k = 0; k < K; k++) { double a = alpha * k; for (int d = 0; d < 2; d++) { LocNodes[iFace * K + k, d] = vtx[R[iFace], d] * (1 - a) + vtx[R[iFace + 1], d] * a; } } } for (int i = 0; i < I; i++) { int ind0 = K * (R.Length - 1) * i; int indE = K * (R.Length - 1) * (i + 1) - 1; int indp0 = K * (R.Length - 1) * (i - 1); int indpE = K * (R.Length - 1) * i - 1; var LocNodes_i = LocNodes.ExtractSubArrayShallow(new int[] { ind0, 0 }, new int[] { indE, 1 }); if (i > 0) { var LocNodes_iP = LocNodes.ExtractSubArrayShallow(new int[] { indp0, 0 }, new int[] { indpE, 1 }); LocNodes_i.Set(LocNodes_iP); LocNodes_i.Scale(0.65); } else { LocNodes_i.Scale(0.9); } } LocNodes.LockForever(); MultidimensionalArray GlobalNodes = Transform(Kref, Cell, LocNodes); xmin = Math.Min(xmin, GlobalNodes.ExtractSubArrayShallow(-1, 0).Min()); xmax = Math.Max(xmax, GlobalNodes.ExtractSubArrayShallow(-1, 0).Max()); ymin = Math.Min(ymin, GlobalNodes.ExtractSubArrayShallow(-1, 1).Min()); ymax = Math.Max(ymax, GlobalNodes.ExtractSubArrayShallow(-1, 1).Max()); gp.PlotXY(GlobalNodes.GetColumn(0), GlobalNodes.GetColumn(1), title: ("tri" + j), format: new PlotFormat(lineColor: ((LineColors)j))); } gp.SetXRange(xmin - 0.1, xmax + 0.1); gp.SetYRange(ymin - 0.1, ymax + 0.1); gp.Execute(); Console.WriteLine("press any key to continue..."); Console.ReadKey(); } }