/// <summary> /// Poisson Equation on a (-1,1)x(-1,1), Dirichlet everywhere /// </summary> public static SipControl Square(int xRes = 5, int yRes = 5, int deg = 5) { //Func<double[], double> exRhs = X => 2 * X[0] * X[0] + 2 * X[1] * X[1] - 4; //Func<double[], double> exSol = X => (1.0 - X[0] * X[0]) * (1.0 - X[1] * X[1]); //Func<double[], double> exSol = X => (1.0 - X[1]); //Func<double[], double> exRhs = X => 0.0; Func <double[], double> exSol = X => - Math.Cos(X[0] * Math.PI * 0.5) * Math.Cos(X[1] * Math.PI * 0.5); Func <double[], double> exRhs = X => (Math.PI * Math.PI * 0.5 * Math.Cos(X[0] * Math.PI * 0.5) * Math.Cos(X[1] * Math.PI * 0.5)); // == - /\ exSol var R = new SipControl(); R.ProjectName = "ipPoison/square"; R.savetodb = false; //R.DbPath = "D:\\BoSSS-db"; R.FieldOptions.Add("T", new FieldOpts() { Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = 4 }); R.InitialValues_Evaluators.Add("RHS", exRhs); R.InitialValues_Evaluators.Add("Tex", exSol); R.ExactSolution_provided = true; //R.LinearSolver.NoOfMultigridLevels = 2; //R.LinearSolver.SolverCode = LinearSolverCode.exp_softpcg_mg; R.LinearSolver.SolverCode = LinearSolverCode.exp_softpcg_schwarz_directcoarse; R.SuppressExceptionPrompt = true; //R.LinearSolver.SolverCode = LinearSolverCode.classic_mumps; R.GridFunc = delegate() { double[] xNodes = GenericBlas.Linspace(-1, 1, xRes); double[] yNodes = GenericBlas.Linspace(-1, 1, yRes); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.DefineEdgeTags(delegate(double[] X) { byte ret = 1; return(ret); }); return(grd); }; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", exSol); R.NoOfSolverRuns = 1; R.AdaptiveMeshRefinement = true; R.NoOfTimesteps = 5; return(R); }
/// <summary> /// Test on a curved grid. /// </summary> public static SipControl TestCurved() { var R = new SipControl(); R.ProjectName = "ipPoison/curved"; R.savetodb = false; R.FieldOptions.Add("T", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = 15 }); R.InitialValues_Evaluators.Add("RHS", X => 0.0); R.InitialValues_Evaluators.Add("Tex", X => (Math.Log(X[0].Pow2() + X[1].Pow2()) / Math.Log(4.0)) + 1.0); R.ExactSolution_provided = true; R.GridFunc = delegate() { var grd = Grid2D.CurvedSquareGrid(GenericBlas.Linspace(1, 2, 3), GenericBlas.Linspace(0, 1, 11), CellType.Square_9, true); grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.DefineEdgeTags(X => 1); return(grd); }; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", delegate(double[] X) { double x = X[0], y = X[1]; return(Math.Sqrt(x * x + y * y)); }); return(R); }
/// <summary> /// Test on a Cartesian grid, with an exact polynomial solution. /// </summary> public static SipControl TestCartesian1(int xRes = 32, double xStretch = 1.0, int yRes = 16, double yStretch = 1.01, int pDG = 2) { //BoSSS.Application.SipPoisson.SipHardcodedControl.TestCartesian1() var RR = new SipControl(); RR.ProjectName = "ipPoison/cartesian"; RR.savetodb = false; RR.FieldOptions.Add("T", new FieldOpts() { Degree = pDG, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); RR.FieldOptions.Add("Tex", new FieldOpts() { Degree = pDG * 2 }); RR.InitialValues_Evaluators.Add("RHS", X => 1.0); RR.InitialValues_Evaluators.Add("Tex", X => (0.5 * X[0].Pow2() - 10 * X[0])); RR.ExactSolution_provided = true; RR.GridFunc = delegate() { double[] xNodes = CreateNodes(xRes, xStretch, 0, 10); double[] yNodes = CreateNodes(yRes, yStretch, -1, +1); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); 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); }; RR.AddBoundaryValue(BoundaryType.Dirichlet.ToString()); RR.AddBoundaryValue(BoundaryType.Neumann.ToString()); RR.GridPartType = BoSSS.Foundation.Grid.GridPartType.none; return(RR); }
public static SipControl JumpingSquare(int xRes = 5, int yRes = 5, int deg = 3) { var R = new SipControl(); R.ProjectName = "ipPoison/square"; R.savetodb = false; R.FieldOptions.Add("T", new FieldOpts() { Degree = deg }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = 4 }); R.InitialValues_Evaluators.Add("RHS", X => 0.0); R.InitialValues_Evaluators.Add("Tex", X => 0.1); R.ExactSolution_provided = true; R.SuppressExceptionPrompt = true; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", X => { if (X[0] > 0.9999) { return(0.1); } else { return(0.1); } }); R.NoOfSolverRuns = 1; R.AdaptiveMeshRefinement = true; R.NoOfTimesteps = 1; R.ImmediatePlotPeriod = 1; R.SuperSampling = 2; R.GridFunc = delegate() { double[] xNodes = GenericBlas.Linspace(-1, 1, xRes); double[] yNodes = GenericBlas.Linspace(-1, 1, yRes); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.DefineEdgeTags(delegate(double[] X) { byte ret = 1; return(ret); }); return(grd); }; return(R); }
/// <summary> /// Poisson Equation on a (-1,1)x(-1,1), Dirichlet everywhere /// </summary> public static SipControl Square(int xRes = 21, int yRes = 16, int deg = 5) { //Func<double[], double> exRhs = X => 2 * X[0] * X[0] + 2 * X[1] * X[1] - 4; //Func<double[], double> exSol = X => (1.0 - X[0] * X[0]) * (1.0 - X[1] * X[1]); //Func<double[], double> exSol = X => (1.0 - X[1]); //Func<double[], double> exRhs = X => 0.0; Func <double[], double> exSol = X => - Math.Cos(X[0] * Math.PI * 0.5) * Math.Cos(X[1] * Math.PI * 0.5); Func <double[], double> exRhs = X => (Math.PI * Math.PI * 0.5 * Math.Cos(X[0] * Math.PI * 0.5) * Math.Cos(X[1] * Math.PI * 0.5)); // == - /\ exSol var R = new SipControl(); R.ProjectName = "ipPoison/square"; R.savetodb = false; //R.DbPath = "D:\\BoSSS-db"; R.FieldOptions.Add("T", new FieldOpts() { Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = 4 }); R.InitialValues_Evaluators.Add("RHS", exRhs); R.InitialValues_Evaluators.Add("Tex", exSol); R.ExactSolution_provided = true; R.GridFunc = delegate() { double[] xNodes = GenericBlas.Linspace(-1, 1, xRes); double[] yNodes = GenericBlas.Linspace(-1, 1, yRes); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.DefineEdgeTags(delegate(double[] X) { byte ret = 1; return(ret); }); return(grd); }; R.AddBoundaryCondition(BoundaryType.Dirichlet.ToString(), "T", exSol); R.NoOfSolverRuns = 1; return(R); }
/// <summary> /// Test on a Cartesian grid, with an exact polynomial solution. /// </summary> public static SipControl TestCartesian3D(int xRes = 32, double xStretch = 1.0, int yRes = 16, double yStretch = 1.0, int zRes = 16, double zStretch = 1.0) { var R = new SipControl(); R.ProjectName = "ipPoison/cartesian"; R.savetodb = false; R.FieldOptions.Add("T", new FieldOpts() { Degree = 6, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = 6 }); R.InitialValues_Evaluators.Add("RHS", X => 1.0); R.InitialValues_Evaluators.Add("Tex", X => (0.5 * X[0].Pow2() - 10 * X[0])); R.ExactSolution_provided = true; R.GridFunc = delegate() { double[] xNodes = CreateNodes(xRes, xStretch, 0, 10); double[] yNodes = CreateNodes(yRes, yStretch, -1, +1); double[] zNodes = CreateNodes(zRes, zStretch, -1, +1); var grd = Grid3D.Cartesian3DGrid(xNodes, yNodes, zNodes); grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.EdgeTagNames.Add(2, BoundaryType.Neumann.ToString()); grd.DefineEdgeTags(delegate(double[] X) { byte ret; if (Math.Abs(X[0] - 0.0) <= 1.0e-6) { ret = 1; } else { ret = 2; } return(ret); }); return(grd); }; R.AddBoundaryCondition(BoundaryType.Dirichlet.ToString()); R.AddBoundaryCondition(BoundaryType.Neumann.ToString()); return(R); }
/// <summary> /// Poisson Equation on a (-1,1)x(-1,1), Dirichlet everywhere /// </summary> public static SipControl RegularSquare(int xRes = 5, int yRes = 5, int deg = 2) { Func <double[], double> exSol = X => - Math.Cos(X[0] * Math.PI * 0.5) * Math.Cos(X[1] * Math.PI * 0.5); Func <double[], double> exRhs = X => (Math.PI * Math.PI * 0.5 * Math.Cos(X[0] * Math.PI * 0.5) * Math.Cos(X[1] * Math.PI * 0.5)); // == - /\ exSol var R = new SipControl(); R.ProjectName = "ipPoison/square"; R.savetodb = false; R.FieldOptions.Add("T", new FieldOpts() { Degree = deg }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = 4 }); R.InitialValues_Evaluators.Add("RHS", exRhs); R.InitialValues_Evaluators.Add("Tex", exSol); R.ExactSolution_provided = true; R.SuppressExceptionPrompt = true; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", exSol); R.NoOfSolverRuns = 1; R.AdaptiveMeshRefinement = true; R.NoOfTimesteps = 1; R.ImmediatePlotPeriod = 1; R.SuperSampling = 2; R.GridFunc = delegate() { double[] xNodes = GenericBlas.Linspace(-1, 1, xRes); double[] yNodes = GenericBlas.Linspace(-1, 1, yRes); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.DefineEdgeTags(delegate(double[] X) { byte ret = 1; return(ret); }); return(grd); }; return(R); }
public static SipControl VoronoiSquare(int res = 50, int deg = 2) { var R = new SipControl { ProjectName = "SipPoisson-Voronoi", SessionName = "testrun", ImmediatePlotPeriod = 1, SuperSampling = 2, savetodb = false, ExactSolution_provided = 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 => X[0] * X[0]); R.InitialValues_Evaluators.Add("Tex", X => X[0]); Func <double[], double> dirichletBoundary = X => 0.0; // X => Math.Pow(X[0], 2) + Math.Pow(X[1], 2); R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", dirichletBoundary); R.GridFunc = delegate(){ Vector[] DomainBndyPolygon = new[] { new Vector(-1, 1), new Vector(1, 1), new Vector(1, -1), new Vector(-1, -1) }; AggregationGrid grid; grid = BoSSS.Foundation.Grid.Voronoi.VoronoiGrid2D.Polygonal(DomainBndyPolygon, 10, res); grid.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grid.DefineEdgeTags((double[] X) => (byte)1); return(grid); }; return(R); }
//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); }
/// <summary> /// Test on a Cartesian grid, with an exact polynomial solution. /// </summary> public static SipControl TestCartesian3D(int PowRes = 5, int DGdegree = 1, string blapath = null, int xRes = 2, double xStretch = 1.0, int yRes = 2, double yStretch = 1.0, int zRes = 2, double zStretch = 1.0) { xRes = (int)Math.Pow(xRes, PowRes); yRes = (int)Math.Pow(yRes, PowRes); zRes = (int)Math.Pow(zRes, PowRes); var R = new SipControl(); R.ProjectName = "ipPoison/cartesian"; R.savetodb = false; R.WriteMeSomeAnalyse = @"D:\Analysis\CCpoisson\Study0_vary_Mlevel_n_blocks\"; R.FieldOptions.Add("T", new FieldOpts() { Degree = DGdegree, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = DGdegree }); R.InitialValues_Evaluators.Add("RHS", X => 1.0); R.InitialValues_Evaluators.Add("Tex", X => (0.5 * X[0].Pow2() - 10 * X[0])); R.ExactSolution_provided = true; R.GridFunc = delegate() { double[] xNodes = CreateNodes(xRes, xStretch, 0, 10); //double[] xNodes = CreateNodes(xRes, xStretch, -1, +1); double[] yNodes = CreateNodes(yRes, yStretch, -1, +1); //double[] zNodes = CreateNodes(zRes, zStretch, -1, +1); //var grd = Grid3D.Cartesian3DGrid(xNodes, yNodes, zNodes); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); 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.LinearSolver.SolverCode = LinearSolverConfig.Code.exp_softpcg_jacobi_mg; R.LinearSolver.SolverCode = LinearSolverConfig.Code.exp_decomposedMG_OrthoScheme; //R.LinearSolver.SolverCode = LinearSolverConfig.Code.classic_mumps; R.LinearSolver.NoOfMultigridLevels = 10; R.LinearSolver.TargetBlockSize = 40; //R.LinearSolver.MaxSolverIterations = 1; //R.LinearSolver.MaxSolverIterations = 10; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString()); R.AddBoundaryValue(BoundaryType.Neumann.ToString()); return(R); }
/// <summary> /// Test on a 2D Voronoi mesh /// </summary> /// <param name="Res"> /// number of randomly chosen Delaunay vertices /// </param> /// <param name="deg"> /// polynomial degree /// </param> /// <param name="solver_name"> /// Name of solver to use. /// </param> public static SipControl TestVoronoi(int Res, SolverCodes solver_name = SolverCodes.classic_pardiso, int deg = 3) { if (System.Environment.MachineName.ToLowerInvariant().EndsWith("rennmaschin") //|| System.Environment.MachineName.ToLowerInvariant().Contains("jenkins") ) { // This is Florians Laptop; // he is to poor to afford MATLAB, so he uses OCTAVE BatchmodeConnector.Flav = BatchmodeConnector.Flavor.Octave; BatchmodeConnector.MatlabExecuteable = "C:\\cygwin64\\bin\\bash.exe"; } var R = new SipControl(); R.ProjectName = "SipPoisson-Voronoi"; R.SessionName = "testrun"; 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); R.InitialValues_Evaluators.Add("Tex", X => 0.0); R.ExactSolution_provided = false; R.NoOfMultigridLevels = int.MaxValue; R.solver_name = solver_name; //R.TargetBlockSize = 100; bool IsIn(params double[] X) { Debug.Assert(X.Length == 2); double xi = X[0]; double yi = X[1]; //for(int l = 0; l < bndys.Length; l++) { // Debug.Assert(bndys[l].Normal.Length == 2); // if (bndys[l].PointDistance(xi, yi) > 0.0) // return false; //} if (xi > 1.0) { return(false); } if (yi > 1.0) { return(false); } if (xi < 0 && yi < 0) { return(false); } if (xi < -1) { return(false); } if (yi < -1) { return(false); } return(true); } int Mirror(ref double[] _x, ref double[] _y, AffineManifold[] bndys) { if (_x.Length != _y.Length) { throw new ArgumentException(); } var x = _x.ToList(); var y = _y.ToList(); int N = _x.Length; // filter all points that are outside of the domain for (int n = 0; n < N; n++) { if (!IsIn(x[n], y[n])) { x.RemoveAt(n); y.RemoveAt(n); N--; n--; } } Debug.Assert(x.Count == N); Debug.Assert(y.Count == N); for (int n = 0; n < N; n++) { Debug.Assert(IsIn(x[n], y[n])); } // mirror each point for (int n = 0; n < N; n++) { double xn = x[n]; double yn = y[n]; for (int l = 0; l < bndys.Length; l++) { var bndy_l = bndys[l]; double dist = bndy_l.PointDistance(xn, yn); if (dist < 0) { double xMirr = xn - bndy_l.Normal[0] * dist * 2; double yMirr = yn - bndy_l.Normal[1] * dist * 2; Debug.Assert(bndy_l.PointDistance(xMirr, yMirr) > 0); if (!IsIn(xMirr, yMirr)) { x.Add(xMirr); y.Add(yMirr); } } } } // return _x = x.ToArray(); _y = y.ToArray(); return(N); } GridCommons GridFunc() { GridCommons grd = null; var Matlab = new BatchmodeConnector(); // boundaries for L-domain AffineManifold[] Boundaries = new AffineManifold[6]; Boundaries[0] = new AffineManifold(new[] { 0.0, 1.0 }, new[] { 0.0, 1.0 }); Boundaries[1] = new AffineManifold(new[] { 1.0, 0.0 }, new[] { 1.0, 0.0 }); Boundaries[2] = new AffineManifold(new[] { -1.0, 0.0 }, new[] { -1.0, 0.0 }); Boundaries[3] = new AffineManifold(new[] { -1.0, 0.0 }, new[] { 0.0, 0.0 }); Boundaries[4] = new AffineManifold(new[] { 0.0, -1.0 }, new[] { 0.0, -1.0 }); Boundaries[5] = new AffineManifold(new[] { 0.0, -1.0 }, new[] { 0.0, 0.0 }); // generate Delaunay vertices Random rnd = new Random(0); double[] xNodes = Res.ForLoop(idx => rnd.NextDouble() * 2 - 1); double[] yNodes = Res.ForLoop(idx => rnd.NextDouble() * 2 - 1); int ResFix = Mirror(ref xNodes, ref yNodes, Boundaries); var Nodes = MultidimensionalArray.Create(xNodes.Length, 2); Nodes.SetColumn(0, xNodes); Nodes.SetColumn(1, yNodes); Matlab.PutMatrix(Nodes, "Nodes"); // compute Voronoi diagramm Matlab.Cmd("[V, C] = voronoin(Nodes);"); // output (export from matlab) int[][] OutputVertexIndex = new int[Nodes.NoOfRows][]; Matlab.GetStaggeredIntArray(OutputVertexIndex, "C"); Matlab.GetMatrix(null, "V"); // run matlab Matlab.Execute(false); // import here MultidimensionalArray VertexCoordinates = (MultidimensionalArray)(Matlab.OutputObjects["V"]); // correct indices (1-based index to 0-based index) foreach (int[] cell in OutputVertexIndex) { int K = cell.Length; for (int k = 0; k < K; k++) { cell[k]--; } } // tessellation List <Cell> cells = new List <Cell>(); List <int[]> aggregation = new List <int[]>(); for (int jV = 0; jV < ResFix; jV++) // loop over Voronoi Cells { Debug.Assert(IsIn(Nodes.GetRow(jV))); int[] iVtxS = OutputVertexIndex[jV]; int NV = iVtxS.Length; List <int> Agg2Pt = new List <int>(); for (int iTri = 0; iTri < NV - 2; iTri++) // loop over triangles of voronoi cell { int iV0 = iVtxS[0]; int iV1 = iVtxS[iTri + 1]; int iV2 = iVtxS[iTri + 2]; double[] V0 = VertexCoordinates.GetRow(iV0); double[] V1 = VertexCoordinates.GetRow(iV1); double[] V2 = VertexCoordinates.GetRow(iV2); double[] D1 = V1.Minus(V0); double[] D2 = V2.Minus(V0); Debug.Assert(D1.CrossProduct2D(D2).Abs() > 1.0e-8); if (D1.CrossProduct2D(D2) < 0) { double[] T = V2; int t = iV2; V2 = V1; iV2 = iV1; V1 = T; iV1 = t; } double[] Center = V0.Plus(V1).Plus(V2).Mul(1.0 / 3.0); //Debug.Assert(IsIn(Center[0], Center[1])); Cell Cj = new Cell(); Cj.GlobalID = cells.Count; Cj.Type = CellType.Triangle_3; Cj.TransformationParams = MultidimensionalArray.Create(3, 2); Cj.NodeIndices = new int[] { iV0, iV1, iV2 }; Cj.TransformationParams.SetRow(0, V0); Cj.TransformationParams.SetRow(1, V1); Cj.TransformationParams.SetRow(2, V2); Agg2Pt.Add(cells.Count); cells.Add(Cj); } aggregation.Add(Agg2Pt.ToArray()); } // return grid grd = new Grid2D(Triangle.Instance); grd.Cells = cells.ToArray(); grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.DefineEdgeTags(X => (byte)1); //grd.Plot2DGrid(); // create aggregation grid //var agrd = new AggregationGrid(grd, aggregation.ToArray()); return(grd); }; R.GridFunc = GridFunc; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", delegate(double[] X) { //double x = X[0], y = X[1]; return(0.0); //if(Math.Abs(X[0] - (0.0)) < 1.0e-8) // return 0.0; // //throw new ArgumentOutOfRangeException(); }); return(R); }
/* * * /// <summary> * /// Test on a 2D Voronoi mesh * /// </summary> * /// <param name="Res"> * /// number of randomly chosen Delaunay vertices * /// </param> * /// <param name="deg"> * /// polynomial degree * /// </param> * /// <param name="solver_name"> * /// Name of solver to use. * /// </param> * public static SipControl TestVoronoiOld(int Res, SolverCodes solver_name = SolverCodes.classic_pardiso, int deg = 3) { * * if (System.Environment.MachineName.ToLowerInvariant().EndsWith("rennmaschin") * //|| System.Environment.MachineName.ToLowerInvariant().Contains("jenkins") * ) { * // This is Florians Laptop; * // he is to poor to afford MATLAB, so he uses OCTAVE * BatchmodeConnector.Flav = BatchmodeConnector.Flavor.Octave; * BatchmodeConnector.MatlabExecuteable = "C:\\cygwin64\\bin\\bash.exe"; * } * * * var R = new SipControl(); * R.ProjectName = "SipPoisson-Voronoi"; * R.SessionName = "testrun"; * 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); * R.InitialValues_Evaluators.Add("Tex", X => 0.0); * R.ExactSolution_provided = false; * R.NoOfMultigridLevels = int.MaxValue; * R.solver_name = solver_name; * //R.TargetBlockSize = 100; * * * * * bool IsIn(double xi, double yi) { * * //for(int l = 0; l < bndys.Length; l++) { * // Debug.Assert(bndys[l].Normal.Length == 2); * // if (bndys[l].PointDistance(xi, yi) > 0.0) * // return false; * //} * if (xi > 1.0) * return false; * if (yi > 1.0) * return false; * if (xi < 0 && yi < 0) * return false; * if (xi < -1) * return false; * if (yi < -1) * return false; * * return true; * } * * bool IsInV(Vector X) { * Debug.Assert(X.Dim == 2); * return IsIn(X.x, X.y); * } * * int Mirror(ref double[] _x, ref double[] _y, AffineManifold[] bndys) { * if (_x.Length != _y.Length) * throw new ArgumentException(); * var x = _x.ToList(); * var y = _y.ToList(); * int N = _x.Length; * * * * // filter all points that are outside of the domain * for (int n = 0; n < N; n++) { * if (!IsIn(x[n], y[n])) { * x.RemoveAt(n); * y.RemoveAt(n); * N--; * n--; * } * } * Debug.Assert(x.Count == N); * Debug.Assert(y.Count == N); * for (int n = 0; n < N; n++) { * Debug.Assert(IsIn(x[n], y[n])); * } * * // mirror each point * for(int n = 0; n < N; n++) { * double xn = x[n]; * double yn = y[n]; * for(int l = 0; l < bndys.Length; l++) { * var bndy_l = bndys[l]; * * double dist = bndy_l.PointDistance(xn, yn); * * if(dist < 0) { * double xMirr = xn - bndy_l.Normal[0] * dist*2; * double yMirr = yn - bndy_l.Normal[1] * dist*2; * * Debug.Assert(bndy_l.PointDistance(xMirr, yMirr) > 0); * * if(!IsIn(xMirr, yMirr)) { * x.Add(xMirr); * y.Add(yMirr); * } * } * } * } * * // return * _x = x.ToArray(); * _y = y.ToArray(); * return N; * } * * * IGrid GridFunc() { * GridCommons grd = null; * * var Matlab = new BatchmodeConnector(); * * // boundaries for L-domain * AffineManifold[] Boundaries = new AffineManifold[6]; * Boundaries[0] = new AffineManifold(new[] { 0.0, 1.0 }, new[] { 0.0, 1.0 }); * Boundaries[1] = new AffineManifold(new[] { 1.0, 0.0 }, new[] { 1.0, 0.0 }); * Boundaries[2] = new AffineManifold(new[] { -1.0, 0.0 }, new[] { -1.0, 0.0 }); * Boundaries[3] = new AffineManifold(new[] { -1.0, 0.0 }, new[] { 0.0, 0.0 }); * Boundaries[4] = new AffineManifold(new[] { 0.0, -1.0 }, new[] { 0.0, -1.0 }); * Boundaries[5] = new AffineManifold(new[] { 0.0, -1.0 }, new[] { 0.0, 0.0 }); * * * // generate Delaunay vertices * Random rnd = new Random(0); * double[] xNodes = Res.ForLoop(idx => rnd.NextDouble()*2 - 1); * double[] yNodes = Res.ForLoop(idx => rnd.NextDouble()*2 - 1); * int ResFix = Mirror(ref xNodes, ref yNodes, Boundaries); * * * var Nodes = MultidimensionalArray.Create(xNodes.Length, 2); * Nodes.SetColumn(0, xNodes); * Nodes.SetColumn(1, yNodes); * * Matlab.PutMatrix(Nodes, "Nodes"); * * // compute Voronoi diagramm * Matlab.Cmd("[V, C] = voronoin(Nodes);"); * * // output (export from matlab) * int[][] OutputVertexIndex = new int[Nodes.NoOfRows][]; * Matlab.GetStaggeredIntArray(OutputVertexIndex, "C"); * Matlab.GetMatrix(null, "V"); * * // run matlab * Matlab.Execute(false); * * // import here * MultidimensionalArray VertexCoordinates = (MultidimensionalArray)(Matlab.OutputObjects["V"]); * * // correct indices (1-based index to 0-based index) * foreach(int[] cell in OutputVertexIndex) { * int K = cell.Length; * for (int k = 0; k < K; k++) { * cell[k]--; * } * } * * // tessellation * List<Cell> cells = new List<Cell>(); * List<int[]> aggregation = new List<int[]>(); * for(int jV = 0; jV < ResFix; jV++) { // loop over Voronoi Cells * Debug.Assert(IsInV(Nodes.GetRowPt(jV))); * * int[] iVtxS = OutputVertexIndex[jV]; * int NV = iVtxS.Length; * * List<int> Agg2Pt = new List<int>(); * * for(int iTri = 0; iTri < NV - 2; iTri++) { // loop over triangles of voronoi cell * int iV0 = iVtxS[0]; * int iV1 = iVtxS[iTri + 1]; * int iV2 = iVtxS[iTri + 2]; * * Vector V0 = VertexCoordinates.GetRowPt(iV0); * Vector V1 = VertexCoordinates.GetRowPt(iV1); * Vector V2 = VertexCoordinates.GetRowPt(iV2); * * double[] D1 = V1 - V0; * double[] D2 = V2 - V0; * Debug.Assert(D1.CrossProduct2D(D2).Abs() > 1.0e-8); * if(D1.CrossProduct2D(D2) < 0) { * Vector T = V2; * int t = iV2; * V2 = V1; * iV2 = iV1; * V1 = T; * iV1 = t; * } * * //double[] Center = V0.Plus(V1).Plus(V2).Mul(1.0 / 3.0); * //Debug.Assert(IsIn(Center[0], Center[1])); * * Cell Cj = new Cell(); * Cj.GlobalID = cells.Count; * Cj.Type = CellType.Triangle_3; * Cj.TransformationParams = MultidimensionalArray.Create(3, 2); * Cj.NodeIndices = new int[] { iV0, iV1, iV2 }; * Cj.TransformationParams.SetRowPt(0, V0); * Cj.TransformationParams.SetRowPt(1, V1); * Cj.TransformationParams.SetRowPt(2, V2); * * Agg2Pt.Add(cells.Count); * * cells.Add(Cj); * } * * aggregation.Add(Agg2Pt.ToArray()); * } * * // return grid * grd = new Grid2D(Triangle.Instance); * grd.Cells = cells.ToArray(); * grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); * grd.DefineEdgeTags(X => (byte)1); * * //grd.Plot2DGrid(); * * // create aggregation grid * var agrd = new AggregationGrid(grd, aggregation.ToArray()); * return agrd; * * }; * R.GridFunc = GridFunc; * * R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", * delegate (double[] X) { * //double x = X[0], y = X[1]; * * return 0.0; * //if(Math.Abs(X[0] - (0.0)) < 1.0e-8) * // return 0.0; * // * //throw new ArgumentOutOfRangeException(); * }); * * * * * * return R; * } * * //*/ /// <summary> /// Test on a 2D Voronoi mesh /// </summary> /// <param name="Res"> /// number of randomly chosen Delaunay vertices /// </param> /// <param name="deg"> /// polynomial degree /// </param> /// <param name="solver_name"> /// Name of solver to use. /// </param> /// <param name="mirror"> /// use vertex mirroring at boundary to make a large fraction of the Voronoi cells conformal /// </param> /// <param name="NoOfLlyodsIter"> /// Number of iterations for Llyod's algorithm (aka. Voronoi relaxation) /// </param> public static SipControl TestVoronoi(int Res, SolverCodes solver_name = SolverCodes.classic_pardiso, int deg = 1, bool mirror = true, double NoOfLlyodsIter = 0) { if (System.Environment.MachineName.ToLowerInvariant().EndsWith("rennmaschin") //|| System.Environment.MachineName.ToLowerInvariant().Contains("jenkins") ) { // This is Florians Laptop; // he is to poor to afford MATLAB, so he uses OCTAVE BatchmodeConnector.Flav = BatchmodeConnector.Flavor.Octave; //BatchmodeConnector.MatlabExecuteable = "C:\\cygwin64\\bin\\bash.exe"; } var R = new SipControl(); R.ProjectName = "SipPoisson-Voronoi"; R.SessionName = "testrun"; 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 => 0.0);// -1.0 + X[0] * X[0]); R.InitialValues_Evaluators.Add("Tex", X => X[0]); R.ExactSolution_provided = false; R.NoOfMultigridLevels = int.MaxValue; R.solver_name = solver_name; R.NoOfMultigridLevels = 1; //R.TargetBlockSize = 100; bool IsIn(double xi, double yi) { //for(int l = 0; l < bndys.Length; l++) { // Debug.Assert(bndys[l].Normal.Length == 2); // if (bndys[l].PointDistance(xi, yi) > 0.0) // return false; //} if (xi > 1.0) { return(false); } if (yi > 1.0) { return(false); } if (xi < 0 && yi < 0) { return(false); } if (xi < -1) { return(false); } if (yi < -1) { return(false); } return(true); } Vector[] DomainBndyPolygon = new[] { new Vector(+0, +0), new Vector(-1, +0), new Vector(-1, +1), new Vector(+1, +1), new Vector(+1, -1), new Vector(+0, -1) }; //*/ /* * bool IsIn(double xi, double yi) { * double myEps = 0.0; * if (xi > 1.0 + myEps) * return false; * if (yi > 1.0 + myEps) * return false; * if (xi < -1 - myEps) * return false; * if (yi < -1 - myEps) * return false; * * return true; * } * * * * Vector[] DomainBndyPolygon = new[] { * new Vector(-1,+1), * new Vector(+1,+1), * new Vector(+1,-1), * new Vector(-1,-1) * }; * //*/ bool IsInV(Vector X) { Debug.Assert(X.Dim == 2); return(IsIn(X.x, X.y)); } bool Idenity(Vector A, Vector B) { bool t2 = (A - B).AbsSquare() < 1.0e-10; bool t1 = (A - B).AbsSquare() < 1.0e-15; //Debug.Assert(t1 == t2); //Voronoi.VoronoiMeshGen.AccuracyFlag = (t1 == t2); return(t2); } IGrid GridFunc() { // generate Delaunay vertices Random rnd = new Random(0); int RR = Res; var Node = MultidimensionalArray.Create(RR, 2); bool useMirror = mirror; double scl = useMirror ? 2.0 : 4.0; int cmt = 0; while (cmt < Res) { double nx = rnd.NextDouble() * scl - 0.5 * scl; double ny = rnd.NextDouble() * scl - 0.5 * scl; if (IsIn(nx, ny)) { Node[cmt, 0] = nx; Node[cmt, 1] = ny; cmt++; } } // generate mesh return(Voronoi.VoronoiMeshGen.FromPolygonalDomain(Node, DomainBndyPolygon, useMirror, NoOfLlyodsIter, IsInV, Idenity)); }; R.GridFunc = GridFunc; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", delegate(double[] X) { //double x = X[0], y = X[1]; return(X[0]); //if(Math.Abs(X[0] - (0.0)) < 1.0e-8) // return 0.0; // //throw new ArgumentOutOfRangeException(); }); return(R); }
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); }
/// <summary> /// Test channel flow around a cylinder (half domain with symmetry condition) /// </summary> public static SipControl ConfinedCylinder(int k = 3) { var C = new SipControl(); #region other settings // Miscellaneous Solver Settings C.ExactSolution_provided = false; C.savetodb = false; C.DbPath = @"D:\bosss_db_masterthesis"; C.ProjectName = "ConfinedCylinderipPoisson"; C.SessionName = "Confined Cylinder MG with ipPoisson"; //C.WriteMeSomeAnalyse = @"C:\Users\Matth\Desktop"; #endregion #region grid instantiation // GUID's to confined cylinder grids (half) List <string> grids = new List <string>(); grids.Add("a8370a9b-86b6-4dda-8147-b30f897b2320"); grids.Add("462f3f2e-8cd9-4563-a62f-191629ffd155"); grids.Add("6270aeda-0ae8-4197-939b-4018cd9500fe"); grids.Add("f97ff88f-8980-4760-ba54-76bd7071cdbd"); /*grids.Add("0f6132db-a263-4140-b0b4-cca275f3af3c");*/ //half_0 /*grids.Add("282f25a2-bb4e-4549-96c6-e5d8d806a607");*/ //half_1 /*grids.Add("e174a74c-d2fc-40a1-af12-a16356264911");*/ //half_2 /*grids.Add("de43ee58-c3b3-41bd-9df3-7deb883de36b");*/ //half_3 Guid gridGuid; if (Guid.TryParse(grids[1], out gridGuid)) { C.GridGuid = gridGuid; } else { throw new ArgumentException(); } #endregion #region dgfields and bc // Setup DGFields C.FieldOptions.Add("T", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); C.FieldOptions.Add("Tex", new FieldOpts() { Degree = k, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); // Boundary Values C.AddBoundaryValue("Dirichlet_inlet", "T", "X => 0", false); C.AddBoundaryValue("Dirichlet_top", "T", "X => 0", false); C.AddBoundaryValue("Dirichlet_outlet", "T", "X => 0", false); C.AddBoundaryValue("Dirichlet_bottom", "T", "X => 0", false); C.AddBoundaryValue("Dirichlet_cylinder", "T", "X => -10", false); #endregion #region RHS //Func<double[], double> exRhs = X => -1; //C.InitialValues_Evaluators.Add("RHS", exRhs); #endregion #region linear solver config // Linear Solver Settings C.LinearSolver.MaxKrylovDim = 5000; C.LinearSolver.MaxSolverIterations = 50; C.LinearSolver.NoOfMultigridLevels = 5; C.LinearSolver.SolverCode = LinearSolverCode.exp_Kcycle_schwarz; C.LinearSolver.TargetBlockSize = 10000; C.LinearSolver.SolverMode = LinearSolverMode.Solve; C.SuperSampling = 2; C.LinearSolver.ConvergenceCriterion = 1E-8; //C.LinearSolver.SolverMode = LinearSolverMode.SpectralAnalysis; #endregion return(C); }
/// <summary> /// Test on a Cartesian grid, with a sinusodial solution. /// </summary> /// <param name="Res"> /// Grid resolution /// </param> /// <param name="Dim"> /// spatial dimension /// </param> /// <param name="deg"> /// polynomial degree /// </param> /// <param name="solver_name"> /// Name of solver to use. /// </param> public static SipControl TestCartesian2(int Res, int Dim, 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); }
/// <summary> /// Adaptive mesh refinement on a manufactured solution /// </summary> public static SipControl RefinementManufactured(int xRes = 2, int yRes = 2, int deg = 3) { double RHS(double[] X) { double x = X[0]; double y = X[1]; return(0.001 * Math.Pow(y, 2) * Math.Pow(y - 1, 2) * Math.Exp(10 * Math.Pow(x, 2) + 10 * y) * (200 * Math.Pow(x, 6) - 400 * Math.Pow(x, 5) + 290 * Math.Pow(x, 4) - 140 * Math.Pow(x, 3) + 56 * Math.Pow(x, 2) - 6 * x + 1) + 0.001 * Math.Pow(x, 2) * Math.Pow(x - 1, 2) * Math.Exp(10 * Math.Pow(x, 2) + 10 * y) * (50 * Math.Pow(y, 4) - 60 * Math.Pow(y, 3) - 4 * Math.Pow(y, 2) + 14 * y + 1)); } double Tex(double[] X) { double x = X[0]; double y = X[1]; return(0.0005 * Math.Pow(x, 2) * Math.Pow(x - 1, 2) * Math.Pow(y, 2) * Math.Pow(y - 1, 2) * Math.Exp(10 * Math.Pow(x, 2) + 10 * y)); } Func <double[], double> exSol = Tex; Func <double[], double> exRhs = RHS; var R = new SipControl(); R.ProjectName = "ipPoison/hRefinementManufactured"; R.savetodb = false; //R.DbPath = "D:\\BoSSS-db"; R.FieldOptions.Add("T", new FieldOpts() { Degree = deg, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); R.FieldOptions.Add("Tex", new FieldOpts() { Degree = deg + 1 }); R.InitialValues_Evaluators.Add("RHS", exRhs); R.InitialValues_Evaluators.Add("Tex", exSol); R.ExactSolution_provided = true; //R.LinearSolver.NoOfMultigridLevels = 2; //R.LinearSolver.SolverCode = LinearSolverConfig.Code.exp_softpcg_mg; R.LinearSolver.SolverCode = LinearSolverConfig.Code.classic_pardiso; R.SuppressExceptionPrompt = true; //R.LinearSolver.SolverCode = LinearSolverConfig.Code.classic_mumps; R.GridFunc = delegate() { double[] xNodes = GenericBlas.Linspace(0, 1, xRes + 1); double[] yNodes = GenericBlas.Linspace(0, 1, yRes + 1); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); grd.EdgeTagNames.Add(1, BoundaryType.Dirichlet.ToString()); grd.DefineEdgeTags(delegate(double[] X) { byte ret = 1; return(ret); }); return(grd); }; R.AddBoundaryValue(BoundaryType.Dirichlet.ToString(), "T", exSol); R.NoOfSolverRuns = 1; R.AdaptiveMeshRefinement = true; R.NoOfTimesteps = 100; return(R); }
/// <summary> /// Test on a Cartesian grid, with a sinusodial solution. /// </summary> /// <param name="Res"> /// Grid resolution /// </param> /// <param name="Dim"> /// spatial dimension /// </param> /// <param name="deg"> /// polynomial degree /// </param> /// <param name="solver_name"> /// Name of solver to use. /// </param> public static SipControl TestCartesian2(int Res, int Dim, 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); }