Ejemplo n.º 1
0
        /// <summary>
        /// Automatic choice of linear solver depending on problem size, immersed boundary, polynomial degree, etc.
        /// </summary>
        static void AutomaticChoice(IBM_Control Control, XdgBDFTimestepping Timestepper)
        {
            throw new NotImplementedException("Option currently not available");

            // Detecting MPI Size
            MPI.Wrappers.csMPI.Raw.Comm_Size(MPI.Wrappers.csMPI.Raw._COMM.WORLD, out int size);
            //Timestepper.MultigridSequence[0].

            // Spatial Dimension

            //Timestepper.

            // Wenn Gesamtproblem in 2D < 100000 DoFs -> Direct Solver
            // Wenn Gesamtproblem in 3D < 10000 DoFs -> Direct Solver

            // Block Solve 3D ca. 6000 DoFs per Process -> Adjust Blocks per Process
            // Coarse Solve ca. 5000 bis 10000 DoFs. -> Adjust Multigrid Levels
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Choose solver depending on configurations made in the control file.
        /// </summary>
        /// <param name="nonlinSol"></param>
        /// <param name="linSol"></param>
        /// <param name="Timestepper"></param>
        public static void ChooseSolver(IBM_Control Control, ref XdgBDFTimestepping Timestepper)
        {
            // Set several solver options for Timestepper
            Timestepper.Config_SolverConvergenceCriterion = Control.Solver_ConvergenceCriterion;
            Timestepper.Config_MaxIterations = Control.MaxSolverIterations;
            Timestepper.Config_MinIterations = Control.MinSolverIterations;
            Timestepper.Config_MaxKrylovDim  = Control.MaxKrylovDim;

            // Set nonlinear Solver
            switch (Control.NonlinearSolve)
            {
            case NonlinearSolverCodes.NewtonGMRES:
                Timestepper.Config_NonlinearSolver = NonlinearSolverMethod.Newton;
                break;

            case NonlinearSolverCodes.Picard:
                Timestepper.Config_NonlinearSolver = NonlinearSolverMethod.Picard;
                break;

            default:
                throw new NotImplementedException("Nonlinear solver option not available");
            }


            switch (Control.LinearSolve)
            {
            case LinearSolverCodes.automatic:
                AutomaticChoice(Control, Timestepper);
                break;

            case LinearSolverCodes.classic_mumps:
                Timestepper.Config_linearSolver = new DirectSolver()
                {
                    WhichSolver = DirectSolver._whichSolver.MUMPS
                };
                break;

            case LinearSolverCodes.classic_pardiso:
                Timestepper.Config_linearSolver = new DirectSolver()
                {
                    WhichSolver = DirectSolver._whichSolver.PARDISO
                };
                break;

            case LinearSolverCodes.exp_schwarz_directcoarse_overlap:

                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }

                Timestepper.Config_linearSolver = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                    {
                        NoOfPartsPerProcess = 1,
                    },
                    Overlap      = 1,
                    CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                };
                break;

            case LinearSolverCodes.exp_schwarz_directcoarse:

                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }

                Timestepper.Config_linearSolver = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                    {
                        NoOfPartsPerProcess = 1,
                    },
                    Overlap      = 0,
                    CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                };
                break;

            case LinearSolverCodes.exp_schwarz_Kcycle_directcoarse:

                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }

                Timestepper.Config_linearSolver = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.MultigridBlocks()
                    {
                        Depth = Control.NoOfMultigridLevels - 1
                    },
                    Overlap      = 0,
                    CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                };
                break;

            case LinearSolverCodes.exp_schwarz_Kcycle_directcoarse_overlap:

                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }

                Timestepper.Config_linearSolver = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.MultigridBlocks()
                    {
                        Depth = Control.NoOfMultigridLevels - 1
                    },
                    Overlap      = 1,
                    CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                };
                break;

            case LinearSolverCodes.exp_softgmres:
                Timestepper.Config_linearSolver = new SoftGMRES()
                {
                    MaxKrylovDim = Timestepper.Config_MaxKrylovDim,
                };
                break;

            case LinearSolverCodes.exp_softgmres_schwarz_Kcycle_directcoarse_overlap:
                Timestepper.Config_linearSolver = new SoftGMRES()
                {
                    MaxKrylovDim = Timestepper.Config_MaxKrylovDim,
                    Precond      = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.MultigridBlocks()
                        {
                            Depth = Control.NoOfMultigridLevels - 1
                        },
                        Overlap      = 1,
                        CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                    },
                };
                break;

            default:
                throw new NotImplementedException("Linear solver option not available");
            }
        }
Ejemplo n.º 3
0
        static public IBM_Control ChannelFlow(int k = 2, bool periodic = false, bool pardiso = true, int xCells = 10, int yCells = 10)
        {
            IBM_Control C = new IBM_Control();

            // Solver Options
            C.NoOfTimesteps       = 100;
            C.MaxSolverIterations = 50;
            C.savetodb            = false;
            C.ProjectName         = "ChannelFlow";

            // Calculate Navier-Stokes?
            C.PhysicalParameters.IncludeConvection = true;

            // Timestepper
            C.FixedStreamwisePeriodicBC = periodic;
            C.SrcPressureGrad           = new double[] { -0.1, 0 };

            if (pardiso)
            {
                C.whichSolver = DirectSolver._whichSolver.PARDISO;
            }
            else
            {
                C.whichSolver = DirectSolver._whichSolver.MUMPS;
            }
            C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.ImplicitEuler;
            double dt = 1E20;

            C.dtMax         = dt;
            C.dtMin         = dt;
            C.Endtime       = 60;
            C.NoOfTimesteps = 1;

            // Physical values
            C.PhysicalParameters.rho_A = 1;

            // 1/Re
            C.PhysicalParameters.mu_A = 1.0 / 20;


            // 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
            });

            // Create Grid
            C.GridFunc = delegate {
                var _xNodes = GenericBlas.Linspace(0, 10, 21);
                var _yNodes = GenericBlas.Linspace(-1, 1, 11);

                var grd = Grid2D.Cartesian2DGrid(_xNodes, _yNodes, Foundation.Grid.RefElements.CellType.Square_Linear, periodicX: periodic);

                if (!periodic)
                {
                    grd.EdgeTagNames.Add(1, "Velocity_inlet");
                    grd.EdgeTagNames.Add(4, "Pressure_Outlet");
                }

                grd.EdgeTagNames.Add(2, "Wall_bottom");
                grd.EdgeTagNames.Add(3, "Wall_top");

                grd.DefineEdgeTags(delegate(double[] _X) {
                    var X    = _X;
                    double x = X[0];
                    double y = X[1];

                    if (Math.Abs(y - (-1)) < 1.0e-6)
                    {
                        // bottom
                        return(2);
                    }

                    if (Math.Abs(y - (+1)) < 1.0e-6)
                    {
                        // top
                        return(3);
                    }

                    if (!periodic)
                    {
                        if (Math.Abs(x - (0)) < 1.0e-6)
                        {
                            // left
                            return(1);
                        }

                        if (Math.Abs(x - (10)) < 1.0e-6)
                        {
                            // right
                            return(4);
                        }
                    }
                    throw new ArgumentOutOfRangeException();
                });

                Console.WriteLine("2D Channel Flow");

                return(grd);
            };


            Func <double[], double, double> VelocityX = (X, t) => (1 - (X[1] * X[1]));
            Func <double[], double, double> VelocityY = (X, t) => 0;
            Func <double[], double, double> Pressure  = (X, t) => 0;


            C.ExSol_Velocity_Evaluator = new Func <double[], double, double>[] { VelocityX, VelocityY };

            //Func<double[], double, double> Velocity = new  Func<double[], double, double>;
            //C.ExSol_Velocity[0] = (X, t) => (1 - (X[1] * X[1]));
            //C.ExSol_Velocity["A"][1] = (X, t) => (1 - (X[1] * X[1]));
            //C.ExSol_Pressure["A"] = (X, t) => 0;

            if (!periodic)
            {
                C.AddBoundaryCondition("Velocity_inlet", "VelocityX", X => 1 - X[1] * X[1]);
                C.AddBoundaryCondition("Pressure_Outlet");
            }

            C.AddBoundaryCondition("Wall_bottom");
            C.AddBoundaryCondition("Wall_top");

            // Set Initial Conditions
            C.InitialValues_Evaluators.Add("VelocityX", X => 0);
            C.InitialValues_Evaluators.Add("VelocityY", X => 0);
            C.InitialValues_Evaluators.Add("Phi", X => - 1);

            return(C);
        }
Ejemplo n.º 4
0
        public static IBM_Control IBMCylinderFlow(string _DbPath = null, int k = 2, bool xPeriodic = false, double VelXBase = 0.0)
        {
            IBM_Control C = new IBM_Control();

            const double BaseSize = 1.0;

            // basic database options
            // ====================

            C.savetodb           = false;
            C.ProjectDescription = "Cylinder";
            C.Tags.Add("with immersed boundary method");

            // DG degrees
            // ==========

            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
            });

            // grid and boundary conditions
            // ============================

            C.GridFunc = delegate {
                var _xNodes1 = Grid1D.TanhSpacing(0, 1, 5, 1, false);
                _xNodes1 = _xNodes1.GetSubVector(0, (_xNodes1.Length - 1));
                var _xNodes2 = GenericBlas.Linspace(1, 5.5, 35);
                _xNodes2 = _xNodes2.GetSubVector(0, (_xNodes2.Length - 1));
                var _xNodes3 = Grid1D.TanhSpacing(5.5, 22, 20, 1.3, true);

                var xNodes = ArrayTools.Cat(_xNodes1, _xNodes2, _xNodes3);


                var _yNodes1 = Grid1D.TanhSpacing(0, 1, 5, 1.2, false);
                _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
                var _yNodes2 = GenericBlas.Linspace(1, 3, 20);
                _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1));
                var _yNodes3 = Grid1D.TanhSpacing(3, 4.1, 5, 1.2, true);

                var yNodes = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3);

                var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: xPeriodic);
                grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
                grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
                if (!xPeriodic)
                {
                    grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
                    grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
                }

                grd.DefineEdgeTags(delegate(double[] X) {
                    byte et = 0;
                    if (Math.Abs(X[1] - (0 * BaseSize)) <= 1.0e-8)
                    {
                        et = 1;
                    }
                    if (Math.Abs(X[1] + (-4.1 * BaseSize)) <= 1.0e-8)
                    {
                        et = 2;
                    }
                    if (!xPeriodic && Math.Abs(X[0] - (0 * BaseSize)) <= 1.0e-8)
                    {
                        et = 3;
                    }
                    if (!xPeriodic && Math.Abs(X[0] + (-22 * BaseSize)) <= 1.0e-8)
                    {
                        et = 4;
                    }


                    Debug.Assert(et != 0);
                    return(et);
                });

                return(grd);
            };

            C.AddBoundaryCondition("Velocity_Inlet_upper", "VelocityX", X => 0);
            C.AddBoundaryCondition("Velocity_Inlet_lower", "VelocityX", X => 0);
            if (!xPeriodic)
            {
                C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX", X => (4 * 1.5 * X[1] * (4.1 - X[1]) / (4.1 * 4.1)));
            }
            C.AddBoundaryCondition("Pressure_Outlet_right");

            // Initial Values
            // ==============

            C.particleRadius = 0.5;

            C.InitialValues_Evaluators.Add("Phi", X => - (X[0] - 2).Pow2() + -(X[1] - 2).Pow2() + C.particleRadius.Pow2());


            C.InitialValues_Evaluators.Add("VelocityX", X => 0);


            // Physical Parameters
            // ===================

            C.PhysicalParameters.mu_A  = 0.05;
            C.PhysicalParameters.rho_A = 1;

            C.PhysicalParameters.IncludeConvection = true;
            C.PhysicalParameters.Material          = true;

            // misc. solver options
            // ====================

            C.AdvancedDiscretizationOptions.PenaltySafety = 1;
            C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.1;
            C.LevelSetSmoothing        = false;
            C.MaxKrylovDim             = 20;
            C.MaxSolverIterations      = 100;
            C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;
            C.NoOfMultigridLevels      = 1;

            // Timestepping
            // ============

            C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.BDF2;
            double dt = 1E20;

            C.dtFixed       = dt;
            C.dtMax         = dt;
            C.dtMin         = dt;
            C.Endtime       = 200;
            C.NoOfTimesteps = 1;

            // haben fertig...
            // ===============

            return(C);
        }
Ejemplo n.º 5
0
        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 SolverFactory 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, CellType.Cube_Linear, false, true, 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];
                        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.LinearSolver.MaxKrylovDim = 1000;
            C.LinearSolver.MaxKrylovDim            = maxKrDim;
            C.LinearSolver.MaxSolverIterations     = 100;
            C.LinearSolver.MinSolverIterations     = 1;
            C.NonLinearSolver.MaxSolverIterations  = 100;
            C.NonLinearSolver.MinSolverIterations  = 1;
            C.LinearSolver.ConvergenceCriterion    = 1E-5;
            C.NonLinearSolver.ConvergenceCriterion = 1E-5;
            //C.LinearSolver.ConvergenceCriterion = 1E-6;
            C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;

            // Choosing the Preconditioner
            ISolverSmootherTemplate Prec;

            if (name_newton == 1)
            {
                C.NonLinearSolver.SolverCode = NonLinearSolverCode.Newton; // Newton GMRES will be executed if a GMRES linsolver is chosen
            }
            else
            {
                C.NonLinearSolver.SolverCode = NonLinearSolverCode.Picard; // Picard GMRES will be executed if a GMRES linsolver is chosen
            }
            switch (precNo)
            {
            case 0:
            {
                Prec = null;
                break;
            }

            case 1:
            {
                C.LinearSolver.SolverCode = LinearSolverCode.exp_gmres_Schur;
                break;
            }

            case 2:
            {
                C.LinearSolver.SolverCode = LinearSolverCode.exp_gmres_Simple;
                break;
            }

            case 3:
            {
                C.LinearSolver.SolverCode          = LinearSolverCode.exp_gmres_AS;
                C.LinearSolver.TargetBlockSize     = 1000;
                C.LinearSolver.NoOfMultigridLevels = MGLevels;          // 3 // --> grobes MG am Ende nochmal
                break;
            }

            case 4:
            {
                C.LinearSolver.SolverCode          = LinearSolverCode.exp_gmres_AS;
                C.LinearSolver.TargetBlockSize     = 5000;
                C.LinearSolver.NoOfMultigridLevels = MGLevels;
                break;
            }

            case 5:
            {
                C.LinearSolver.SolverCode          = LinearSolverCode.exp_gmres_AS;
                C.LinearSolver.TargetBlockSize     = 10000;
                C.LinearSolver.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.LinearSolver.SolverCode          = LinearSolverCode.exp_gmres_AS_MG;
                C.NoOfMultigridLevels              = 2;
                C.LinearSolver.NoOfMultigridLevels = MGLevels;
                break;
            }

            case 7:
            {
                C.LinearSolver.SolverCode          = LinearSolverCode.exp_gmres_localPrec;;
                C.LinearSolver.NoOfMultigridLevels = MGLevels;
                break;
            }

            case 8:
            {
                C.LinearSolver.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.SolverCoder = Prec;

            ////For Picard
            //C.LinearSolver.SolverCoder = new SoftGMRES()
            //{
            //    MaxKrylovDim = C.LinearSolver.MaxKrylovDim,
            //    Precond_solver = 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);
        }
Ejemplo n.º 6
0
        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.SetDGdegree(k);

            #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, CellType.Cube_Linear, false, true, 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];
                    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.AddBoundaryValue("Velocity_inlet", "VelocityX", (X, t) => 1 - 4 * (X[2] * X[2]));
            C.AddBoundaryValue("Velocity_inlet", "VelocityY", (X, t) => 0);
            C.AddBoundaryValue("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.LinearSolver.MaxKrylovDim            = 1000;
            C.LinearSolver.MaxSolverIterations     = 1;
            C.NonLinearSolver.MaxSolverIterations  = 1;
            C.LinearSolver.ConvergenceCriterion    = 1E-5;
            C.NonLinearSolver.ConvergenceCriterion = 1E-5;
            C.VelocityBlockPrecondMode             = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;

            // Solver configuration
            C.NonLinearSolver.SolverCode = NonLinearSolverCode.Newton; // Newton GMRES will be executed if a GMRES linsolver is chosen
            C.LinearSolver.SolverCode    = LinearSolverCode.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.LinearSolver.NoOfMultigridLevels = 7;

            return(C);
        }
Ejemplo n.º 7
0
        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 <AppControl> 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.AddBoundaryCondition("Velocity_inlet", "VelocityX", (X, t) => 1);
            C.AddBoundaryCondition("Velocity_inlet", "VelocityY", (X, t) => 0);
            //C.AddBoundaryCondition("Velocity_inlet", "VelocityZ", (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             = 20;
            C.MaxSolverIterations      = 50;
            C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;

            // Timestepping
            // ============

            if (pardiso)
            {
                C.whichSolver = DirectSolver._whichSolver.PARDISO;
            }
            else
            {
                C.whichSolver = DirectSolver._whichSolver.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);
        }
Ejemplo n.º 8
0
        static public IBM_Control IBMCylinderFlow(string _DbPath = null, int k = 2, bool only_channel = true, bool pardiso = true, int no_p = 1, int no_it = 1, bool load_Grid = false, string _GridGuid = null)
        {
            // int cells_x, int cells_yz
            IBM_Control  C         = new IBM_Control();
            bool         xPeriodic = false;
            int          i         = 2;
            const double BaseSize  = 1.0;

            // basic database options
            // ======================

            //C.DbPath = _DbPath;

            C.DbPath   = @"\\dc1\userspace\stange\HiWi_database\PerformanceTests";
            C.savetodb = true;

            bool   restart            = false;
            string restartSession     = "67a29dcc-ade9-4704-b198-b3380e774f5a";
            string restartGrid        = "42e1ede0-40fc-4267-9d48-94c0397ac9a5";
            bool   startFromGivenGrid = true;
            string startGrid          = "42e1ede0-40fc-4267-9d48-94c0397ac9a5";

            switch (i)
            {
            case 1:
                C.MeshFactor = 1.258;     // was 1.33
                break;

            case 2:
                C.MeshFactor = 3.0;     //1.77; //0.92;
                break;

            case 3:
                C.MeshFactor = 0.7;     // was 07
                break;

            default:

                throw new ApplicationException();
            }

            if (pardiso)
            {
                if (only_channel)
                {
                    C.SessionName = "2DChannel_Pardiso_k" + k + "_MeshFactor" + C.MeshFactor + "_no_p" + no_p + "_run" + no_it;
                }
                else
                {
                    C.SessionName = "Cylinder_Pardiso_k" + k + "_MeshFactor" + C.MeshFactor + "_no_p" + no_p + "_run" + no_it;
                }
            }
            else
            {
                if (only_channel)
                {
                    C.SessionName = "2DChannel_Mumps_k" + k + "_MeshFactor" + C.MeshFactor + "_no_p" + no_p + "_run" + no_it;
                }
                else
                {
                    C.SessionName = "Cylinder_Mumps_k" + k + "_MeshFactor" + C.MeshFactor + "_no_p" + no_p + "_run" + no_it;
                }
            }
            C.saveperiod = 1;
            //C.SessionName = "Sphere_k" + k + "_h" + h+"Re100";


            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("MeshFactor " + C.MeshFactor);

            C.ProjectName = "FixedCylinderRe100_k" + i + "_CellAgglo02_penalty4_newMesh2";

            C.ProjectDescription = "Cylinder";

            // DG degrees
            // ==========

            C.FieldOptions.Add("VelocityX", new FieldOpts()
            {
                Degree   = k,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("VelocityY", new FieldOpts()
            {
                Degree   = k,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            //Console.WriteLine("Achtung: equal order!!!!");
            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
            });

            // restart options
            // ===============
            if (restart)
            {
                C.RestartInfo = new Tuple <Guid, TimestepNumber>(new Guid(restartSession), -1);
                C.GridGuid    = new Guid(restartGrid);
            }
            //grid and boundary conditions
            // ============================

            // Initial Values
            // ==============

            double radius = 0.5;

            C.PhysicalParameters.rho_A = 1.0;
            C.PhysicalParameters.mu_A  = 1.0 / 100.0;

            if (!restart)
            {
                if (!startFromGivenGrid)
                {
                    C.GridFunc = delegate
                    {
                        var _xNodes1 = Grid1D.TanhSpacing(-2.0, -1.0, Convert.ToInt32(10.0 * C.MeshFactor), 0.5, false); //10
                        _xNodes1 = _xNodes1.GetSubVector(0, (_xNodes1.Length - 1));
                        var _xNodes2 = GenericBlas.Linspace(-1.0, 2.0, Convert.ToInt32(35.0 * C.MeshFactor));            //35
                        _xNodes2 = _xNodes2.GetSubVector(0, (_xNodes2.Length - 1));
                        var _xNodes3 = Grid1D.TanhSpacing(2.0, 20.0, Convert.ToInt32(60.0 * C.MeshFactor), 1.5, true);   //60

                        var xNodes = ArrayTools.Cat(_xNodes1, _xNodes2, _xNodes3);


                        var _yNodes1 = Grid1D.TanhSpacing(-2.0, -1.0, Convert.ToInt32(7.0 * C.MeshFactor), 0.9, false); //7
                        _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
                        var _yNodes2 = GenericBlas.Linspace(-1.0, 1.0, Convert.ToInt32(25.0 * C.MeshFactor));           //25
                        _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1));
                        var _yNodes3 = Grid1D.TanhSpacing(1.0, 2.1, Convert.ToInt32(7.0 * C.MeshFactor), 1.1, true);    //7
                        var yNodes   = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3);



                        //double[] xNodes = GenericBlas.Linspace(0 * BaseSize, 22 * BaseSize, 25);
                        //double[] yNodes = GenericBlas.Linspace(0 * BaseSize, 4.1 * BaseSize, 25);
                        var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: xPeriodic);
                        grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
                        grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
                        if (!xPeriodic)
                        {
                            grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
                            grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
                        }

                        grd.DefineEdgeTags(delegate(double[] X)
                        {
                            byte et = 0;
                            if (Math.Abs(X[1] - (-2.0 * BaseSize)) <= 1.0e-8)
                            {
                                et = 1;
                            }
                            if (Math.Abs(X[1] - (+2.1 * BaseSize)) <= 1.0e-8)
                            {
                                et = 2;
                            }
                            if (!xPeriodic && Math.Abs(X[0] - (-2.0 * BaseSize)) <= 1.0e-8)
                            {
                                et = 3;
                            }
                            if (!xPeriodic && Math.Abs(X[0] - (+20.0 * BaseSize)) <= 1.0e-8)
                            {
                                et = 4;
                            }


                            Debug.Assert(et != 0);
                            return(et);
                        });

                        Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

                        return(grd);
                    };
                }
                else
                {
                    C.GridGuid = new Guid(startGrid);
                }
                if (only_channel)
                {
                    C.InitialValues_Evaluators.Add("Phi", X => - 1);
                }
                else
                {
                    C.InitialValues_Evaluators.Add("Phi", X => - (X[0]).Pow2() + -(X[1]).Pow2() + radius.Pow2());
                }


                //C.InitialValues.Add("Phi", X => -1);

                C.InitialValues_Evaluators.Add("VelocityX", X => 4.0 * 1.5 * (X[1] + 2.0) * (4.1 - (X[1] + 2.0)) / (4.1 * 4.1));
            }

            //C.GridFunc = delegate {

            //    // Box1
            //    var box1_p1 = new double[2] { -2, -2 };
            //    var box1_p2 = new double[2] { 20, 2.1 };
            //    var box1 = new GridBox(box1_p1, box1_p2, 46, 20); //k1: 70,25 ; k2: 46,20 ; k3: 35,15

            //    // Box2
            //    var box2_p1 = new double[2] { -2, -2 };
            //    var box2_p2 = new double[2] { 3, 2.1 };
            //    var box2 = new GridBox(box2_p1, box2_p2, 26, 40); //k1: 40,50 ; k2: 26,40; k3: 20, 30

            //    // Box3
            //    var box3_p1 = new double[2] { -2, -1 };
            //    var box3_p2 = new double[2] { 1, 1 };
            //    var box3 = new GridBox(box3_p1, box3_p2, 32, 38); //k1: 48,58  ; k2: 32,38; k3: 24, 30

            //    // Box4
            //    var box4_p1 = new double[2] { -0.7, -0.72 };
            //    var box4_p2 = new double[2] { 0.7, 0.7 };
            //    var box4 = new GridBox(box4_p1, box4_p2, 30, 56); //k1: 44,84  ; k2: 30,56; k3: 22, 42

            //    var grd = Grid2D.HangingNodes2D(box1, box2, box3,box4);

            //    grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
            //    grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
            //    if (!xPeriodic) {
            //        grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
            //        grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
            //    }

            //    grd.DefineEdgeTags(delegate (double[] X) {
            //        byte et = 0;
            //        if (Math.Abs(X[1] - (-2 * BaseSize)) <= 1.0e-8)
            //            et = 1;
            //        if (Math.Abs(X[1] - (+2.1 * BaseSize)) <= 1.0e-8)
            //            et = 2;
            //        if (!xPeriodic && Math.Abs(X[0] - (-2 * BaseSize)) <= 1.0e-8)
            //            et = 3;
            //        if (!xPeriodic && Math.Abs(X[0] - (+20.0 * BaseSize)) <= 1.0e-8)
            //            et = 4;


            //        Debug.Assert(et != 0);
            //        return et;
            //    });

            //    Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

            //    return grd;
            //};

            C.AddBoundaryCondition("Velocity_Inlet_upper", "VelocityX", X => 0.0);
            C.AddBoundaryCondition("Velocity_Inlet_lower", "VelocityX", X => 0.0); //-(4 * 1.5 * X[1] * (4.1 - X[1]) / (4.1 * 4.1))
            if (!xPeriodic)
            {
                C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX", X => (4.0 * 1.5 * (X[1] + 2.0) * (4.1 - (X[1] + 2.0)) / (4.1 * 4.1)));
                //C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX#A", X => 1);
            }
            C.AddBoundaryCondition("Pressure_Outlet_right");



            //C.InitialValues.Add("Phi", X => phi(X, 0));

            //C.InitialValues.Add("Phi", X => ((X[0] / (radius * BaseSize)) - mPx) * (X[0] / (radius * BaseSize)) - mPx) + ((X[1]) / (radius * BaseSize)) - 2.)Pow2() - radius.Pow2()));  // quadratic form
            //    );


            //C.InitialValues.Add("VelocityX", delegate (double[] X)
            //{
            //    double x = X[0];
            //    double y = X[1];

            //    double R = Math.Sqrt((x + 1).Pow2() + y.Pow2());

            //    double xVel = 0;

            //    if (R < 0.75)
            //    {
            //        xVel = 1;
            //    }
            //    return xVel;
            //});

            //C.InitialValues.Add("VelocityY", delegate (double[] X) {
            //    double x = X[0];
            //    double y = X[1];

            //    double R = Math.Sqrt((x + 1).Pow2() + (y).Pow2());

            //    double yVel = 0;

            //    if (R < 0.75) {
            //        yVel = 1;
            //    }
            //    return yVel;
            //});

            // For restart
            //C.RestartInfo = new Tuple<Guid, TimestepNumber>(new Guid("8f5cfed9-31c7-4be8-aa56-e92e5348e08b"), 95);
            //C.GridGuid = new Guid("71ffc0c4-66aa-4762-b07e-45385f34b03f");

            // Physical Parameters
            // ===================


            C.PhysicalParameters.IncludeConvection = true;


            // misc. solver options
            // ====================

            C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2;
            C.AdvancedDiscretizationOptions.PenaltySafety = 4;
            C.LevelSetSmoothing = false;
            //C.option_solver = "direct";
            C.MaxKrylovDim             = 20;
            C.MaxSolverIterations      = 50;
            C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;
            //C.NoOfMultigridLevels = 0;

            if (pardiso)
            {
                C.whichSolver = DirectSolver._whichSolver.PARDISO;
            }
            else
            {
                C.whichSolver = DirectSolver._whichSolver.MUMPS;
            }
            // Timestepping
            // ============

            C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.BDF2;
            double dt = 0.1;

            C.dtMax         = dt;
            C.dtMin         = dt;
            C.Endtime       = 70;
            C.NoOfTimesteps = 10;

            // haben fertig...
            // ===============
            return(C);
        }
Ejemplo n.º 9
0
        static public IBM_Control MittalSphereFlow(int k = 2, int h = 1)
        {
            IBM_Control C = new IBM_Control();

            // basic database options
            // ======================
            C.DbPath      = @"\\dc1\userspace\krause\BoSSS_DBs\Sphere3D";
            C.savetodb    = false;
            C.ProjectName = "Sphere3D";
            C.SessionName = "Sphere3D_" + k + "_Re100";
            C.Tags.Add("with immersed boundary method");

            // 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
            });

            C.AdaptiveMeshRefinement = false;

            // Load Grid
            Console.WriteLine("...loading grid");
            C.GridGuid = new Guid("202033c5-7c2a-4c29-aaea-86d7a2f7a8a3");

            //#region Creates grid () and sets BC
            ////// Create Grid
            //Console.WriteLine("...generating grid");
            //C.GridFunc = delegate {

            //    // x-direction
            //    var _xNodes = GenericBlas.Linspace(-10, 30, (10 * h) + 1);

            //    // y-direction
            //    var _yNodes = GenericBlas.Linspace(-10, 10, (5 * h) + 1);

            //    // z-direction
            //    var _zNodes = GenericBlas.Linspace(-10, 10, (5 * h) + 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.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();
            //    });

            //    Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

            //    return grd;
            //};
            //#endregion


            // Create Grid with HANGING NODES
            //Console.WriteLine("...generating grid");
            //C.GridFunc = delegate {

            //    // Box1
            //    var box1_p1 = new double[3] { -6, -7.5, -7.5 };
            //    var box1_p2 = new double[3] { 10, 7.5, 7.5 };
            //    var box1 = new GridCommons.GridBox(box1_p1, box1_p2, 16 * h, 15 * h, 15 * h);

            //    // Box2
            //    var box2_p1 = new double[3] { -2.5, -1.5, -1.5 };
            //    var box2_p2 = new double[3] { 7.5, 1.5, 1.5 };
            //    var box2 = new GridCommons.GridBox(box2_p1, box2_p2, 10 * (h + 3), 4 * (h + 3), 4 * (h + 3));

            //    // Cut Out
            //    //var box1 = new GridCommons.GridBox(box1_p1, box1_p2, 10, 5, 5);
            //    //var box2 = new GridCommons.GridBox(box2_p1, box2_p2, 10, 5, 5);
            //    var grd = Grid3D.HangingNodes3D(false, false, false, 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 - (-6)) < 1.0e-6)
            //            // inlet
            //            return 1;

            //        if (Math.Abs(x - (10)) < 1.0e-6)
            //            // outlet
            //            return 2;

            //        if (Math.Abs(y - (-7.5)) < 1.0e-6)
            //            // left
            //            return 2;

            //        if (Math.Abs(y - (7.5)) < 1.0e-6)
            //            // right
            //            return 2;

            //        if (Math.Abs(z - (-7.5)) < 1.0e-6)
            //            // top left
            //            return 2;

            //        if (Math.Abs(z - (7.5)) < 1.0e-6)
            //            // top right
            //            return 2;

            //        throw new ArgumentOutOfRangeException();
            //    });

            //    Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

            //    return grd;
            //};

            //Console.WriteLine("Loading Grid...");
            //C.GridGuid = new Guid("9aca8eed-e98a-4dca-8024-e02edc4d3edc");
            //C.GridGuid = new Guid("099cffa4-238d-42ad-8fbd-85228bfc6b1e");

            #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

            Console.WriteLine("...starting calculation of Sphere3D");

            // Initial Solution

            // Physical values
            C.particleRadius           = 0.5;
            C.PhysicalParameters.rho_A = 1;
            //C.PhysicalParameters.mu_A = (2 * C.particleRadius) / 100;
            C.PhysicalParameters.mu_A = (2.0 * C.particleRadius * 1.0) / 100;

            // Boundary conditions
            C.AddBoundaryCondition("Velocity_inlet", "VelocityX", (X, t) => 1);
            C.AddBoundaryCondition("Velocity_inlet", "VelocityY", (X, t) => 0);
            C.AddBoundaryCondition("Velocity_inlet", "VelocityZ", (X, t) => 0);
            // C.AddBoundaryCondition("Wall");
            C.AddBoundaryCondition("Pressure_Outlet");

            // Set Initial Conditions
            C.InitialValues_Evaluators.Add("VelocityX", X => 1);
            //C.InitialValues_Evaluators.Add("VelocityY", X => 5);
            C.InitialValues_Evaluators.Add("VelocityZ", X => 0);
            C.InitialValues_Evaluators.Add("Pressure", X => 0);
            C.InitialValues_Evaluators.Add("Phi", X => - (X[0]).Pow2() + -(X[1]).Pow2() + -(X[2]).Pow2() + C.particleRadius.Pow2());

            //C.InitialValues_Evaluators.Add("VelocityY", delegate (double[] X) {
            //    double x = X[0];
            //    double y = X[1];
            //    double z = X[2];

            //    double R = Math.Sqrt((x + 4).Pow2() + y.Pow2()+z.Pow2());

            //    double yVel = 0;

            //    if (R < 3) {
            //        yVel = 5;
            //    }
            //    return yVel;
            //});
            //C.InitialValues_Evaluators.Add("Phi", X => -(X[0]).Pow2() + -(X[1]).Pow2() + C.particleRadius.Pow2());
            //C.InitialValues_Evaluators.Add("Phi", X => -1);



            // misc. solver options
            // ====================
            C.PhysicalParameters.IncludeConvection        = true;
            C.AdvancedDiscretizationOptions.PenaltySafety = 4;
            C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2;
            C.LevelSetSmoothing        = false;
            C.MaxKrylovDim             = 30;
            C.MaxSolverIterations      = 50;
            C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;
            C.NonlinearSolve           = NonlinearSolverCodes.NewtonGMRES;
            C.LinearSolve = LinearSolverCodes.exp_schwarz_Kcycle_directcoarse_overlap;
            C.Solver_ConvergenceCriterion = 1E-6;
            C.NoOfMultigridLevels         = 3;

            // Timestepping
            // ============


            C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.BDF2;
            double dt = 1E20;
            C.dtFixed       = dt;
            C.dtMax         = dt;
            C.dtMin         = dt;
            C.Endtime       = 100000;
            C.NoOfTimesteps = 1;

            return(C);
        }
Ejemplo n.º 10
0
        public static IBM_Control[] IBMCylinderFlow(string _DbPath = null, int k = 2, bool xPeriodic = false, double VelXBase = 0.0)
        {
            List <IBM_Control> R = new List <IBM_Control>();

            foreach (int i in new int[] { 3 })
            {
                IBM_Control C = new IBM_Control();

                C.Paramstudy_CaseIdentification = new Tuple <string, object>[] {
                    new Tuple <string, object>("k", i),
                };

                k = i;

                const double BaseSize = 1.0;

                // basic database options
                // ======================

                C.DbPath      = @"\\fdyprime\userspace\krause\BoSSS_DBs\Paper_CellAgglo01_Penalty4";
                C.savetodb    = false;
                C.ProjectName = "FixedCylinderRe100_k" + i + "_CellAgglo02_penalty4_newMesh2";

                switch (i)
                {
                case 1:
                    C.MeshFactor = 1.33; // was 1.33
                    break;

                case 2:
                    C.MeshFactor = 0.92;
                    break;

                case 3:
                    C.MeshFactor = 0.7; // was 07
                    break;

                default:

                    throw new ApplicationException();
                }

                C.ProjectDescription = "Cylinder";
                C.Tags.Add("with immersed boundary method");

                // DG degrees
                // ==========

                C.FieldOptions.Add("VelocityX", new FieldOpts()
                {
                    Degree   = k,
                    SaveToDB = FieldOpts.SaveToDBOpt.TRUE
                });
                C.FieldOptions.Add("VelocityY", new FieldOpts()
                {
                    Degree   = k,
                    SaveToDB = FieldOpts.SaveToDBOpt.TRUE
                });
                //Console.WriteLine("Achtung: equal order!!!!");
                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
                });

                //grid and boundary conditions
                // ============================

                C.GridFunc = delegate {
                    var _xNodes1 = Grid1D.TanhSpacing(-2, -1, Convert.ToInt32(10 * C.MeshFactor), 0.5, false); //10
                    _xNodes1 = _xNodes1.GetSubVector(0, (_xNodes1.Length - 1));
                    var _xNodes2 = GenericBlas.Linspace(-1, 2, Convert.ToInt32(35 * C.MeshFactor));            //35
                    _xNodes2 = _xNodes2.GetSubVector(0, (_xNodes2.Length - 1));
                    var _xNodes3 = Grid1D.TanhSpacing(2, 20, Convert.ToInt32(60 * C.MeshFactor), 1.5, true);   //60

                    var xNodes = ArrayTools.Cat(_xNodes1, _xNodes2, _xNodes3);


                    var _yNodes1 = Grid1D.TanhSpacing(-2, -1, Convert.ToInt32(7 * C.MeshFactor), 0.9, false); //7
                    _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
                    var _yNodes2 = GenericBlas.Linspace(-1, 1, Convert.ToInt32(25 * C.MeshFactor));           //25
                    _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1));
                    var _yNodes3 = Grid1D.TanhSpacing(1, 2.1, Convert.ToInt32(7 * C.MeshFactor), 1.1, true);  //7
                    var yNodes   = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3);



                    //double[] xNodes = GenericBlas.Linspace(0 * BaseSize, 22 * BaseSize, 25);
                    //double[] yNodes = GenericBlas.Linspace(0 * BaseSize, 4.1 * BaseSize, 25);
                    var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: xPeriodic);
                    grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
                    grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
                    if (!xPeriodic)
                    {
                        grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
                        grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
                    }

                    grd.DefineEdgeTags(delegate(double[] X) {
                        byte et = 0;
                        if (Math.Abs(X[1] - (-2 * BaseSize)) <= 1.0e-8)
                        {
                            et = 1;
                        }
                        if (Math.Abs(X[1] - (+2.1 * BaseSize)) <= 1.0e-8)
                        {
                            et = 2;
                        }
                        if (!xPeriodic && Math.Abs(X[0] - (-2 * BaseSize)) <= 1.0e-8)
                        {
                            et = 3;
                        }
                        if (!xPeriodic && Math.Abs(X[0] - (+20.0 * BaseSize)) <= 1.0e-8)
                        {
                            et = 4;
                        }


                        Debug.Assert(et != 0);
                        return(et);
                    });

                    Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

                    return(grd);
                };

                //C.GridFunc = delegate {

                //    // Box1
                //    var box1_p1 = new double[2] { -2, -2 };
                //    var box1_p2 = new double[2] { 20, 2.1 };
                //    var box1 = new GridBox(box1_p1, box1_p2, 46, 20); //k1: 70,25 ; k2: 46,20 ; k3: 35,15

                //    // Box2
                //    var box2_p1 = new double[2] { -2, -2 };
                //    var box2_p2 = new double[2] { 3, 2.1 };
                //    var box2 = new GridBox(box2_p1, box2_p2, 26, 40); //k1: 40,50 ; k2: 26,40; k3: 20, 30

                //    // Box3
                //    var box3_p1 = new double[2] { -2, -1 };
                //    var box3_p2 = new double[2] { 1, 1 };
                //    var box3 = new GridBox(box3_p1, box3_p2, 32, 38); //k1: 48,58  ; k2: 32,38; k3: 24, 30

                //    // Box4
                //    var box4_p1 = new double[2] { -0.7, -0.72 };
                //    var box4_p2 = new double[2] { 0.7, 0.7 };
                //    var box4 = new GridBox(box4_p1, box4_p2, 30, 56); //k1: 44,84  ; k2: 30,56; k3: 22, 42

                //    var grd = Grid2D.HangingNodes2D(box1, box2, box3,box4);

                //    grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
                //    grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
                //    if (!xPeriodic) {
                //        grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
                //        grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
                //    }

                //    grd.DefineEdgeTags(delegate (double[] X) {
                //        byte et = 0;
                //        if (Math.Abs(X[1] - (-2 * BaseSize)) <= 1.0e-8)
                //            et = 1;
                //        if (Math.Abs(X[1] - (+2.1 * BaseSize)) <= 1.0e-8)
                //            et = 2;
                //        if (!xPeriodic && Math.Abs(X[0] - (-2 * BaseSize)) <= 1.0e-8)
                //            et = 3;
                //        if (!xPeriodic && Math.Abs(X[0] - (+20.0 * BaseSize)) <= 1.0e-8)
                //            et = 4;


                //        Debug.Assert(et != 0);
                //        return et;
                //    });

                //    Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

                //    return grd;
                //};

                C.AddBoundaryCondition("Velocity_Inlet_upper", "VelocityX", X => 0);
                C.AddBoundaryCondition("Velocity_Inlet_lower", "VelocityX", X => 0); //-(4 * 1.5 * X[1] * (4.1 - X[1]) / (4.1 * 4.1))
                if (!xPeriodic)
                {
                    C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX", X => (4 * 1.5 * (X[1] + 2) * (4.1 - (X[1] + 2)) / (4.1 * 4.1)));
                    //C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX#A", X => 1);
                }
                C.AddBoundaryCondition("Pressure_Outlet_right");


                // Initial Values
                // ==============

                double radius = 0.5;
                C.PhysicalParameters.rho_A = 1;
                C.PhysicalParameters.mu_A  = 1.0 / 20;

                //C.InitialValues.Add("Phi", X => phi(X, 0));

                //C.InitialValues.Add("Phi", X => ((X[0] / (radius * BaseSize)) - mPx) * (X[0] / (radius * BaseSize)) - mPx) + ((X[1]) / (radius * BaseSize)) - 2.)Pow2() - radius.Pow2()));  // quadratic form
                //    );
                C.InitialValues_Evaluators.Add("Phi", X => - (X[0]).Pow2() + -(X[1]).Pow2() + radius.Pow2());
                //C.InitialValues.Add("Phi", X => -1);

                C.InitialValues_Evaluators.Add("VelocityX", X => 4 * 1.5 * (X[1] + 2) * (4.1 - (X[1] + 2)) / (4.1 * 4.1));
                //C.InitialValues.Add("VelocityX", delegate (double[] X)
                //{
                //    double x = X[0];
                //    double y = X[1];

                //    double R = Math.Sqrt((x + 1).Pow2() + y.Pow2());

                //    double xVel = 0;

                //    if (R < 0.75)
                //    {
                //        xVel = 1;
                //    }
                //    return xVel;
                //});

                //C.InitialValues.Add("VelocityY", delegate (double[] X) {
                //    double x = X[0];
                //    double y = X[1];

                //    double R = Math.Sqrt((x + 1).Pow2() + (y).Pow2());

                //    double yVel = 0;

                //    if (R < 0.75) {
                //        yVel = 1;
                //    }
                //    return yVel;
                //});

                // For restart
                //C.RestartInfo = new Tuple<Guid, TimestepNumber>(new Guid("8f5cfed9-31c7-4be8-aa56-e92e5348e08b"), 95);
                //C.GridGuid = new Guid("71ffc0c4-66aa-4762-b07e-45385f34b03f");

                // Physical Parameters
                // ===================


                C.PhysicalParameters.IncludeConvection = true;


                // misc. solver options
                // ====================

                C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2;

                C.LevelSetSmoothing = false;
                //C.option_solver = "direct";
                C.MaxKrylovDim             = 20;
                C.MaxSolverIterations      = 50;
                C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;
                C.NoOfMultigridLevels      = 0;

                // Timestepping
                // ============

                C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.ImplicitEuler;
                double dt = 0.05;
                C.dtMax         = dt;
                C.dtMin         = dt;
                C.Endtime       = 70;
                C.NoOfTimesteps = 1000000;

                // haben fertig...
                // ===============

                R.Add(C);
            }

            return(R.ToArray());
        }
Ejemplo n.º 11
0
        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   = @"\\dc1\userspace\krause\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 <AppControl> app, int noOfPerformanceClasses)
            {
                Console.WriteLine("i was called");
                int[] map = new int[] { 1, 5, 100 };
                return(new StaticCellCostEstimator(map));
            });

            // Assign correct names
            C.SessionName = "Channel_" + k + "_" + cells_x + "x" + cells_yz + "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 => 0);
            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         = 50;
            C.Solver_ConvergenceCriterion = 1E-5;
            C.VelocityBlockPrecondMode    = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;


            // Choosing the Preconditioner
            ISolverSmootherTemplate Prec;

            Prec = new SchurPrecond()
            {
                SchurOpt = SchurPrecond.SchurOptions.decoupledApprox
            };

            //Prec = new SchurPrecond()
            //{
            //    SchurOpt = SchurPrecond.SchurOptions.SIMPLE
            //};

            //Prec = new Schwarz()
            //{
            //    m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
            //    {
            //        NoOfParts = 5,
            //    },
            //    CoarseSolver = new DirectSolver()
            //    {
            //        WhichSolver = DirectSolver._whichSolver.MUMPS
            //    },
            // overlap =1
            //};


            //Prec = new Schwarz()
            //{
            //    m_BlockingStrategy = new Schwarz.MultigridBlocks()
            //    {
            //        Depth = 5,
            //    },
            //    CoarseSolver = new DirectSolver()
            //    {
            //        WhichSolver = DirectSolver._whichSolver.MUMPS
            //    },
            //    overlap = 1
            //};



            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;
            C.NoOfMultigridLevels = 1;

            return(C);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Automatic choice of linear solver depending on problem size, immersed boundary, polynomial degree, etc.
        /// </summary>
        static ISolverSmootherTemplate AutomaticChoice(IBM_Control Control, XdgBDFTimestepping Timestepper)
        {
            //int pV = Control.FieldOptions["VelocityX"].Degree;
            int pP = Control.FieldOptions["Pressure"].Degree;
            int pV = pP + 1;

            // Detecting variables for solver determination
            var D        = Timestepper.MultigridSequence[0].SpatialDimension;
            var cellsLoc = Timestepper.MultigridSequence[0].CellPartitioning.LocalLength;
            var cellsGlo = Timestepper.MultigridSequence[0].CellPartitioning.TotalLength;

            ISolverSmootherTemplate tempsolve = null;


            var size = Timestepper.MultigridSequence[0].CellPartitioning.MpiSize;

            // !!!!!!!!!!!UNTERSCHEIDUNG OB PICARD ODER NEWTON!!!!!!!!!!!!
            if (Timestepper.Config_NonlinearSolver == NonlinearSolverMethod.NewtonGMRES)
            {
                // Spatial Dimension
                switch (D)
                {
                case 1:
                    break;
                    throw new NotImplementedException("Currently not implemented for " + D + " Dimensions");
                //break;

                case 2:
                    throw new NotImplementedException("Currently not implemented for " + D + " Dimensions");
                //break;

                case 3:
                    var dofsPerCell3D = (3 * (pV * pV * pV + 6 * pV * pV + 11 * pV + 6) / 6 + 1 * (pP * pP * pP + 6 * pP * pP + 11 * pP + 6) / 6);
                    var dofsLoc       = dofsPerCell3D * cellsLoc;
                    var dofsGlo       = dofsPerCell3D * cellsGlo;

                    var PPP = (int)Math.Ceiling(dofsLoc / 6500.0);

                    Console.WriteLine("Analysing the problem yields " + PPP + " parts per process.");

                    if (dofsGlo > 10000)
                    {
                        if (Control.NoOfMultigridLevels < 2)
                        {
                            throw new ApplicationException("At least 2 Multigridlevels are required");
                        }

                        Timestepper.Config_linearSolver = new Schwarz()
                        {
                            m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                            {
                                NoOfPartsPerProcess = PPP,
                            },
                            Overlap      = 1,
                            CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                        };
                    }
                    else
                    {
                        Timestepper.Config_linearSolver = new DirectSolver()
                        {
                            WhichSolver = DirectSolver._whichSolver.MUMPS
                        };
                    }
                    break;

                default:
                    throw new NotImplementedException("Currently not implemented for " + D + " Dimensions");
                }
            }
            else
            {
                // Spatial Dimension
                switch (D)
                {
                case 1:
                    break;
                    throw new NotImplementedException("Currently not implemented for " + D + " Dimensions");
                //break;

                case 2:
                    throw new NotImplementedException("Currently not implemented for " + D + " Dimensions");
                //break;

                case 3:
                    var dofsPerCell3D = (3 * (pV * pV * pV + 6 * pV * pV + 11 * pV + 6) / 6 + 1 * (pP * pP * pP + 6 * pP * pP + 11 * pP + 6) / 6);
                    var dofsLoc       = dofsPerCell3D * cellsLoc;
                    var dofsGlo       = dofsPerCell3D * cellsGlo;

                    if (dofsGlo > 10000)
                    {
                        if (Control.NoOfMultigridLevels < 2)
                        {
                            throw new ApplicationException("At least 2 Multigridlevels are required");
                        }

                        tempsolve = new SoftGMRES()
                        {
                            MaxKrylovDim = Timestepper.Config_MaxKrylovDim,
                            m_Tolerance  = Timestepper.Config_SolverConvergenceCriterion,
                            Precond      = new Schwarz()
                            {
                                m_BlockingStrategy = new Schwarz.SimpleBlocking()
                                {
                                    NoOfPartsPerProcess = (int)Math.Ceiling(dofsLoc / 6500.0),
                                },
                                Overlap      = 1,
                                CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                            },
                        };
                    }
                    else
                    {
                        tempsolve = new DirectSolver()
                        {
                            WhichSolver = DirectSolver._whichSolver.MUMPS
                        };
                    }
                    break;

                default:
                    throw new NotImplementedException("Currently not implemented for " + D + " Dimensions");
                }
            }

            return(tempsolve);
            //Timestepper.

            // Wenn Gesamtproblem in 2D < 100000 DoFs -> Direct Solver
            // Wenn Gesamtproblem in 3D < 10000 DoFs -> Direct Solver

            // Block Solve 3D ca. 6000 DoFs per Process -> Adjust Blocks per Process
            // Coarse Solve ca. 5000 bis 10000 DoFs. -> Adjust Multigrid Levels
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Choose solver depending on configurations made in the control file.
        /// </summary>
        /// <param name="nonlinSol"></param>
        /// <param name="linSol"></param>
        /// <param name="Timestepper"></param>
        public static void ChooseSolver(IBM_Control Control, ref XdgBDFTimestepping Timestepper)
        {
            // Set several solver options for Timestepper
            Timestepper.Config_SolverConvergenceCriterion = Control.Solver_ConvergenceCriterion;
            Timestepper.Config_MaxIterations = Control.MaxSolverIterations;
            Timestepper.Config_MinIterations = Control.MinSolverIterations;
            Timestepper.Config_MaxKrylovDim  = Control.MaxKrylovDim;

            // Set to pseudo Picard if the Stokes equations should be solved
            if (Control.PhysicalParameters.IncludeConvection == false)
            {
                Control.NonlinearSolve = NonlinearSolverCodes.Picard;
            }

            ISolverSmootherTemplate templinearSolve = null;

            switch (Control.LinearSolve)
            {
            case LinearSolverCodes.automatic:
                templinearSolve = AutomaticChoice(Control, Timestepper);
                break;

            case LinearSolverCodes.classic_mumps:
                templinearSolve = new DirectSolver()
                {
                    WhichSolver = DirectSolver._whichSolver.MUMPS
                };
                break;

            case LinearSolverCodes.classic_pardiso:
                templinearSolve = new DirectSolver()
                {
                    WhichSolver = DirectSolver._whichSolver.PARDISO
                };
                break;

            case LinearSolverCodes.exp_schwarz_directcoarse_overlap:

                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }

                templinearSolve = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                    {
                        NoOfPartsPerProcess = 1,
                    },
                    Overlap      = 1,
                    CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                };
                break;

            case LinearSolverCodes.exp_schwarz_directcoarse:

                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }

                templinearSolve = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                    {
                        NoOfPartsPerProcess = 1,
                    },
                    Overlap      = 0,
                    CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                };
                break;

            case LinearSolverCodes.exp_schwarz_Kcycle_directcoarse:

                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }

                templinearSolve = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.MultigridBlocks()
                    {
                        Depth = Control.NoOfMultigridLevels - 1
                    },
                    Overlap      = 0,
                    CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                };
                break;

            case LinearSolverCodes.exp_schwarz_Kcycle_directcoarse_overlap:

                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }

                templinearSolve = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.MultigridBlocks()
                    {
                        Depth = Control.NoOfMultigridLevels - 1
                    },
                    Overlap      = 1,
                    CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                };
                break;

            case LinearSolverCodes.exp_softgmres:
                templinearSolve = new SoftGMRES()
                {
                    MaxKrylovDim = Timestepper.Config_MaxKrylovDim,
                    m_Tolerance  = Timestepper.Config_SolverConvergenceCriterion,
                };
                break;

            case LinearSolverCodes.exp_softgmres_schwarz_Kcycle_directcoarse_overlap:
                templinearSolve = new SoftGMRES()
                {
                    MaxKrylovDim = Timestepper.Config_MaxKrylovDim,
                    m_Tolerance  = Timestepper.Config_SolverConvergenceCriterion,
                    Precond      = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.MultigridBlocks()
                        {
                            Depth = Control.NoOfMultigridLevels - 1
                        },
                        Overlap      = 1,
                        CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                    },
                };
                break;

            case LinearSolverCodes.exp_softgmres_schwarz_directcoarse_overlap:
                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }
                templinearSolve = new SoftGMRES()
                {
                    MaxKrylovDim = Timestepper.Config_MaxKrylovDim,
                    m_Tolerance  = Timestepper.Config_SolverConvergenceCriterion,
                    Precond      = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                        {
                            NoOfPartsPerProcess = 1,
                        },
                        Overlap      = 1,
                        CoarseSolver = DetermineMGSquence(Control.NoOfMultigridLevels - 2)
                    },
                };
                break;

            case LinearSolverCodes.exp_multigrid:
                if (Control.NoOfMultigridLevels < 2)
                {
                    throw new ApplicationException("At least 2 Multigridlevels are required");
                }
                templinearSolve = new ILU()
                {
                };
                break;

            case LinearSolverCodes.exp_ILU:
                templinearSolve = new ILU()
                {
                };
                break;

            case LinearSolverCodes.exp_Schur:
                templinearSolve = new SchurPrecond()
                {
                    SchurOpt = SchurPrecond.SchurOptions.decoupledApprox
                };
                break;

            case LinearSolverCodes.exp_Simple:
                templinearSolve = new SchurPrecond()
                {
                    SchurOpt = SchurPrecond.SchurOptions.SIMPLE
                };
                break;

            case LinearSolverCodes.exp_AS_1000:
                if (Timestepper.MultigridSequence[0].SpatialDimension == 3)       //3D --> 212940DoF
                {
                    templinearSolve = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                        {
                            //noofparts = 76,
                            NoOfPartsPerProcess = 213,     // Warum 76
                        },
                        CoarseSolver = new DirectSolver()
                        {
                            WhichSolver = DirectSolver._whichSolver.MUMPS        //PARDISO
                        },
                        Overlap = 1
                    };
                }
                else      //2D --> 75088DoF
                {
                    templinearSolve = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                        {
                            //noofparts = 213,
                            NoOfPartsPerProcess = 213,
                        },
                        CoarseSolver = new DirectSolver()
                        {
                            WhichSolver = DirectSolver._whichSolver.MUMPS        //PARDISO
                        },
                        Overlap = 1
                    };
                }
                break;

            case LinearSolverCodes.exp_AS_5000:
                if (Timestepper.MultigridSequence[0].SpatialDimension == 3)       //3D --> 212940DoF
                {
                    templinearSolve = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                        {
                            //noofparts = 43,
                            NoOfPartsPerProcess = 43,
                        },
                        CoarseSolver = new DirectSolver()
                        {
                            WhichSolver = DirectSolver._whichSolver.MUMPS        //PARDISO
                        },
                        Overlap = 1
                    };
                }
                else      //2D --> 75088DoF
                {
                    templinearSolve = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                        {
                            //noofparts = 16,
                            NoOfPartsPerProcess = 43,
                        },
                        CoarseSolver = new DirectSolver()
                        {
                            WhichSolver = DirectSolver._whichSolver.MUMPS        //PARDISO
                        },
                        Overlap = 1
                    };
                }

                break;

            case LinearSolverCodes.exp_AS_10000:
                if (Timestepper.MultigridSequence[0].SpatialDimension == 3)       //3D --> 212940DoF
                {
                    templinearSolve = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                        {
                            //noofparts = 22,
                            NoOfPartsPerProcess = 22,
                        },
                        CoarseSolver = new DirectSolver()
                        {
                            WhichSolver = DirectSolver._whichSolver.MUMPS        //PARDISO
                        },
                        Overlap = 1
                    };
                }
                else      //2D --> 75088DoF
                {
                    templinearSolve = new Schwarz()
                    {
                        m_BlockingStrategy = new Schwarz.METISBlockingStrategy()
                        {
                            //noofparts = 8,
                            NoOfPartsPerProcess = 22,     //
                        },
                        CoarseSolver = new DirectSolver()
                        {
                            WhichSolver = DirectSolver._whichSolver.MUMPS        //PARDISO
                        },
                        Overlap = 1
                    };
                }

                break;

            case LinearSolverCodes.exp_AS_MG:
                templinearSolve = new Schwarz()
                {
                    m_BlockingStrategy = new Schwarz.MultigridBlocks()
                    {
                        //depth = asdepth,
                        Depth = 2,
                    },
                    CoarseSolver = new DirectSolver()
                    {
                        WhichSolver = DirectSolver._whichSolver.MUMPS        //PARDISO
                    },

                    Overlap = 1
                };
                break;


            case LinearSolverCodes.exp_localPrec:
                templinearSolve = new LocalizedOperatorPrec()
                {
                    m_dt  = Control.GetFixedTimestep(),
                    m_muA = Control.PhysicalParameters.mu_A,
                };
                break;

            default:
                throw new NotImplementedException("Linear solver option not available");
            }

            // Set nonlinear Solver
            switch (Control.NonlinearSolve)
            {
            case NonlinearSolverCodes.NewtonGMRES:
                Timestepper.Config_NonlinearSolver = NonlinearSolverMethod.NewtonGMRES;
                Timestepper.Config_linearSolver    = templinearSolve;
                break;

            case NonlinearSolverCodes.Picard:
                Timestepper.Config_NonlinearSolver = NonlinearSolverMethod.Picard;
                Timestepper.Config_linearSolver    = templinearSolve;
                break;

            case NonlinearSolverCodes.Newton:
                Timestepper.Config_NonlinearSolver = NonlinearSolverMethod.Newton;
                Timestepper.Config_linearSolver    = templinearSolve;
                break;

            case NonlinearSolverCodes.PicardGMRES:
                Timestepper.Config_NonlinearSolver = NonlinearSolverMethod.Picard;
                Timestepper.Config_linearSolver    = new SoftGMRES()
                {
                    MaxKrylovDim    = Timestepper.Config_MaxKrylovDim,
                    m_Tolerance     = Timestepper.Config_SolverConvergenceCriterion,
                    Precond         = templinearSolve,
                    m_MaxIterations = Timestepper.Config_MaxIterations,
                };
                break;

            default:
                throw new NotImplementedException("Nonlinear solver option not available");
            }
        }