/// <summary> /// See also <see cref="GRID_CASE"/> and <see cref="GRID_FILE"/>. /// </summary> protected override GridCommons CreateOrLoadGrid() { GridCommons grd; switch (GRID_CASE) { case 1: grd = Grid1D.LineGrid(GenericBlas.Linspace(-4, 4, 5)); break; case 2: { grd = Grid1D.LineGrid(GenericBlas.Linspace(-4, 4, 20)); break; } case 3: { double[] xnodes = new double[] { -2, 0, 2 }; double[] ynodes = new double[] { -2, 0, 2 }; double dx = xnodes[1] - xnodes[0]; double dy = ynodes[1] - ynodes[0]; //this.CellVolume = dx * dy; //if(Math.Abs(dx - dy) <= 1.0e-12) // EdgeArea = dx; grd = Grid2D.Cartesian2DGrid(xnodes, ynodes, periodicX: false, periodicY: false, type: CellType.Square_4); break; } case 4: { double[] xnodes = GenericBlas.Linspace(-1, 5, 9); double[] ynodes = GenericBlas.Linspace(-1, 5, 13); double dx = xnodes[1] - xnodes[0]; double dy = ynodes[1] - ynodes[0]; this.CellVolume = dx * dy; if (Math.Abs(dx - dy) <= 1.0e-12) { EdgeArea = dx; } grd = Grid2D.Cartesian2DGrid(xnodes, ynodes, periodicX: false, periodicY: false, type: CellType.Square_4); break; } case 5: { double[] xnodes = GenericBlas.Linspace(-1, 1, 8); double[] ynodes = GenericBlas.Linspace(-1, 1, 13); grd = Grid2D.UnstructuredTriangleGrid(xnodes, ynodes, JitterScale: 0.5); break; } case 6: { grd = Circle(); break; } case 7: { // test periodicity grd = Grid2D.CurvedSquareGrid(GenericBlas.Linspace(1, 2, 4), GenericBlas.Linspace(0, 0.25, 10), CellType.Square_9, PeriodicS: true); AltRefSol = true; break; } case 8: { double[] rNodes = GenericBlas.Linspace(1, 4, 8); double[] sNodes = GenericBlas.Linspace(0, 0.5, 15); grd = Grid2D.CurvedSquareGrid(rNodes, sNodes, CellType.Square_4, PeriodicS: false); break; } case 9: { double[] xNodes1 = GenericBlas.Linspace(-1, 0.3, 7); double[] yNodes1 = GenericBlas.Linspace(-1, 1, 13); double[] xNodes2 = GenericBlas.Linspace(0.3, 1, 5); double[] yNodes2 = GenericBlas.Linspace(-1, 1, 25); double[] xNodes3 = GenericBlas.Linspace(-1, 1, 8); double[] yNodes3 = GenericBlas.Linspace(-2, -1, 5); var grd1 = Grid2D.Cartesian2DGrid(xNodes1, yNodes1, type: CellType.Square_Linear); var grd2 = Grid2D.Cartesian2DGrid(xNodes2, yNodes2, type: CellType.Square_Linear); var grd3 = Grid2D.Cartesian2DGrid(xNodes3, yNodes3, type: CellType.Square_Linear); var grdJ = GridCommons.MergeLogically(grd1, GridCommons.MergeLogically(grd2, grd3)); grd = GridCommons.Seal(grdJ, 4); break; } case 10: { double[] xNodes1 = GenericBlas.Linspace(-1, 0.3, 4); double[] xNodes2 = GenericBlas.Linspace(0.3, 1, 5); double[] yNodes1 = GenericBlas.Linspace(-1, 1, 9); double[] yNodes2 = GenericBlas.Linspace(-1, 1, 5); double[] zNodes1 = GenericBlas.Linspace(-1, 1, 5); double[] zNodes2 = GenericBlas.Linspace(-1, 1, 3); var grd1 = Grid3D.Cartesian3DGrid(xNodes1, yNodes1, zNodes1); var grd2 = Grid3D.Cartesian3DGrid(xNodes2, yNodes2, zNodes2); var grdJ = GridCommons.MergeLogically(grd1, grd2); grd = GridCommons.Seal(grdJ, 4); break; } case 11: { grd = Grid2D.Trapezoidal2dGrid(4, 2, 2, GenericBlas.Linspace(0, 1, 2)); break; } case 12: { var grid1 = Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-3, 5, 5), GenericBlas.Linspace(-1, 1, 2)); //grd = base_grid; //grid1.Plot2DGrid(); var gdat1 = new GridData(grid1); var grid2 = gdat1.Adapt(new int[] { 1, 2 }, null, out GridCorrelation o2c_1); //grid2.Plot2DGrid(); var gdat2 = new GridData(grid2); var grid3 = gdat2.Adapt(new int[] { 2, 4 }, null, out GridCorrelation o2c_2); //grid3.Plot2DGrid(); var gdat3 = new GridData(grid3); var grid4 = gdat3.Adapt(new int[] { 11, 14, 15 }, null, out GridCorrelation o2c_3); //grid4.Plot2DGrid(); var gdat4 = new GridData(grid4); var grid5 = gdat4.Adapt(new[] { 4, 21, 22, 10 }, new[] { new[] { 13, 14, 15, 16 } }, out GridCorrelation o2c_4); //grid5.Plot2DGrid(); grd = grid5; break; } case 13: { double[] rNodes = GenericBlas.Linspace(1, 4, 8); double[] sNodes = GenericBlas.Linspace(0, 0.5, 15); grd = Grid2D.CurvedSquareGrid(rNodes, sNodes, CellType.Square_9, PeriodicS: false); break; } case 14: { double[] rNodes = GenericBlas.Linspace(1, 4, 13); double[] sNodes = GenericBlas.Linspace(0, 0.5, 25); grd = Grid2D.CurvedSquareGrid(rNodes, sNodes, CellType.Square_16, PeriodicS: false); break; } case 15: { double[] rNodes = GenericBlas.Linspace(1, 2, 4); double[] sNodes = GenericBlas.Linspace(0, 0.5, 4); double[] zNodes = GenericBlas.Linspace(-1, 1, 5); grd = Grid3D.CylinderGrid(rNodes, sNodes, zNodes, CellType.Cube_27, PeriodicS: false, PeriodicZ: false); break; } case 16: { grd = Grid2D.Ogrid(0.5, 1, 5, 3, CellType.Square_4); break; } case 17: { grd = Grid3D.Ogrid(0.5, 1, 3, 3, GenericBlas.Linspace(0, 4, 3)); break; } case 18: { // aggregation grid double[] xNodes = GenericBlas.Linspace(-1, 1, 5); double[] yNodes = GenericBlas.Linspace(-1, 1, 5); var baseGrid = Grid2D.UnstructuredTriangleGrid(xNodes, yNodes); var baseGdat = new GridData(baseGrid); var aggGrid = CoarseningAlgorithms.Coarsen(baseGdat, 2); base.AggGrid = aggGrid; grd = null; double dx = xNodes[1] - xNodes[0]; double dy = yNodes[1] - yNodes[0]; this.CellVolume = dx * dy; if (Math.Abs(dx - dy) <= 1.0e-12) { EdgeArea = dx; } break; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++ // more expensive grids (not tested in DEBUG MODE) // ++++++++++++++++++++++++++++++++++++++++++++++++++++ case 30: { double[] xnodes = GenericBlas.Linspace(-1, 1, 7); double[] ynodes = GenericBlas.Linspace(-1, 1, 9); double[] znodes = GenericBlas.Linspace(-1, 1, 8); grd = Grid3D.Cartesian3DGrid(xnodes, ynodes, znodes, periodicX: false, periodicY: false, periodicZ: false); break; } // +++++++++++++++++++++++++++++++++ // grids imported from GMSH/CGNS // +++++++++++++++++++++++++++++++++ case 50: { // gmsh grid import test Console.WriteLine("Loading file: '" + GRID_FILE + "'..."); grd = GridImporter.Import(GRID_FILE); //Console.WriteLine("done. " + grd.NoOfUpdateCells.MPISum() + " cells loaded."); //Plot2dGridGnuplot(grd); HashSet <CellType> cellTypes = new HashSet <CellType>(); foreach (var cell in grd.Cells) { if (!cellTypes.Contains(cell.Type)) { cellTypes.Add(cell.Type); } } Console.Write("Cell types: "); foreach (var ct in cellTypes) { Console.Write(ct); Console.Write(" "); } Console.WriteLine(); break; } default: throw new NotSupportedException(); } return(grd); }