示例#1
0
 /// <summary>
 /// Test on a square 2D Voronoi mesh
 /// </summary>
 /// <param name="Res">
 /// number of randomly chosen Delaunay vertices
 /// </param>
 /// <param name="deg">
 /// polynomial degree
 /// </param>
 /// <param name="NoOfLlyodsIter">
 /// Number of Llyods iterations.
 /// </param>
 /// <param name="mirror">
 /// Mirror vertices of boundary cells along boundary to approximate boundary
 /// </param>
 /// <param name="solver_name">
 /// Name of solver to use.
 /// </param>
 /// <returns></returns>
 public static SipControl TestVoronoi_Square(
     int Res,
     int deg                        = 1,
     int NoOfLlyodsIter             = 10,
     bool mirror                    = false,
     LinearSolverCode solver_name   = LinearSolverCode.classic_pardiso,
     Foundation.IO.IDatabaseInfo db = null)
 {
     return(TestGrid(new VoronoiGrids.Square(Res, NoOfLlyodsIter), deg, solver_name, db));
 }
示例#2
0
        /// <summary>
        /// A spherical interface in the 3D domain \f$ (-2, 2)^3 \f$.
        /// </summary>
        public static XdgPoisson3Control Ball3D(int pDeg, int Res, LinearSolverCode solverCode)
        {
            XdgPoisson3Control R = new XdgPoisson3Control();

            R.ProjectName = "XdgPoisson3/Ball3D";
            R.savetodb    = false;

            R.FieldOptions.Add("Phi", new FieldOpts()
            {
                Degree   = 1,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            R.FieldOptions.Add("u", new FieldOpts()
            {
                Degree   = pDeg,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });

            R.GridFunc = delegate() {
                return(Grid3D.Cartesian3DGrid(GenericBlas.Linspace(-2, 2, Res), GenericBlas.Linspace(-2, 2, Res), GenericBlas.Linspace(-2, 2, Res)));
            };


            // set the level-set
            R.InitialValues_Evaluators.Add("Phi", X => (X[0].Pow2() + X[1].Pow2() + X[2].Pow2()) - 1.0.Pow2());
            //R.InitialValues.Add("Phi", X => X[0] + 0.1);
            R.ExcactSolSupported = false;
            //R.InitialValues.Add("uEx#A", X => X[1]);
            //R.InitialValues.Add("uEx#B", X => X[1]);
            R.InitialValues_Evaluators.Add("rhs#A", X => 1.0);
            R.InitialValues_Evaluators.Add("rhs#B", X => 1.0);


            R.MU_A = -1.0;
            R.MU_B = -1.0;

            R.xLaplaceBCs.g_Diri      = ((CommonParamsBnd inp) => 0.0);
            R.xLaplaceBCs.IsDirichlet = (inp => true);

            R.LinearSolver.SolverCode = solverCode;//R.solverName = "direct";
            R.AgglomerationThreshold  = 0.1;
            R.PrePreCond         = MultigridOperator.Mode.DiagBlockEquilib;
            R.penalty_multiplyer = 1.1;
            R.ViscosityMode      = XLaplace_Interface.Mode.SIP;

            return(R);
        }
示例#3
0
        //Base case for Voronoi Testing
        static SipControl TestGrid(
            VoronoiGrid grid,
            int deg = 1,
            LinearSolverCode solver_name   = LinearSolverCode.classic_pardiso,
            Foundation.IO.IDatabaseInfo db = null)
        {
            var R = new SipControl
            {
                ProjectName = "SipPoisson-Voronoi",
                SessionName = "testrun"
            };

            R.ImmediatePlotPeriod = 1;
            if (db != null)
            {
                R.savetodb = true;
                R.SetDatabase(db);
            }

            R.FieldOptions.Add("T", new FieldOpts()
            {
                Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            R.FieldOptions.Add("Tex", new FieldOpts()
            {
                Degree = deg * 2
            });
            R.InitialValues_Evaluators.Add("RHS", X => 1.0);
            R.InitialValues_Evaluators.Add("Tex", X => X[0]);
            R.ExactSolution_provided           = false;
            R.LinearSolver.NoOfMultigridLevels = int.MaxValue;
            R.LinearSolver.SolverCode          = solver_name;
            R.LinearSolver.NoOfMultigridLevels = 1;
            //R.TargetBlockSize = 100;

            grid.SetGridAndBoundaries(R);
            return(R);
        }
示例#4
0
        /// <summary>
        /// Solution of the system
        /// <see cref="LaplaceMtx"/>*<see cref="T"/> + <see cref="LaplaceAffine"/> = <see cref="RHS"/>
        /// using a black-box solver
        /// </summary>
        private void ClassicSolve(out double mintime, out double maxtime, out bool Converged, out int NoOfIter)
        {
            mintime   = double.MaxValue;
            maxtime   = double.MinValue;
            Converged = false;
            NoOfIter  = int.MaxValue;

            for (int i = 0; i < base.Control.NoOfSolverRuns; i++)
            {
                // create sparse solver
                // --------------------
                ISparseSolver    ipSolver;
                LinearSolverCode solvercodes = LinearSolverCode.classic_pardiso;

                switch (solvercodes)
                {
                case LinearSolverCode.classic_pardiso:
                    ipSolver = new ilPSP.LinSolvers.PARDISO.PARDISOSolver()
                    {
                        CacheFactorization = true,
                        UseDoublePrecision = true
                    };
                    break;

                case LinearSolverCode.classic_mumps:
                    ipSolver = new ilPSP.LinSolvers.MUMPS.MUMPSSolver();
                    break;

                case LinearSolverCode.classic_cg:
                    ipSolver = new ilPSP.LinSolvers.monkey.CG()
                    {
                        MaxIterations = 1000000,
                        Tolerance     = 1.0e-10,
                        DevType       = ilPSP.LinSolvers.monkey.DeviceType.Cuda
                    };
                    break;

                default:
                    throw new ArgumentException();
                }
                ipSolver.DefineMatrix(LaplaceMtx);

                // call solver
                // -----------
                T.Clear();

                Console.WriteLine("RUN " + i + ": solving system...");

                var RHSvec = RHS.CoordinateVector.ToArray();
                BLAS.daxpy(RHSvec.Length, -1.0, this.LaplaceAffine, 1, RHSvec, 1);

                T.Clear();
                SolverResult solRes = ipSolver.Solve(T.CoordinateVector, RHSvec);
                mintime = Math.Min(solRes.RunTime.TotalSeconds, mintime);
                maxtime = Math.Max(solRes.RunTime.TotalSeconds, maxtime);

                Converged = solRes.Converged;
                NoOfIter  = solRes.NoOfIterations;

                Console.WriteLine("Pardiso phase 11: " + ilPSP.LinSolvers.PARDISO.PARDISOSolver.Phase_11.Elapsed.TotalSeconds);
                Console.WriteLine("Pardiso phase 22: " + ilPSP.LinSolvers.PARDISO.PARDISOSolver.Phase_22.Elapsed.TotalSeconds);
                Console.WriteLine("Pardiso phase 33: " + ilPSP.LinSolvers.PARDISO.PARDISOSolver.Phase_33.Elapsed.TotalSeconds);

                ipSolver.Dispose();
            }
        }
示例#5
0
        /// <summary>
        /// A circular interface in the 2D domain \f$ (3/2,3/2)^2 \f$.
        /// </summary>
        public static XdgPoisson3Control Circle(int Resolution = 16, int p = 1, string DBPath = null, LinearSolverCode solver = LinearSolverCode.classic_pardiso)
        {
            XdgPoisson3Control R = new XdgPoisson3Control();

            R.ProjectName = "XdgPoisson3/Circle";
            if (DBPath == null)
            {
                R.savetodb = false;
            }
            else
            {
                R.savetodb = false;
                R.DbPath   = DBPath;
            }


            R.FieldOptions.Add("Phi", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            R.FieldOptions.Add("u", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });

            R.GridFunc = delegate() {
                return(Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1.5, 1.5, Resolution), GenericBlas.Linspace(-1.5, 1.5, Resolution)));
            };


            double RADIUS = 0.8;

            R.InitialValues_Evaluators.Add("Phi", X => - X[0].Pow2() - X[1].Pow2() + (RADIUS).Pow2());

            R.ExcactSolSupported = false;
            R.InitialValues_Evaluators.Add("uEx#A", X => 0.0);
            R.InitialValues_Evaluators.Add("uEx#B", X => 0.0);
            R.InitialValues_Evaluators.Add("u#A", X => 0.0);
            R.InitialValues_Evaluators.Add("u#B", X => 0.0);
            R.InitialValues_Evaluators.Add("rhs#A", X => + 1.0);
            R.InitialValues_Evaluators.Add("rhs#B", X => + 1.0);

            R.MU_A = -1.0;
            R.MU_B = -1000.0;

            R.xLaplaceBCs.g_Diri      = (X => 0.0);
            R.xLaplaceBCs.IsDirichlet = (inp => true);

            R.LinearSolver.SolverCode = solver;
            R.LinearSolver.SolverCode = LinearSolverCode.exp_softpcg_mg;

            R.dtMax         = 0.1;
            R.dtMin         = 0.1;
            R.NoOfTimesteps = 10;
            R.Endtime       = 100000.0;

            R.AgglomerationThreshold           = 0.1;
            R.PrePreCond                       = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;
            R.LinearSolver.NoOfMultigridLevels = 5;


            return(R);
        }
示例#6
0
        /// <summary>
        /// A circular interface in the 2D domain \f$ (3/2,3/2)^2 \f$.
        /// </summary>
        public static XdgPoisson3Control Circle(int Resolution = 16, int p = 1, string DBPath = null, LinearSolverCode solver = LinearSolverCode.classic_pardiso)
        {
            //BoSSS.Application.XdgPoisson3.HardCodedControl.Circle(Resolution: 8);

            XdgPoisson3Control R = new XdgPoisson3Control();

            R.ProjectName = "XdgPoisson3/Circle";
            if (DBPath == null)
            {
                R.savetodb = false;
            }
            else
            {
                R.savetodb = false;
                R.DbPath   = DBPath;
            }


            R.SetDGdegree(p);

            R.GridFunc = delegate() {
                return(Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1.5, 1.5, Resolution + 1), GenericBlas.Linspace(-1.5, 1.5, Resolution + 1)));
            };


            double RADIUS = 0.8;

            R.InitialValues_Evaluators.Add("Phi", X => - (X[0] - 0.0).Pow2() - (X[1] - 0.0).Pow2() + (RADIUS).Pow2());

            R.ExcactSolSupported = false;
            R.InitialValues_Evaluators.Add("uEx#A", X => 0.0);
            R.InitialValues_Evaluators.Add("uEx#B", X => 0.0);
            R.InitialValues_Evaluators.Add("u#A", X => 0.0);
            R.InitialValues_Evaluators.Add("u#B", X => 0.0);
            R.InitialValues_Evaluators.Add("rhs#A", X => + 1.0);
            R.InitialValues_Evaluators.Add("rhs#B", X => + 1.0);

            R.MU_A = -1.0;
            R.MU_B = -1000.0;

            R.xLaplaceBCs.g_Diri      = (X => 0.0);
            R.xLaplaceBCs.IsDirichlet = (inp => true);

            R.LinearSolver.SolverCode = solver;
            R.LinearSolver.SolverCode = LinearSolverCode.classic_pardiso;

            R.TimesteppingMode = AppControl._TimesteppingMode.Steady;

            R.AgglomerationThreshold           = 0.1;
            R.PrePreCond                       = MultigridOperator.Mode.SymPart_DiagBlockEquilib;
            R.LinearSolver.NoOfMultigridLevels = 5;


            return(R);
        }
示例#7
0
        /// <summary>
        /// Test on a Cartesian grid, with a sinusodial solution.
        /// </summary>
        /// <param name="Res">
        /// Grid resolution
        /// </param>
        /// <param name="Dim">
        /// spatial dimension
        /// </param>
        /// <param name="deg">
        /// polynomial degree
        /// </param>
        /// <param name="solver_name">
        /// Name of solver to use.
        /// </param>
        public static SipControl TestCartesian2(int Res, int Dim, LinearSolverCode solver_name = LinearSolverCode.exp_Kcycle_schwarz, int deg = 5)
        {
            //BoSSS.Application.SipPoisson.SipHardcodedControl.TestCartesian2(8,3,deg:2)


            if (Dim != 2 && Dim != 3)
            {
                throw new ArgumentOutOfRangeException();
            }

            var R = new SipControl();

            R.ProjectName = "ipPoison/cartesian";
            R.savetodb    = false;

            R.FieldOptions.Add("T", new FieldOpts()
            {
                Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            R.FieldOptions.Add("Tex", new FieldOpts()
            {
                Degree = deg + 2
            });
            R.InitialValues_Evaluators.Add("RHS", X => - Math.Sin(X[0]));
            R.InitialValues_Evaluators.Add("Tex", X => Math.Sin(X[0]));
            R.ExactSolution_provided           = true;
            R.LinearSolver.NoOfMultigridLevels = int.MaxValue;
            R.LinearSolver.SolverCode          = solver_name;
            // exp_Kcycle_schwarz
            // exp_gmres_levelpmg

#if DEBUG
            // For testing in DEBUG mode, this setting enforces the use
            // of many multigrid-levels. In 2D, the examples are so small that
            R.LinearSolver.TargetBlockSize = 100;
#endif


            R.GridFunc = delegate() {
                GridCommons grd = null;
                if (Dim == 2)
                {
                    double[] xNodes = GenericBlas.Linspace(0, 10, Res * 5 + 1);
                    double[] yNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1);

                    grd = Grid2D.Cartesian2DGrid(xNodes, yNodes);
                }
                else if (Dim == 3)
                {
                    double[] xNodes = GenericBlas.Linspace(0, 10, Res * 5 + 1);
                    //double[] yNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1);
                    //double[] zNodes = GenericBlas.SinLinSpacing(-1, +1, 0.6, Res + 1);
                    double[] yNodes = GenericBlas.Linspace(-1, +1, Res + 1);
                    double[] zNodes = GenericBlas.Linspace(-1, +1, Res + 1);

                    grd = Grid3D.Cartesian3DGrid(xNodes, yNodes, zNodes);
                }
                else
                {
                    throw new NotSupportedException();
                }
                grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString());
                grd.EdgeTagNames.Add(2, BoundaryType.Neumann.ToString());
                grd.DefineEdgeTags(delegate(double[] X) {
                    byte ret;
                    double x = X[0];
                    if (Math.Abs(x - 0.0) <= 1.0e-8)
                    {
                        ret = 1; // Dirichlet
                    }
                    else
                    {
                        ret = 2; // Neumann
                    }
                    return(ret);
                });

                return(grd);
            };

            R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T",
                               delegate(double[] X) {
                double x = X[0], y = X[1];


                return(Math.Sin(x));
                //if (Math.Abs(X[0] - (0.0)) < 1.0e-8)
                //    return 0.0;

                //throw new ArgumentOutOfRangeException();
            });

            R.AddBoundaryValue(BoundaryType.Neumann.ToString(), "T",
                               delegate(double[] X) {
                double x = X[0], y = X[1], z = X.Length > 2 ? X[2] : 0.0;

                if (Math.Abs(y - 1.0) < 1.0e-8 || Math.Abs(y + 1.0) < 1.0e-8)      // y = -1, y = +1
                {
                    return(0);
                }

                if (X.Length > 2 && (Math.Abs(z - 1.0) < 1.0e-8 || Math.Abs(z + 1.0) < 1.0e-8))      // z = -1, z = +1
                {
                    return(0);
                }

                //if (Math.Abs(X[0] - (+10.0)) < 1.0e-8)
                return(Math.Cos(x));

                //throw new ArgumentOutOfRangeException();
            });
            return(R);
        }
示例#8
0
        public static SipControl ConvergenceTest(int Res = 20, int Dim = 2, LinearSolverCode solver_name = LinearSolverCode.exp_Kcycle_schwarz, int deg = 1)
        {
            if (Dim != 2 && Dim != 3)
            {
                throw new ArgumentOutOfRangeException();
            }

            var R = new SipControl();

            R.ProjectName = "ipPoison/cartesian";
            R.savetodb    = false;

            R.FieldOptions.Add("T", new FieldOpts()
            {
                Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            R.FieldOptions.Add("Tex", new FieldOpts()
            {
                Degree = deg + 2
            });
            R.InitialValues_Evaluators.Add("RHS", X => - 1.0); // constant force i.e. gravity
            R.ExactSolution_provided           = false;        //true;
            R.LinearSolver.NoOfMultigridLevels = int.MaxValue;
            R.LinearSolver.SolverCode          = solver_name;
            R.LinearSolver.MaxSolverIterations = 200;
            R.LinearSolver.TargetBlockSize     = 10000;
            R.LinearSolver.MaxKrylovDim        = 2000;



            R.GridFunc = delegate() {
                GridCommons grd = null;
                if (Dim == 2)
                {
                    double[] xNodes = GenericBlas.Linspace(-10, 10, Res * 5 + 1);
                    double[] yNodes = GenericBlas.Linspace(-10, 10, Res * 5 + 1);
                    grd = Grid2D.Cartesian2DGrid(xNodes, yNodes);
                }
                else
                {
                    throw new NotSupportedException();
                }

                grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString());
                grd.DefineEdgeTags(delegate(double[] X) {
                    byte ret;

                    ret = 1; // all dirichlet
                    return(ret);
                });

                return(grd);
            };

            R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T",
                               delegate(double[] X) {
                double x = X[0], y = X[1];
                return(0.0);
            });

            return(R);
        }