/// <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); //grd = Grid3D.Ogrid(0.5, 1, 5, 3, GenericBlas.Linspace(0,4,5)); 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); }
public override GridCommons GetGrid(IDatabaseInfo db) { GridCommons grid; switch (GridType) { case GridTypes.Structured: int noOfCellsPerDirection; switch (GridSize) { case GridSizes.Tiny: noOfCellsPerDirection = 5; break; case GridSizes.Small: noOfCellsPerDirection = 10; break; case GridSizes.Normal: noOfCellsPerDirection = 20; break; case GridSizes.Large: noOfCellsPerDirection = 40; break; case GridSizes.Huge: noOfCellsPerDirection = 80; break; default: throw new Exception(); } double[] nodes = GenericBlas.Linspace(-2.0, 2.0, noOfCellsPerDirection + 1); grid = Grid3D.Cartesian3DGrid(nodes, nodes, nodes); break; case GridTypes.Unstructured: switch (GridSize) { case GridSizes.Tiny: grid = db.Controller.DBDriver.LoadGrid( new Guid("523a0225-2c4f-46dd-ac75-86da5d547ad4"), db); //grid = db.DBController.DBDriver.LoadGrid( // new Guid("ec92c7eb-890e-468b-9728-5e5a3235822a"), db); break; case GridSizes.Small: grid = db.Controller.DBDriver.LoadGrid( new Guid("b55f328e-49dc-4e0b-aa0c-a8f3529adddc"), db); //grid = db.DBController.DBDriver.LoadGrid( // new Guid("45e51c76-e636-4bf1-b577-966d23aa744f"), db); break; case GridSizes.Normal: grid = db.Controller.DBDriver.LoadGrid( new Guid("189ac579-f9b9-4e5f-b847-4bc32b77c812"), db); //grid = db.DBController.DBDriver.LoadGrid( // new Guid("990cd7df-fe82-4c36-86b3-ea67d24057c7"), db); break; case GridSizes.Large: grid = db.Controller.DBDriver.LoadGrid( new Guid("51b0b6d8-f52a-45e3-a785-258fee6f573c"), db); //grid = db.DBController.DBDriver.LoadGrid( // new Guid("989ea7bb-86d4-4429-98a7-27471aab4bb8"), db); break; case GridSizes.Huge: throw new NotImplementedException(); default: throw new Exception(); } break; default: throw new Exception(); } return(grid); }
static public IBM_Control PrecTest3DChannel(int k, int cells_x, int cells_yz) { IBM_Control C = new IBM_Control(); // basic database options // ====================== C.savetodb = false; //C.DbPath = @"/home/oe11okuz/BoSSS_DB/Lichtenberg_DB"; //C.DbPath = @"P:\BoSSS_DBs\Bug"; //string restartSession = "727da287-1b6a-463e-b7c9-7cc19093b5b3"; //string restartGrid = "3f8f3445-46f1-47ed-ac0e-8f0260f64d8f"; //C.DynamicLoadBalancing_Period = 1; //C.DynamicLoadBalancing_CellCostEstimatorFactories.Add(delegate (IApplication app, int noOfPerformanceClasses) { // Console.WriteLine("i was called"); // int[] map = new int[] { 1, 5, 100 }; // return new StaticCellCostEstimator(map); //}); C.DynamicLoadBalancing_RedistributeAtStartup = false; //c.DynamicLoadBalancing_CellClassifier = new IndifferentCellClassifier(); C.DynamicLoadBalancing_CellCostEstimatorFactories.Add((p, i) => new StaticCellCostEstimator(new[] { 1 })); //c.DynamicLoadBalancing_CellCostEstimatorFactories.Add((p, i) => new StaticCellCostEstimator(new[] { 10, 1 })); //c.DynamicLoadBalancing_CellCostEstimatorFactories.AddRange(ArtificialViscosityCellCostEstimator.GetStaticCostBasedEstimator()); //c.DynamicLoadBalancing_CellCostEstimatorFactories.AddRange(ArtificialViscosityCellCostEstimator.GetMultiBalanceConstraintsBasedEstimators()); // Assign correct names C.SessionName = "Channel_" + k + "_" + cells_x + "x" + cells_yz; C.saveperiod = 1; //C.SessionName = "Sphere_k" + k + "_h" + h+"Re100"; C.ProjectName = "3DChannel"; C.ProjectDescription = "Sphere_k" + k + cells_x + "x" + cells_yz + "x" + cells_yz; C.Tags.Add("Prec Test"); // Create Fields C.FieldOptions.Add("VelocityX", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("VelocityY", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("VelocityZ", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("Pressure", new FieldOpts() { Degree = k - 1, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("PhiDG", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("Phi", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); #region Creates grid () and sets BC //// Create Grid Console.WriteLine("...generating grid"); C.GridFunc = delegate { // x-direction var _xNodes = GenericBlas.Linspace(-0.5, 1.5, cells_x + 1); // y-direction var _yNodes = GenericBlas.Linspace(-0.5, 0.5, cells_yz + 1); // z-direction var _zNodes = GenericBlas.Linspace(-0.5, 0.5, cells_yz + 1); // Cut Out var grd = Grid3D.Cartesian3DGrid(_xNodes, _yNodes, _zNodes, false, true, false, CellType.Cube_Linear); grd.EdgeTagNames.Add(1, "Velocity_inlet"); grd.EdgeTagNames.Add(2, "Wall"); grd.EdgeTagNames.Add(3, "Pressure_Outlet"); grd.DefineEdgeTags(delegate(double[] _X) { var X = _X; double x = X[0]; double y = X[1]; double z = X[2]; if (Math.Abs(x - (-0.5)) < 1.0e-6) { // inlet return(1); } if (Math.Abs(x - (1.5)) < 1.0e-6) { // outlet return(3); } if (Math.Abs(y - (-0.5)) < 1.0e-6) { // left return(2); } if (Math.Abs(y - (0.5)) < 1.0e-6) { // right return(2); } if (Math.Abs(z - (-0.5)) < 1.0e-6) { // top left return(2); } if (Math.Abs(z - (0.5)) < 1.0e-6) { // top right return(2); } throw new ArgumentOutOfRangeException(); }); return(grd); }; #endregion // Set Initial Conditions C.InitialValues_Evaluators.Add("VelocityX", X => 1 - 4 * (X[2] * X[2])); C.InitialValues_Evaluators.Add("VelocityY", X => 0); C.InitialValues_Evaluators.Add("VelocityZ", X => 0); C.InitialValues_Evaluators.Add("Pressure", X => 0); // Because its only channeö C.InitialValues_Evaluators.Add("Phi", X => - 1); Console.WriteLine("...starting calculation of Preconditioning test with 3D Channel"); // Physical values C.PhysicalParameters.rho_A = 1; C.PhysicalParameters.mu_A = 1.0 / 10.0; // Boundary conditions C.AddBoundaryCondition("Velocity_inlet", "VelocityX", (X, t) => 1 - 4 * (X[2] * X[2])); C.AddBoundaryCondition("Velocity_inlet", "VelocityY", (X, t) => 0); C.AddBoundaryCondition("Wall"); C.AddBoundaryCondition("Pressure_Outlet"); // misc. solver options // ==================== C.PhysicalParameters.IncludeConvection = true; C.AdvancedDiscretizationOptions.PenaltySafety = 4; C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2; C.LevelSetSmoothing = false; C.MaxKrylovDim = 1000; C.MaxSolverIterations = 1; C.Solver_ConvergenceCriterion = 1E-5; C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite; // Solver configuration C.NonlinearSolve = NonlinearSolverCodes.NewtonGMRES; C.LinearSolve = LinearSolverCodes.classic_mumps; // Timestepping // ============ C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.BDF2; double dt = 1E20; C.dtFixed = dt; C.dtMax = dt; C.dtMin = dt; C.Endtime = 10000000; C.NoOfTimesteps = 1; C.NoOfMultigridLevels = 7; return(C); }
static public IBM_Control SphereFlow(string _DbPath = null, int k = 2, int cells_x = 11, int cells_yz = 9, bool only_channel = true, bool pardiso = true, int no_p = 1, int no_it = 1, bool restart = false, bool load_Grid = false, string _GridGuid = null) { IBM_Control C = new IBM_Control(); // basic database options // ====================== //C.DbPath = _DbPath; C.savetodb = true; //C.savetodb = false; //C.DbPath = @"\\dc1\userspace\krause\BoSSS_DBs\Bug"; C.DbPath = @"/home/ws35kire/test_db/"; //string restartSession = "727da287-1b6a-463e-b7c9-7cc19093b5b3"; //string restartGrid = "3f8f3445-46f1-47ed-ac0e-8f0260f64d8f"; C.DynamicLoadBalancing_Period = 1; C.DynamicLoadBalancing_CellCostEstimatorFactories.Add(delegate(IApplication app, int noOfPerformanceClasses) { Console.WriteLine("i was called"); int[] map = new int[] { 1, 5, 100 }; return(new StaticCellCostEstimator(map)); }); // Assign correct names if (pardiso) { if (only_channel) { C.SessionName = "Channel_Pardiso_k" + k + "_" + cells_x + "x" + cells_yz + "x" + cells_yz + "_no_p" + no_p + "_run" + no_it; } else { C.SessionName = "Sphere_Pardiso_k" + k + cells_x + "x" + cells_yz + "x" + cells_yz + "_no_p" + no_p + "_run" + no_it; } } else { if (only_channel) { C.SessionName = "Channel_Mumps_k" + k + cells_x + "x" + cells_yz + "x" + cells_yz + "_no_p" + no_p + "_run" + no_it; } else { C.SessionName = "Sphere_Mumps_k" + k + cells_x + "x" + cells_yz + "x" + cells_yz + "_no_p" + no_p + "_run" + no_it; } } C.saveperiod = 1; //C.SessionName = "Sphere_k" + k + "_h" + h+"Re100"; C.ProjectName = "Sphere3D_Stokes"; C.ProjectDescription = "Sphere_k" + k + cells_x + "x" + cells_yz + "x" + cells_yz; C.Tags.Add("with immersed boundary method"); C.Tags.Add("Pardiso " + pardiso); C.Tags.Add("only channel " + only_channel); C.Tags.Add("k " + k); C.Tags.Add("no_p" + no_p); C.Tags.Add("run " + no_it); C.Tags.Add("cells_x " + cells_x); C.Tags.Add("cells_yz " + cells_yz); C.Tags.Add("restart " + restart); // Create Fields C.FieldOptions.Add("VelocityX", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("VelocityY", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("VelocityZ", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("Pressure", new FieldOpts() { Degree = k - 1, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("PhiDG", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("Phi", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); //if (restart) //{ // C.RestartInfo = new Tuple<Guid, TimestepNumber>(new Guid(restartSession), -1); // C.GridGuid = new Guid(restartGrid); //} // Load Grid if (!restart) { if (load_Grid == true) { Console.WriteLine("...loading grid"); C.GridGuid = new Guid(_GridGuid); } else { #region Creates grid () and sets BC //// Create Grid Console.WriteLine("...generating grid"); C.GridFunc = delegate { // x-direction var _xNodes = GenericBlas.Linspace(-10, 30, cells_x + 1); // y-direction var _yNodes = GenericBlas.Linspace(-10, 10, cells_yz + 1); // z-direction var _zNodes = GenericBlas.Linspace(-10, 10, cells_yz + 1); // Cut Out var grd = Grid3D.Cartesian3DGrid(_xNodes, _yNodes, _zNodes, false, false, false, CellType.Cube_Linear); grd.EdgeTagNames.Add(1, "Velocity_inlet"); grd.EdgeTagNames.Add(2, "Pressure_Outlet"); // grd.EdgeTagNames.Add(3, "Wall"); grd.DefineEdgeTags(delegate(double[] _X) { var X = _X; double x = X[0]; double y = X[1]; double z = X[2]; if (Math.Abs(x - (-10)) < 1.0e-6) { // inlet return(1); } if (Math.Abs(x - (30)) < 1.0e-6) { // outlet return(2); } if (Math.Abs(y - (-10)) < 1.0e-6) { // left return(2); } if (Math.Abs(y - (10)) < 1.0e-6) { // right return(2); } if (Math.Abs(z - (-10)) < 1.0e-6) { // top left return(2); } if (Math.Abs(z - (10)) < 1.0e-6) { // top right return(2); } throw new ArgumentOutOfRangeException(); }); return(grd); }; } #endregion //// Create Grid with HANGING NODES //Console.WriteLine("...generating grid"); //C.GridFunc = delegate { // // Box1 // var box1_p1 = new double[3] { -10, -10, -10 }; // var box1_p2 = new double[3] { 30, 10, 10 }; // var box1 = new GridCommons.GridBox(box1_p1, box1_p2,10,5,5); // // Box2 // var box2_p1 = new double[3] { 0, -5, -5 }; // var box2_p2 = new double[3] { 20, 5, 5 }; // var box2 = new GridCommons.GridBox(box2_p1, box2_p2, 10, 6, 6); // // Cut Out // var grd = Grid3D.HangingNodes3D(false, true, true, box1, box2); // grd.EdgeTagNames.Add(1, "Velocity_inlet"); // grd.EdgeTagNames.Add(2, "Pressure_Outlet"); // grd.EdgeTagNames.Add(3, "Wall"); // grd.DefineEdgeTags(delegate (double[] _X) { // var X = _X; // double x = X[0]; // double y = X[1]; // double z = X[2]; // if (Math.Abs(x - (-10)) < 1.0e-6) // // inlet // return 1; // if (Math.Abs(x - (30)) < 1.0e-6) // // outlet // return 2; // if (Math.Abs(y - (-10)) < 1.0e-6) // // left // return 1; // if (Math.Abs(y - (10)) < 1.0e-6) // // right // return 1; // if (Math.Abs(z - (-10)) < 1.0e-6) // // top left // return 1; // if (Math.Abs(z - (10)) < 1.0e-6) // // top right // return 1; // throw new ArgumentOutOfRangeException(); // }); // Console.WriteLine("Cells: {0}", grd.NumberOfCells); // return grd; //}; #region Creates grid (17710 Cells) and sets BC //// Create Grid //Console.WriteLine("...generating grid"); //C.GridFunc = delegate { // // x-direction // var _xNodes1 = Grid1D.ExponentialSpaceing(-9.5, -3, 11, 0.98); // _xNodes1 = _xNodes1.GetSubVector(0, (_xNodes1.Length - 1)); // var _xNodes2 = Grid1D.ExponentialSpaceing(-3, -1, 9, 0.95); // _xNodes2 = _xNodes2.GetSubVector(0, (_xNodes2.Length - 1)); // var _xNodes3 = Grid1D.ExponentialSpaceing(-1, 0, 8, 1); // _xNodes3 = _xNodes3.GetSubVector(0, (_xNodes3.Length - 1)); // var _xNodes4 = Grid1D.ExponentialSpaceing(0, 2, 9, 1.05); // _xNodes4 = _xNodes4.GetSubVector(0, (_xNodes4.Length - 1)); // var _xNodes5 = Grid1D.ExponentialSpaceing(2, 8.5, 16, 1.02); // _xNodes5 = _xNodes5.GetSubVector(0, (_xNodes5.Length - 1)); // var _xNodes6 = Grid1D.ExponentialSpaceing(8.5, 12.5, 5, 1); // var _xNodes = ArrayTools.Cat(_xNodes1, _xNodes2, _xNodes3, _xNodes4, _xNodes5, _xNodes6); // // y-direction // var _yNodes1 = Grid1D.ExponentialSpaceing(-9, -2.5, 8, 0.91); // _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1)); // var _yNodes2 = Grid1D.ExponentialSpaceing(-2.5, -0.5, 8, 0.95); // _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1)); // var _yNodes3 = Grid1D.ExponentialSpaceing(-0.5, 0.5, 8, 1.0); // _yNodes3 = _yNodes3.GetSubVector(0, (_yNodes3.Length - 1)); // var _yNodes4 = Grid1D.ExponentialSpaceing(0.5, 2.5, 8, 1.05); // _yNodes4 = _yNodes4.GetSubVector(0, (_yNodes4.Length - 1)); // var _yNodes5 = Grid1D.ExponentialSpaceing(2.5, 9, 8, 1.1); // var _yNodes = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3, _yNodes4, _yNodes5); // // z-direction // var _zNodes = GenericBlas.Linspace(-3, 3, 11); // // Cut Out // double[] CutOutPoint1 = new double[3]; // CutOutPoint1[0] = -1; // CutOutPoint1[1] = -0.5; // CutOutPoint1[2] = -3; // double[] CutOutPoint2 = new double[3]; // CutOutPoint2[0] = 0; // CutOutPoint2[1] = 0.5; // CutOutPoint2[2] = 3; // var CutOut = new BoundingBox(3); // CutOut.AddPoint(CutOutPoint1); // CutOut.AddPoint(CutOutPoint2); // var grd = Grid3D.Cartesian3DGrid(_xNodes, _yNodes, _zNodes, false, false, true, CellType.Cube_Linear, CutOut); // grd.EdgeTagNames.Add(1, "Velocity_inlet"); // grd.EdgeTagNames.Add(2, "Pressure_Outlet"); // grd.EdgeTagNames.Add(3, "Wall"); // grd.DefineEdgeTags(delegate(double[] _X) { // var X = _X; // double x = X[0]; // double y = X[1]; // double z = X[2]; // if (Math.Abs(x - (-9.5)) < 1.0e-6) // // inlet // return 1; // if (Math.Abs(x - (12.5)) < 1.0e-6) // // outlet // return 2; // if (Math.Abs(z - (-3)) < 1.0e-6) // // left // return 2; // if (Math.Abs(z - (3)) < 1.0e-6) // // right // return 2; // if (Math.Abs(x - (-1)) < 1.0e-6) // // Cube front // return 3; // if (Math.Abs(x - (0)) < 1.0e-6) // // cube back // return 3; // if (Math.Abs(y - (-0.5)) < 1.0e-6) // // cube left // return 3; // if (Math.Abs(y - (0.5)) < 1.0e-6) // // cube right // return 3; // throw new ArgumentOutOfRangeException(); // }); // return grd; //}; #endregion // Set Initial Conditions C.InitialValues_Evaluators.Add("VelocityX", X => 0.5); C.InitialValues_Evaluators.Add("VelocityY", X => 0); C.InitialValues_Evaluators.Add("VelocityZ", X => 0.5); C.InitialValues_Evaluators.Add("Pressure", X => 0); if (only_channel) { C.InitialValues_Evaluators.Add("Phi", X => - 1); } else { C.InitialValues_Evaluators.Add("Phi", X => - (X[0]).Pow2() + -(X[1]).Pow2() + -(X[2]).Pow2() + C.particleRadius.Pow2()); } } Console.WriteLine("...starting calculation of Sphere3D"); // Initial Solution // Physical values C.particleRadius = 2.5; C.PhysicalParameters.rho_A = 1; C.PhysicalParameters.mu_A = 2.5 * 2 / 100; // Boundary conditions C.AddBoundaryValue("Velocity_inlet", "VelocityX", (X, t) => 1); C.AddBoundaryValue("Velocity_inlet", "VelocityY", (X, t) => 0); //C.AddBoundaryCondition("Velocity_inlet", "VelocityZ", (X, t) => 0); // C.AddBoundaryCondition("Wall"); C.AddBoundaryValue("Pressure_Outlet"); // misc. solver options // ==================== C.PhysicalParameters.IncludeConvection = true; C.AdvancedDiscretizationOptions.PenaltySafety = 4; C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2; C.LevelSetSmoothing = false; C.MaxKrylovDim = 20; C.MaxSolverIterations = 50; C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite; // Timestepping // ============ if (pardiso) { C.LinearSolve = LinearSolverCodes.classic_pardiso; } else { C.LinearSolve = LinearSolverCodes.classic_mumps; } //C.whichSolver = DirectSolver._whichSolver.MUMPS; C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.BDF2; double dt = 0.1; C.dtFixed = dt; C.dtMax = dt; C.dtMin = dt; C.Endtime = 10000000; //C.NoOfTimesteps = 10; C.NoOfTimesteps = 1; C.NoOfMultigridLevels = 3; return(C); }
static public IBM_Control PrecTest3dDegenhardt(int precNo = 4, int channel = 1, int name_newton = 1, int k = 3, int cells_x = 4, int cells_yz = 5, int re = 100, int ASparts = 3, int ASDepth = 2, int MGLevels = 3, int maxKrDim = 1000, int saveToDB = 1) { IBM_Control C = new IBM_Control(); //in SolverChooser die DoF parts ändern //Possibilities: //channel = 0 --> channel 3D with sphere //channel = 1 --> channel 3D empty //channel = 2 --> channel 2D with cylinder //channel = 3 --> channel 2D empty string sessName = ""; if (channel == 0) { sessName = "Channel_3D_Sphere"; } else if (channel == 1) { sessName = "Channel_3D_empty"; } else if (channel == 2) { sessName = "Channel_2D_Cylinder"; } else if (channel == 3) { sessName = "Channel_2D_empty"; } string precString = ""; if (precNo == 0) { precString = "_noPrec"; } if (precNo == 1) { precString = "_Schur"; } if (precNo == 2) { precString = "_Simple"; } if (precNo == 3) { precString = "_AS-1000"; } if (precNo == 4) { precString = "_AS-5000"; } if (precNo == 5) { precString = "_AS-10000"; } if (precNo == 6) { precString = "_AS-MG"; } if (precNo == 7) { precString = "_localPrec"; } // basic database options // ====================== // if (saveToDB == 1) // C.savetodb = true; //else //C.savetodb = false; C.savetodb = true; C.DbPath = @" \\dc1\scratch\Krause\Datenbank_Louis\degenhardt_final"; //C.DbPath = @"\\hpccluster\hpccluster-scratch\krause\cluster_db"; //C.DbPath = @"/home/oe11okuz/BoSSS_DB/Lichtenberg_DB"; //string restartSession = "727da287-1b6a-463e-b7c9-7cc19093b5b3"; //string restartGrid = "3f8f3445-46f1-47ed-ac0e-8f0260f64d8f"; C.DynamicLoadBalancing_Period = 1; //C.DynamicLoadBalancing_CellCostEstimatorFactory = delegate (IApplication<AppControl> app, int noOfPerformanceClasses) { // Console.WriteLine("i was called"); // int[] map = new int[] { 1, 5, 100 }; // return new StaticCellCostEstimator(map); //}; if (name_newton == 1) { C.SessionName = "Newton_" + sessName + precString + "_k" + k + "_x" + cells_x + "_yz" + cells_yz + "_re" + re + "_asp" + ASparts + "_asd" + ASDepth + "_mgl" + MGLevels + "_kr" + maxKrDim; C.ProjectDescription = "Newton_" + sessName + precString + "_k" + k + "_x" + cells_x + "_yz" + cells_yz + "_re" + re + "_asp" + ASparts + "_asd" + ASDepth + "_mgl" + MGLevels + "_kr" + maxKrDim; } else { C.SessionName = "Picard_" + sessName + precString + "_k" + k + "_x" + cells_x + "_yz" + cells_yz + "_re" + re + "_asp" + ASparts + "_asd" + ASDepth + "_mgl" + MGLevels + "_kr" + maxKrDim; C.ProjectDescription = "Picard_" + sessName + precString + "_k" + k + "_x" + cells_x + "_yz" + cells_yz + "_re" + re + "_asp" + ASparts + "_asd" + ASDepth + "_mgl" + MGLevels + "_kr" + maxKrDim; } C.saveperiod = 1; //C.SessionName = "Sphere_k" + k + "_h" + h+"Re100"; C.ProjectName = "iteration-study"; C.Tags.Add("Prec param study"); // Create Fields C.FieldOptions.Add("VelocityX", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("VelocityY", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("Pressure", new FieldOpts() { Degree = k - 1, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("PhiDG", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("Phi", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); if (channel == 0 || channel == 1) //3D { C.FieldOptions.Add("VelocityZ", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); } #region Creates grid () and sets BC //// Create Grid Console.WriteLine("...generating grid"); if (channel == 0 || channel == 1) //3D { #region grid 3D C.GridFunc = delegate { // x-direction var _xNodes = GenericBlas.Linspace(-0.5, 1.5, cells_x + 1); // y-direction var _yNodes = GenericBlas.Linspace(-0.5, 0.5, cells_yz + 1); // z-direction var _zNodes = GenericBlas.Linspace(-0.5, 0.5, cells_yz + 1); // Cut Out var grd = Grid3D.Cartesian3DGrid(_xNodes, _yNodes, _zNodes, false, true, false, CellType.Cube_Linear); grd.EdgeTagNames.Add(1, "Velocity_inlet"); grd.EdgeTagNames.Add(2, "Wall"); grd.EdgeTagNames.Add(3, "Pressure_Outlet"); grd.DefineEdgeTags(delegate(double[] _X) { var X = _X; double x = X[0]; double y = X[1]; double z = X[2]; if (Math.Abs(x - (-0.5)) < 1.0e-6) { // inlet return(1); } if (Math.Abs(x - (1.5)) < 1.0e-6) { // outlet return(3); } if (Math.Abs(y - (-0.5)) < 1.0e-6) { // left return(2); } if (Math.Abs(y - (0.5)) < 1.0e-6) { // right return(2); } if (Math.Abs(z - (-0.5)) < 1.0e-6) { // top left return(2); } if (Math.Abs(z - (0.5)) < 1.0e-6) { // top right return(2); } throw new ArgumentOutOfRangeException(); }); return(grd); }; #endregion } else { #region grid 2D C.GridFunc = delegate { // x-direction var _xnodes = GenericBlas.Linspace(-0.5, 1.5, cells_x + 1); // y-direction var _ynodes = GenericBlas.Linspace(-0.5, 0.5, cells_yz + 1); var grd = Grid2D.Cartesian2DGrid(_xnodes, _ynodes, CellType.Square_Linear, false, false); grd.EdgeTagNames.Add(1, "Velocity_inlet"); grd.EdgeTagNames.Add(2, "Wall"); grd.EdgeTagNames.Add(3, "Pressure_Outlet"); grd.DefineEdgeTags(delegate(double[] _X) { var X = _X; double x = X[0]; double y = X[1]; if (Math.Abs(x - (-0.5)) < 1.0e-6) { // inlet return(1); } if (Math.Abs(x - (1.5)) < 1.0e-6) { // outlet return(3); } if (Math.Abs(y - (-0.5)) < 1.0e-6) { // left return(2); } if (Math.Abs(y - (0.5)) < 1.0e-6) { // right return(2); } throw new ArgumentOutOfRangeException(); }); return(grd); }; #endregion } #endregion // set initial conditions C.InitialValues_Evaluators.Add("Pressure", X => 0); C.InitialValues_Evaluators.Add("VelocityY", X => 0); if (channel == 0 | channel == 1) //3D { //C.InitialValues_Evaluators.Add("VelocityX", X => 1 - 4 * (X[2] * X[2])); C.InitialValues_Evaluators.Add("VelocityX", X => 0); C.InitialValues_Evaluators.Add("VelocityZ", X => 0); } else { //C.InitialValues_Evaluators.Add("VelocityX", X => 1 - 4 * (X[1] * X[1])); C.InitialValues_Evaluators.Add("VelocityX", X => 0); } // Because its a sphere if (channel == 0) //3D channel sphere { C.particleRadius = 0.1; C.InitialValues_Evaluators.Add("Phi", x => - (x[0]).Pow2() + -(x[1]).Pow2() + -(x[2]).Pow2() + C.particleRadius.Pow2()); } else if (channel == 1 || channel == 3) //3D channel empty or 2D channel empty { C.InitialValues_Evaluators.Add("Phi", x => - 1); } else if (channel == 2) //2D channel cylinder { var radius = 0.1; C.particleRadius = radius; C.InitialValues_Evaluators.Add("Phi", X => - (X[0]).Pow2() + -(X[1]).Pow2() + radius.Pow2()); } Console.WriteLine("...starting calculation of Preconditioning test with 3D Channel"); if (name_newton == 1) { Console.WriteLine("newton_" + sessName + precString + "_k" + k + "_x" + cells_x + "_yz" + cells_yz + "_re" + re + "_asp" + ASparts + "_asd" + ASDepth + "_mgl" + MGLevels + "_kr" + maxKrDim); } else { Console.WriteLine("picard_" + sessName + precString + "_k" + k + "_x" + cells_x + "_yz" + cells_yz + "_re" + re + "_asp" + ASparts + "_asd" + ASDepth + "_mgl" + MGLevels + "_kr" + maxKrDim); } // Physical values C.PhysicalParameters.rho_A = 1; // 1/Re //C.PhysicalParameters.mu_A = 1.0 / 10.0; //C.PhysicalParameters.mu_A = 0.2 / re; C.PhysicalParameters.mu_A = 1.0 / re; // Boundary conditions C.AddBoundaryValue("Velocity_inlet", "VelocityY", (x, t) => 0); C.AddBoundaryValue("Wall"); C.AddBoundaryValue("Pressure_Outlet"); if (channel == 0 || channel == 1) //3D { C.AddBoundaryValue("Velocity_inlet", "VelocityX", (x, t) => 1 - 4 * (x[2] * x[2])); } else { C.AddBoundaryValue("Velocity_inlet", "VelocityX", (x, t) => 1 - 4 * (x[1] * x[1])); } // misc. solver options // ==================== C.PhysicalParameters.IncludeConvection = true; C.AdvancedDiscretizationOptions.PenaltySafety = 4; C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2; C.LevelSetSmoothing = false; //C.MaxKrylovDim = 1000; C.MaxKrylovDim = maxKrDim; C.MaxSolverIterations = 100; //C.MaxSolverIterations = 1; C.MinSolverIterations = 1; // C.MaxSolverIterations = 10000; C.Solver_ConvergenceCriterion = 1E-5; //C.Solver_ConvergenceCriterion = 1E-6; C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite; // Choosing the Preconditioner ISolverSmootherTemplate Prec; if (name_newton == 1) { C.NonlinearSolve = NonlinearSolverCodes.NewtonGMRES; } else { C.NonlinearSolve = NonlinearSolverCodes.PicardGMRES; } switch (precNo) { case 0: { Prec = null; break; } case 1: { C.LinearSolve = LinearSolverCodes.exp_Schur; break; } case 2: { C.LinearSolve = LinearSolverCodes.exp_Simple; break; } case 3: { C.LinearSolve = LinearSolverCodes.exp_AS_1000; C.NoOfMultigridLevels = MGLevels; // 3 // --> grobes MG am Ende nochmal break; } case 4: { C.LinearSolve = LinearSolverCodes.exp_AS_5000; C.NoOfMultigridLevels = MGLevels; break; } case 5: { C.LinearSolve = LinearSolverCodes.exp_AS_10000; C.NoOfMultigridLevels = MGLevels; break; } case 6: { //depth = 2, // Depth = ASDepth, //--> MG bei der Blockzerlegung --> Resultat ergibt die Blöcke zur Berechnung (kleine Blöcke--> schlecht) C.LinearSolve = LinearSolverCodes.exp_AS_MG; C.NoOfMultigridLevels = MGLevels; break; } case 7: { C.LinearSolve = LinearSolverCodes.exp_localPrec;; C.NoOfMultigridLevels = MGLevels; break; } case 8: { C.NoOfMultigridLevels = 5; Prec = new Schwarz() { m_BlockingStrategy = new Schwarz.METISBlockingStrategy() { //noofparts = 5, NoOfPartsPerProcess = ASparts, }, CoarseSolver = new ClassicMultigrid() { CoarserLevelSolver = new ClassicMultigrid() { CoarserLevelSolver = new ClassicMultigrid() { CoarserLevelSolver = new DirectSolver() { WhichSolver = DirectSolver._whichSolver.MUMPS }, }, }, }, Overlap = 1 }; break; } default: { Prec = new SchurPrecond() { SchurOpt = SchurPrecond.SchurOptions.decoupledApprox }; break; } } // For Newton // C.LinearSolver = Prec; ////For Picard //C.LinearSolver = new SoftGMRES() //{ // MaxKrylovDim = C.MaxKrylovDim, // Precond = Prec, // m_Tolerance = 1E-6, // m_MaxIterations = 50 //}; // Timestepping // ============ C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.BDF2; double dt = 1E20; C.dtFixed = dt; C.dtMax = dt; C.dtMin = dt; C.Endtime = 10000000; C.NoOfTimesteps = 1; return(C); }
/// <summary> /// This is a testrun similar to the one in \public\doc\handbook\apdx-NodeSolverPerformance\XDGPoisson\Part1-Calculations.bws /// phase A: 3D sphere, pahse B: [-1,1]^3\sphere /// </summary> /// <param name="myDB"></param> /// <returns></returns> public static XdgPoisson3Control TestOrTreat(int solver = 1, int blocksize = 10000, string myDB = null) { XdgPoisson3Control C = new XdgPoisson3Control(); switch (solver) { case 0: C.LinearSolver.SolverCode = LinearSolverCode.classic_pardiso; break; case 1: C.LinearSolver.SolverCode = LinearSolverCode.exp_Kcycle_schwarz; break; case 3: C.LinearSolver.SolverCode = LinearSolverCode.exp_gmres_levelpmg; break; case 4: C.LinearSolver.SolverCode = LinearSolverCode.exp_OrthoS_pMG; break; default: throw new NotImplementedException("guess again"); } C.savetodb = false; //C.DbPath = @"D:\trash_db"; int Res = 8; C.GridFunc = delegate() { double[] xNodes = GenericBlas.Linspace(-1, +1, Res + 1); double[] yNodes = GenericBlas.Linspace(-1, +1, Res + 1); double[] zNodes = GenericBlas.Linspace(-1, +1, Res + 1); int J = (xNodes.Length - 1) * (yNodes.Length - 1) * (zNodes.Length - 1); var grid = Grid3D.Cartesian3DGrid(xNodes, yNodes, zNodes); grid.Name = "thisisatestgrid"; grid.EdgeTagNames.Add(1, "Dirichlet"); grid.DefineEdgeTags(delegate(double[] X) { return(1); }); return(grid); }; C.SessionName = String.Format("XDGPoison_solver{0}_blsz{1}_Xdg2lowB", solver, blocksize); C.ProjectName = "PoisonTest"; C.GridPartType = GridPartType.Hilbert; C.LinearSolver.TargetBlockSize = blocksize / 2; C.SetDGdegree(2); C.LinearSolver.NoOfMultigridLevels = 2; C.LinearSolver.ConvergenceCriterion = 1e-8; C.LinearSolver.MaxSolverIterations = 1000; C.LinearSolver.MaxKrylovDim = 50; //C.LinearSolver.TargetBlockSize = 79; C.ExcactSolSupported = false; double radius = 0.7; C.InitialValues_Evaluators.Add("Phi", X => X[0].Pow2() + X[1].Pow2() + X[2].Pow2() - radius.Pow2()); C.MU_A = -1; C.MU_B = -1000; C.InitialValues_Evaluators.Add("rhs#A", X => 1.0); C.InitialValues_Evaluators.Add("rhs#B", X => 1.0); C.InitialValues_Evaluators.Add("u#A", X => 0); C.InitialValues_Evaluators.Add("u#B", X => 0); //C.CutCellQuadratureType = XQuadFactoryHelper.MomentFittingVariants.Classic; C.CutCellQuadratureType = XQuadFactoryHelper.MomentFittingVariants.Saye; C.SetDefaultDiriBndCnd = true; //which means ... //C.xLaplaceBCs.g_Diri = ((CommonParamsBnd inp) => 0.0); //C.xLaplaceBCs.IsDirichlet = (inp => true); // ... but stuff is not serializable, therefore this workaround. C.ViscosityMode = XLaplace_Interface.Mode.SIP; C.AgglomerationThreshold = 0.1; return(C); }
/// <summary> /// Test on a Cartesian grid, with a sinusodial solution. /// </summary> /// <param name="Res"> /// Grid resolution /// </param> /// <param name="Dim"> /// spatial dimension /// </param> /// <param name="deg"> /// polynomial degree /// </param> /// <param name="solver_name"> /// Name of solver to use. /// </param> public static SipControl TestCartesian2(int Res, int Dim, LinearSolverCode solver_name = LinearSolverCode.exp_Kcycle_schwarz, int deg = 5) { //BoSSS.Application.SipPoisson.SipHardcodedControl.TestCartesian2(8,3,deg:2) if (Dim != 2 && Dim != 3) { throw new ArgumentOutOfRangeException(); } var R = new SipControl(); R.ProjectName = "ipPoison/cartesian"; R.savetodb = false; R.FieldOptions.Add("T", new FieldOpts() { Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = deg + 2 }); R.InitialValues_Evaluators.Add("RHS", X => - Math.Sin(X[0])); R.InitialValues_Evaluators.Add("Tex", X => Math.Sin(X[0])); R.ExactSolution_provided = true; R.LinearSolver.NoOfMultigridLevels = int.MaxValue; R.LinearSolver.SolverCode = solver_name; // exp_Kcycle_schwarz // exp_gmres_levelpmg #if DEBUG // For testing in DEBUG mode, this setting enforces the use // of many multigrid-levels. In 2D, the examples are so small that R.LinearSolver.TargetBlockSize = 100; #endif R.GridFunc = delegate() { GridCommons grd = null; if (Dim == 2) { double[] xNodes = GenericBlas.Linspace(0, 10, Res * 5 + 1); double[] yNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1); grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); } else if (Dim == 3) { double[] xNodes = GenericBlas.Linspace(0, 10, Res * 5 + 1); //double[] yNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1); //double[] zNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1); double[] yNodes = GenericBlas.Linspace(-1, +1, Res + 1); double[] zNodes = GenericBlas.Linspace(-1, +1, Res + 1); grd = Grid3D.Cartesian3DGrid(xNodes, yNodes, zNodes); } else { throw new NotSupportedException(); } grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.EdgeTagNames.Add(2, BoundaryType.Neumann.ToString()); grd.DefineEdgeTags(delegate(double[] X) { byte ret; double x = X[0]; if (Math.Abs(x - 0.0) <= 1.0e-8) { ret = 1; // Dirichlet } else { ret = 2; // Neumann } return(ret); }); return(grd); }; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", delegate(double[] X) { double x = X[0], y = X[1]; return(Math.Sin(x)); //if (Math.Abs(X[0] - (0.0)) < 1.0e-8) // return 0.0; //throw new ArgumentOutOfRangeException(); }); R.AddBoundaryValue(BoundaryType.Neumann.ToString(), "T", delegate(double[] X) { double x = X[0], y = X[1], z = X.Length > 2 ? X[2] : 0.0; if (Math.Abs(y - 1.0) < 1.0e-8 || Math.Abs(y + 1.0) < 1.0e-8) // y = -1, y = +1 { return(0); } if (X.Length > 2 && (Math.Abs(z - 1.0) < 1.0e-8 || Math.Abs(z + 1.0) < 1.0e-8)) // z = -1, z = +1 { return(0); } //if (Math.Abs(X[0] - (+10.0)) < 1.0e-8) return(Math.Cos(x)); //throw new ArgumentOutOfRangeException(); }); return(R); }
/// <summary> /// Test on a Cartesian grid, with a sinusodial solution. /// </summary> /// <param name="Res"> /// Grid resolution, 2 entries for 2D test, 3 entries for 3D test. /// </param> /// <param name="Stretch"> /// Grid stretching factors. /// </param> /// <param name="solver_name"> /// Name of solver to use. /// </param> public static ippControl TestCartesian2(int[] Res, double[] Stretch = null, string solver_name = "direct", int deg = 3) { if (Res.Length != 2 && Res.Length != 3) { throw new ArgumentOutOfRangeException(); } if (Stretch == null) { Stretch = new double[Res.Length]; Stretch.SetAll(1.0); } else { if (Res.Length != Stretch.Length) { throw new ArgumentException(); } } var R = new ippControl(); R.ProjectName = "ipPoison/cartesian"; R.savetodb = false; R.FieldOptions.Add("T", new FieldOpts() { Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = deg }); R.InitialValues_Evaluators.Add("RHS", X => - Math.Sin(X[0])); R.InitialValues_Evaluators.Add("Tex", X => Math.Sin(X[0])); R.ExactSolution_provided = true; R.GridFunc = delegate() { if (Res.Length == 2) { double[] xNodes = CreateNodes(Res[0], Stretch[0], 0, 10); double[] yNodes = CreateNodes(Res[1], Stretch[1], -1, +1); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); return(grd); } else if (Res.Length == 3) { double[] xNodes = CreateNodes(Res[0], Stretch[0], 0, 10); double[] yNodes = CreateNodes(Res[1], Stretch[1], -1, +1); double[] zNodes = CreateNodes(Res[2], Stretch[2], -1, +1); var grd = Grid3D.Cartesian3DGrid(xNodes, yNodes, zNodes); return(grd); } else { throw new NotSupportedException(); } }; R.IsDirichlet = delegate(CommonParamsBnd inp) { return(Math.Abs(inp.X[0] - 0.0) <= 1.0e-6); }; R.g_Diri = delegate(CommonParamsBnd inp) { return(0.0); }; R.g_Neum = delegate(CommonParamsBnd inp) { if (Math.Abs(inp.X[1] - 1.0) < 1.0e-8 || Math.Abs(inp.X[1] + 1.0) < 1.0e-8) { return(0); } if (inp.X.Length > 2 && (Math.Abs(inp.X[2] - 1.0) < 1.0e-8 || Math.Abs(inp.X[2] + 1.0) < 1.0e-8)) { return(0); } return(Math.Cos(10.0)); }; R.solver_name = solver_name; return(R); }
/// <summary> /// Test on a Cartesian grid, with a sinusodial solution. /// </summary> /// <param name="Res"> /// Grid resolution /// </param> /// <param name="Dim"> /// spatial dimension /// </param> /// <param name="deg"> /// polynomial degree /// </param> /// <param name="solver_name"> /// Name of solver to use. /// </param> public static SipControl TestCartesian2(int Res, int Dim, SolverCodes solver_name = SolverCodes.exp_softpcg_mg, int deg = 3) { if (Dim != 2 && Dim != 3) { throw new ArgumentOutOfRangeException(); } var R = new SipControl(); R.ProjectName = "ipPoison/cartesian"; R.savetodb = false; R.FieldOptions.Add("T", new FieldOpts() { Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = deg * 2 }); R.InitialValues_Evaluators.Add("RHS", X => - Math.Sin(X[0])); R.InitialValues_Evaluators.Add("Tex", X => Math.Sin(X[0])); R.ExactSolution_provided = true; R.NoOfMultigridLevels = int.MaxValue; R.solver_name = solver_name; //R.TargetBlockSize = 100; R.GridFunc = delegate() { GridCommons grd = null; if (Dim == 2) { double[] xNodes = GenericBlas.Linspace(0, 10, Res * 5 + 1); double[] yNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1); grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); } else if (Dim == 3) { double[] xNodes = GenericBlas.Linspace(0, 10, Res * 5 + 1); double[] yNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1); double[] zNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1); grd = Grid3D.Cartesian3DGrid(xNodes, yNodes, zNodes); } else { throw new NotSupportedException(); } grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.EdgeTagNames.Add(2, BoundaryType.Neumann.ToString()); grd.DefineEdgeTags(delegate(double[] X) { byte ret; if (Math.Abs(X[0] - 0.0) <= 1.0e-6) { ret = 1; } else { ret = 2; } return(ret); }); return(grd); }; R.AddBoundaryCondition(BoundaryType.Dirichlet.ToString(), "T", delegate(double[] X) { double x = X[0], y = X[1]; if (Math.Abs(X[0] - (0.0)) < 1.0e-8) { return(0.0); } throw new ArgumentOutOfRangeException(); }); R.AddBoundaryCondition(BoundaryType.Neumann.ToString(), "T", delegate(double[] X) { if (Math.Abs(X[1] - 1.0) < 1.0e-8 || Math.Abs(X[1] + 1.0) < 1.0e-8) // y = -1, y = +1 { return(0); } if (X.Length > 2 && (Math.Abs(X[2] - 1.0) < 1.0e-8 || Math.Abs(X[2] + 1.0) < 1.0e-8)) // z = -1, z = +1 { return(0); } if (Math.Abs(X[0] - (+10.0)) < 1.0e-8) { return(Math.Cos(10.0)); } throw new ArgumentOutOfRangeException(); }); return(R); }