Esempio n. 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,
     LinearSolverConfig.Code solver_name = LinearSolverConfig.Code.classic_pardiso,
     Foundation.IO.IDatabaseInfo db      = null)
 {
     return(TestGrid(new VoronoiGrids.Square(Res, NoOfLlyodsIter), deg, solver_name, db));
 }
Esempio n. 2
0
        //Base case for Voronoi Testing
        static SipControl TestGrid(
            VoronoiGrid grid,
            int deg = 1,
            LinearSolverConfig.Code solver_name = LinearSolverConfig.Code.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);
        }
Esempio n. 3
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, LinearSolverConfig.Code solver = LinearSolverConfig.Code.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 = LinearSolverConfig.Code.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);
        }
Esempio n. 4
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, LinearSolverConfig.Code solver_name = LinearSolverConfig.Code.exp_softpcg_schwarz_directcoarse, int deg = 3)
        {
            if (Dim != 2 && Dim != 3)
            {
                throw new ArgumentOutOfRangeException();
            }

            var R = new SipControl();

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

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



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

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

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

                return(grd);
            };

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

                if (Math.Abs(X[0] - (0.0)) < 1.0e-8)
                {
                    return(0.0);
                }

                throw new ArgumentOutOfRangeException();
            });

            R.AddBoundaryValue(BoundaryType.Neumann.ToString(), "T",
                               delegate(double[] X)
            {
                if (Math.Abs(X[1] - 1.0) < 1.0e-8 || Math.Abs(X[1] + 1.0) < 1.0e-8)      // y = -1, y = +1
                {
                    return(0);
                }

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

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

                throw new ArgumentOutOfRangeException();
            });
            return(R);
        }