override public MultidimensionalArray GetSurfacePoints(LevelSetTracker lsTrk, double[] PositionS, double AngleS) { int SpatialDim = lsTrk.GridDat.SpatialDimension; if (SpatialDim != 2) { throw new NotImplementedException("Only two dimensions are supported at the moment"); } double hMin = lsTrk.GridDat.iGeomCells.h_min.Min(); int NoOfSurfacePoints = Convert.ToInt32(5 * Circumference_P / hMin); MultidimensionalArray SurfacePoints = MultidimensionalArray.Create(NoOfSubParticles(), NoOfSurfacePoints, SpatialDim); double[] InfinitisemalAngle = GenericBlas.Linspace(0, Math.PI * 2, NoOfSurfacePoints + 1); if (Math.Abs(10 * Circumference_P / hMin + 1) >= int.MaxValue) { throw new ArithmeticException("Error trying to calculate the number of surface points, overflow"); } for (int j = 0; j < NoOfSurfacePoints; j++) { double temp0 = Math.Cos(InfinitisemalAngle[j]) * length_P; double temp1 = Math.Sin(InfinitisemalAngle[j]) * thickness_P; SurfacePoints[0, j, 0] = (temp0 * Math.Cos(AngleS) - temp1 * Math.Sin(AngleS)) + PositionS[0]; SurfacePoints[0, j, 1] = (temp0 * Math.Sin(AngleS) + temp1 * Math.Cos(AngleS)) + PositionS[1]; } return(SurfacePoints); }
/// <summary> /// Test using subsonicInlet at the inlet and /// supersonicInlet (Dirichlet) at the outlet /// </summary> /// <returns></returns> public static CNSControl[] EulerSubsonicInlet1D() { CNSControl[] templates = GetTemplates(); foreach (CNSControl c in templates) { int divisions = (int)c.Paramstudy_CaseIdentification.Single(t => t.Item1 == "divisions").Item2; int noOfCells = (2 << divisions) * 8; c.GridFunc = delegate { GridCommons grid = Grid1D.LineGrid( GenericBlas.Linspace(0.0, Math.PI / 2.0 + 0.0, noOfCells + 1)); grid.EdgeTagNames.Add(1, "supersonicInlet"); grid.EdgeTagNames.Add(2, "subsonicInlet"); grid.DefineEdgeTags((Vector x) => Math.Abs(x[0]) < 1e-14 ? (byte)2 : (byte)1); return(grid); }; c.ProjectName += "_subsonicInlet2"; c.AddBoundaryValue("subsonicInlet", CompressibleVariables.Density, exactDensity); c.AddBoundaryValue("subsonicInlet", CNSVariables.Velocity[0], exactVelocity); c.AddBoundaryValue("supersonicInlet", CompressibleVariables.Density, exactDensity); c.AddBoundaryValue("supersonicInlet", CNSVariables.Velocity[0], exactVelocity); c.AddBoundaryValue("supersonicInlet", CNSVariables.Pressure, exactPressure); } return(templates); }
public GridCommons GetGrid() { var grd = Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-2, 2, 7), GenericBlas.Linspace(-2, 2, 5)); grd.EdgeTagNames.Add(1, "wall_top"); grd.EdgeTagNames.Add(2, "Velocity_Inlet"); 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(y - (2)) < 1.0e-6) { return(1); } if (Math.Abs(y - (-2)) < 1.0e-6) { return(2); } return(3); }); return(grd); }
public static void Init() { //GridCommons grd = Grid2D.Cartesian2DGrid(RandomSpacing(), RandomSpacing()); //grid = new GridData(Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-7, 7, 8), GenericBlas.Linspace(-1, 1, 2))); //grid = new GridData(Grid2D.Cartesian2DGrid(new double[] { -6, -4, -2, 2, 4, 6 }, GenericBlas.Linspace(-1, 1, 2))); //if (curved) //{ // grid = Grid2D.CurvedSquareGrid(GenericBlas.Linspace(1, 2, 5), GenericBlas.Linspace(0, 1, 17), CellType.Square_9, true).GridData; //} //else //{ // grid = (Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1.5, 1.5, 17), GenericBlas.Linspace(-1.5, 1.5, 17))).GridData; //} grid = (Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1.5, 1.5, 17), GenericBlas.Linspace(-1.5, 1.5, 17))).GridData; MgSeq = CoarseningAlgorithms.CreateSequence(grid); for (int p = 0; p <= 3; p++) // loop over polynomial degrees... { var uMapping = new UnsetteledCoordinateMapping(new Basis(grid, p)); var MgMapSeq = new MultigridMapping[MgSeq.Length]; var BasisSeq = AggregationGridBasis.CreateSequence(MgSeq, uMapping.BasisS); for (int iLevel = 0; iLevel < MgSeq.Length; iLevel++) { MgMapSeq[iLevel] = new MultigridMapping(uMapping, BasisSeq[iLevel], new int[] { p }); } MultigrigMap.Add(p, MgMapSeq); } }
/// <summary> /// \f[ /// - \operatorname{div} \left( \mu (\partial_d \vec{u}) \right) /// \f] /// </summary> public double Term2(int d, double[] X) { if (d < 0 || d >= D) { throw new ArgumentOutOfRangeException(); } if (X.Length != D) { throw new ArgumentException(); } double _mu = this.mu(X); double[] _dmu = new double[D]; double[] _dU = new double[D]; double _ddU = 0; for (int j = 0; j < D; j++) { _dmu[j] = this.dmu(X, j); _dU[j] = this.dU(j, X, d); _ddU += this.ddU(j, X, d, j); } double ret = 0; ret += GenericBlas.InnerProd(_dmu, _dU); ret += _mu * _ddU; return(-ret); }
/// <summary> /// creates a simple 2d/3d Cartesian grid within the domain \f$ (-7,7)^D \f$ /// </summary> protected override GridCommons CreateOrLoadGrid() { /* * double[] xnodes = GenericBlas.Linspace(-7, 7, 11); * double[] ynodes = GenericBlas.Linspace(-7, 7, 11); * GridCommons grd = Grid2D.Cartesian2DGrid(xnodes, ynodes, type: CellType.Square_Linear); * this.Control.NoOfMultigridLevels = 3; * * return grd; * //*/ //double[] xnodes = GenericBlas.Linspace(-7, 7, 25); //double[] ynodes = GenericBlas.Linspace(-7, 7, 25); //double[] znodes = GenericBlas.Linspace(-7, 7, 25); //var grd = Grid3D.Cartesian3DGrid(xnodes, ynodes, znodes); double[] xNodes = GenericBlas.Linspace(-7, 7, 3); double[] yNodes = GenericBlas.Linspace(-7, 7, 3); var baseGrid = Grid2D.UnstructuredTriangleGrid(xNodes, yNodes); var baseGdat = new GridData(baseGrid); var aggGrid = CoarseningAlgorithms.Coarsen(baseGdat, 2); base.AggGrid = aggGrid; return(null); //*/ }
protected override IGrid CreateOrLoadGrid() { GridCommons grd; switch (TestCase) { case 1: { // ++++++++++++++++++ // affine-linear mesh // ++++++++++++++++++ double[] xNodes = GenericBlas.Linspace(-5, 5, 21); double[] yNodes = GenericBlas.Linspace(-5, 5, 21); grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); break; } case 2: { // +++++++++++ // curved mesh // +++++++++++ double[] xNodes = GenericBlas.Linspace(-5, 5, 21); double[] yNodes = GenericBlas.Linspace(-5, 5, 21); grd = Grid2D.BilinearSquareGrid(xNodes, yNodes, factor: 0.8); break; } default: throw new ArgumentException("unknown test-case index"); } return(grd); }
/// <summary> /// constructs an affine manifold from a set of points /// </summary> /// <param name="pts"> /// points on the manifold; /// 1st index: point index. /// 2nd index: spatial dimension. /// </param> static public AffineManifold FromPoints(params double[][] pts) { int D = pts.Length; for (int i = 0; i < D; i++) if (pts[i].Length != D) throw new ArgumentException(); var ret = new AffineManifold(D); switch (D) { case 2: ret.Normal[0] = -(pts[1][1] - pts[0][1]); ret.Normal[1] = +(pts[1][0] - pts[0][0]); break; case 3: double a_1 = pts[1][0] - pts[0][0]; double a_2 = pts[1][1] - pts[0][1]; double a_3 = pts[1][2] - pts[0][2]; double b_1 = pts[2][0] - pts[0][0]; double b_2 = pts[2][1] - pts[0][1]; double b_3 = pts[2][2] - pts[0][2]; ret.Normal[0] = a_2 * b_3 - a_3 * b_2; ret.Normal[1] = a_3 * b_1 - a_1 * b_3; ret.Normal[2] = a_1 * b_2 - a_2 * b_1; break; default: throw new NotSupportedException(); } ret.a = GenericBlas.InnerProd(ret.Normal, pts[0]); return ret; }
/// <summary> /// Finds the node on the edge that corresponds to the node in the cell (InputNode). /// </summary> /// <param name="InputNode"></param>Node in cell. /// <param name="edgesOfCell"></param> Array of surrounding edges /// <param name="signMod"></param>sign of Phi/LevelSet /// <returns></returns> int[] findCorrelatingNode(Node InputNode, Edge[] edgesOfCell, double signMod) { double[] inputNode = InputNode.NodePosition; double[] EdgeNode = new double[2]; int[] selectedNode = new int[2]; // {edge, No of node} double dist_min = double.MaxValue; double dist; // find closest point: brute force approach // loop over all edges with known values for (int i = 0; i < numberOfUsedEdges; i++) { // loop over all nodes on this edge for (int i_EdgeNode = 0; i_EdgeNode < edgesOfCell[i].noOfEdgeNodes; i_EdgeNode++) { EdgeNode[0] = edgesOfCell[i].EdgeNodesGlobal[i_EdgeNode, 0]; EdgeNode[1] = edgesOfCell[i].EdgeNodesGlobal[i_EdgeNode, 1]; double phi = edgesOfCell[i].PhiEdgeEvalBuffer[0, i_EdgeNode]; phi *= signMod; dist = GenericBlas.L2Dist(EdgeNode, inputNode) + phi; if (dist < dist_min) { dist_min = dist; selectedNode[0] = i; selectedNode[1] = i_EdgeNode; } } } return(selectedNode); }
/// <summary> /// constructs an affine manifold from a set of points /// </summary> /// <param name="pts"> /// points on the manifold; /// 1st index: point index. /// 2nd index: spatial dimension. /// </param> static public AffineManifold FromPoints(MultidimensionalArray pts) { int D = pts.GetLength(1); var ret = new AffineManifold(D); switch (D) { case 2: ret.Normal[0] = -(pts[1, 1] - pts[0, 1]); ret.Normal[1] = +(pts[1, 0] - pts[0, 0]); break; case 3: double a_1 = pts[1, 0] - pts[0, 0]; double a_2 = pts[1, 1] - pts[0, 1]; double a_3 = pts[1, 2] - pts[0, 2]; double b_1 = pts[2, 0] - pts[0, 0]; double b_2 = pts[2, 1] - pts[0, 1]; double b_3 = pts[2, 2] - pts[0, 2]; ret.Normal[0] = a_2 * b_3 - a_3 * b_2; ret.Normal[1] = a_3 * b_1 - a_1 * b_3; ret.Normal[2] = a_1 * b_2 - a_2 * b_1; break; default: throw new NotSupportedException(); } double[] Offset = pts.ExtractSubArrayShallow(0, -1).To1DArray(); ret.a = GenericBlas.InnerProd(ret.Normal, Offset); return ret; }
/// <summary> /// equality check: tests if two objects represent the same affine manifold/plane /// </summary> public bool Equals(object _other, double RelTol) { var other = _other as AffineManifold; if (other == null) throw new ArgumentException(); if (other.Normal.Length != this.Normal.Length) throw new ArgumentException(); double l1 = GenericBlas.L2NormPow2(this.Normal); double l2 = GenericBlas.L2NormPow2(other.Normal); double Tol = (l1 + l2) * RelTol; var inner_prod = GenericBlas.InnerProd(this.Normal, other.Normal); double cos_alpha = inner_prod / Math.Sqrt(l1*l2); if (Math.Abs(Math.Abs(cos_alpha) - 1) > 1.0E-12) // Normals not parallel -> manifolds can't be equal return false; //double offset = inner_prod/(this.a*other.a); double defect = inner_prod - (other.a / this.a) * l1; if (Math.Abs(defect) > Tol) // manifolds don't intersect return false; return true; }
public double LevelSetForm(ref CommonParamsLs cp, double[] U_Neg, double[] U_Pos, double[,] Grad_uA, double[,] Grad_uB, double v_Neg, double v_Pos, double[] Grad_vA, double[] Grad_vB) { double uAxN = GenericBlas.InnerProd(U_Neg, cp.n); var parameters_P = m_getParticleParams(cp.x, cp.time); double[] uLevSet = new double[] { parameters_P[0], parameters_P[1] }; double wLevSet = parameters_P[2]; pRadius = parameters_P[3]; double scale = parameters_P[4]; // double scale = parameters_P[4]; double[] _uLevSet = new double[D]; _uLevSet[0] = uLevSet[0] + pRadius * wLevSet * -cp.n[1]; _uLevSet[1] = uLevSet[1] + pRadius * wLevSet * cp.n[0]; double uBxN = GenericBlas.InnerProd(_uLevSet, cp.n); // transform from species B to A: we call this the "A-fictitious" value double uAxN_fict; uAxN_fict = uBxN; double FlxNeg = -DirichletFlux(uAxN, uAxN_fict); // flux on A-side //double FlxPos = 0; return(FlxNeg * v_Neg); }
public override IGrid GetGrid(IDatabaseInfo db) { switch (GridType) { case GridTypes.Structured: return(Grid3D.Cartesian3DGrid( GenericBlas.Linspace(-2.0, 2.0, 2), GenericBlas.Linspace(-1.0, 1.0, 2), GenericBlas.Linspace(-1.0, 1.0, 2))); //return Grid3D.Cartesian3DGrid( // GenericBlas.Linspace(0.0, 2.0, 2), // GenericBlas.Linspace(-1.0, 1.0, 2), // GenericBlas.Linspace(-1.0, 1.0, 2)); //return Grid3D.Cartesian3DGrid( // GenericBlas.Linspace(0.0, 4.0, 2), // GenericBlas.Linspace(-1.0, 1.0, 3), // GenericBlas.Linspace(-1.0, 1.0, 4)); case GridTypes.Unstructured: throw new NotImplementedException(); default: throw new ArgumentException(); } }
public void PeriodicPairCheckerBoard() { // ### Grid byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 1, "AdiabaticSlipWall" }, { 181, "Periodic-X" } }; var gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(1, 0.5), EdgeTags = tags, EdgeTagNames = tagNames }; double[] xTics = GenericBlas.Linspace(-0.5, 0.5, 3); double[] yTics = GenericBlas.Linspace(-0.25, 0.25, 5); for (int i = 0; i < yTics.Length; ++i) { yTics[i] *= -1; } MultidimensionalArray nodes = Checkerize(xTics, yTics); VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); Plotter.Plot(grid); }
/// <summary> /// creates a simple 2d/3d Cartesian grid within the domain \f$ (-7,7)^D \f$ /// </summary> protected override IGrid CreateOrLoadGrid() { /* * double[] xnodes = GenericBlas.Linspace(-7, 7, 11); * double[] ynodes = GenericBlas.Linspace(-7, 7, 11); * GridCommons grd = Grid2D.Cartesian2DGrid(xnodes, ynodes, type: CellType.Square_Linear); * this.Control.NoOfMultigridLevels = 3; * * return grd; * //*/ //double[] xnodes = GenericBlas.Linspace(-7, 7, 25); //double[] ynodes = GenericBlas.Linspace(-7, 7, 25); //double[] znodes = GenericBlas.Linspace(-7, 7, 25); //var grd = Grid3D.Cartesian3DGrid(xnodes, ynodes, znodes); double[] xNodes = GenericBlas.Linspace(-7, 7, 3); double[] yNodes = GenericBlas.Linspace(-7, 7, 3); var baseGrid = Grid2D.UnstructuredTriangleGrid(xNodes, yNodes); return(baseGrid); //*/ }
/// <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); }
static RefineAndLoadBalControl OnlyBalancing() { RefineAndLoadBalControl C = new RefineAndLoadBalControl(); //C.InitialValues.Add("LevelSet", ) C.GridFunc = delegate() { double[] nodes = GenericBlas.Linspace(-5, 5, 21); var grd = Grid2D.Cartesian2DGrid(nodes, nodes); return(grd); }; double s = 1.0; C.LevelSet = (double[] X, double t) => - (X[0] - s * t).Pow2() - X[1].Pow2() + (2.4).Pow2(); C.GridPartType = GridPartType.none; C.DynamicLoadBalancing_ImbalanceThreshold = 0.0; C.DynamicLoadBalancing_Period = 3; C.NoOfTimesteps = 20; C.dtFixed = 0.1; return(C); }
static public XDGTestControl AllUpTestControl() { var ctrl = new XDGTestControl(); ctrl.SetDGdegree(2); ctrl.InitialValues_Evaluators.Add("Phi", XDGTestMain.Phi0); ctrl.InitialValues_Evaluators.Add("Pressure#A", XDGTestMain.PressureExactA); ctrl.InitialValues_Evaluators.Add("Pressure#B", XDGTestMain.PressureExactB); ctrl.GridFunc = delegate() { var xNodes = GenericBlas.Linspace(-0.33333, 0.666667, 7); var yNodes = GenericBlas.Linspace(-1, 1, 13); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); return(grd); }; //ctrl.ImmediatePlotPeriod = 1; //ctrl.SuperSampling = 3; ctrl.TimesteppingMode = Solution.Control.AppControl._TimesteppingMode.Transient; ctrl.dtFixed = 1.0; ctrl.NoOfTimesteps = 1; return(ctrl); }
public GridCommons CreateGrid() { var xNodes = GenericBlas.Linspace(-1.5, 1.5, 19); var yNodes = GenericBlas.Linspace(-1.5, 1.5, 19); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); grd.EdgeTagNames.Add(1, "wall_top"); grd.EdgeTagNames.Add(2, "wall_bottom"); grd.EdgeTagNames.Add(3, "velocity_inlet_pos"); grd.EdgeTagNames.Add(4, "velocity_inlet_neg"); grd.DefineEdgeTags(delegate(double[] X) { double x = X[0], y = X[1]; if (Math.Abs(x - (-1.5)) <= 1.0e-7) // velocity inlet return (byte)3; if (Math.Abs(x - (1.5)) <= 1.0e-7) // velocity inlet ( return (byte)4; if (Math.Abs(y - (-1.5)) <= 1.0e-7) // bottom wall return (byte)2; if (Math.Abs(y - (+1.5)) <= 1.0e-7) // top wall return (byte)1; throw new ArgumentOutOfRangeException(); }); return grd; }
static public XDGTestControl RestartTest_FirstControl(string DbPath, out int[] ExpectedTimeSteps) { var ctrl = new XDGTestControl(); ctrl.SetDGdegree(2); ctrl.InitialValues_Evaluators.Add("Phi", XDGTestMain.Phi0); ctrl.InitialValues_Evaluators.Add("Pressure#A", XDGTestMain.PressureExactA); ctrl.InitialValues_Evaluators.Add("Pressure#B", XDGTestMain.PressureExactB); ctrl.GridFunc = delegate() { var xNodes = GenericBlas.Linspace(-1.0 / 3.0, 10.0 / 3.0, 11 * 3 + 1); var yNodes = GenericBlas.Linspace(-1, 1, 6 * 2 + 1); var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes); //Guid GridGuid = TestDb.Controller.DBDriver.SaveGrid(grd, TestDb); return(grd); }; //ctrl.ImmediatePlotPeriod = 1; //ctrl.SuperSampling = 3; ctrl.TimesteppingMode = Solution.Control.AppControl._TimesteppingMode.Transient; ctrl.dtFixed = 0.1; ctrl.NoOfTimesteps = 10; ctrl.DbPath = DbPath; ctrl.saveperiod = 5; ctrl.rollingSaves = false; ExpectedTimeSteps = new int[] { 0, 4, 5, 9, 10 }; return(ctrl); }
//static void Main(string[] args) { // BoSSS.Solution.Application._Main(args, false, null, () => new VortexRock4()); //} protected override IGrid CreateOrLoadGrid() { int NumOfCells = 4; double[] xnodes1 = GenericBlas.Linspace(-10, -5, NumOfCells + 1); double[] xnodes2 = GenericBlas.Linspace(-5, 5, 4 * NumOfCells + 1); double[] xnodes3 = GenericBlas.Linspace(5, 10, NumOfCells + 1); double[] xComplete = new double[xnodes1.Length + xnodes2.Length + xnodes3.Length - 2]; for (int i = 0; i < xnodes1.Length; i++) { xComplete[i] = xnodes1[i]; } for (int i = 1; i < xnodes2.Length; i++) { xComplete[i + xnodes1.Length - 1] = xnodes2[i]; } for (int i = 1; i < xnodes3.Length; i++) { xComplete[i + xnodes1.Length + xnodes2.Length - 2] = xnodes3[i]; } GridCommons grd = Grid2D.Cartesian2DGrid(xComplete, xComplete, CellType.Square_Linear, true, true); grd.Description = "2D cartesian grid 10x10 cells"; return(grd); }
/// <summary> /// Returns an array with points on the surface of the particle. /// </summary> /// <param name="hMin"> /// Minimal cell length. Used to specify the number of surface points. /// </param> override public MultidimensionalArray GetSurfacePoints(double hMin, double searchAngle, int subParticleID) { if (SpatialDim != 2) { throw new NotImplementedException("Only two dimensions are supported at the moment"); } int NoOfSurfacePoints = Convert.ToInt32(20 * Circumference / hMin) + 1; MultidimensionalArray SurfacePoints = MultidimensionalArray.Create(NoOfSubParticles, NoOfSurfacePoints, SpatialDim); double[] InfinitisemalAngle = GenericBlas.Linspace(-Math.PI / 4, 5 * Math.PI / 4, NoOfSurfacePoints + 1); double[] InfinitisemalLength = GenericBlas.Linspace(0, m_Length / 4, NoOfSurfacePoints + 1); if (Math.Abs(10 * Circumference / hMin + 1) >= int.MaxValue) { throw new ArithmeticException("Error trying to calculate the number of surface points, overflow"); } for (int k = 0; k < NoOfSurfacePoints; k++) { SurfacePoints[0, k, 0] = Motion.GetPosition(0)[0] + m_Length / 2 - InfinitisemalLength[k]; SurfacePoints[0, k, 1] = Motion.GetPosition(0)[1] - m_Length / 2 + 1.5 * SurfacePoints[0, k, 0] + m_Length / 2; } for (int j = 0; j < NoOfSurfacePoints; j++) { SurfacePoints[0, j, 0] = Math.Sign(Math.Cos(InfinitisemalAngle[j])) * m_Length * 7 + Motion.GetPosition(0)[0] + 7 * m_Length / 4; SurfacePoints[0, j, 1] = Math.Sign(Math.Sin(InfinitisemalAngle[j])) * m_Length * 7 + Motion.GetPosition(0)[1] + 7 * m_Length / 2; } for (int j = 0; j < NoOfSurfacePoints; j++) { SurfacePoints[1, j, 0] = -Math.Sign(Math.Cos(InfinitisemalAngle[j])) * m_Length * 2.5 + Motion.GetPosition(0)[0]; SurfacePoints[1, j, 1] = -Math.Sign(Math.Sin(InfinitisemalAngle[j])) * m_Length * 2.5 + Motion.GetPosition(0)[1]; } return(SurfacePoints); }
/// <summary> /// creates exponentially distributed nodes between two points /// </summary> /// <param name="loBound">minimum;</param> /// <param name="hiBound">maximum;</param> /// <param name="N">number of nodes, i.e. length of the returend array</param> /// <param name="alpha"> /// stretching; must be grater than 0; if grater than one distribution of points gets finer /// around <paramref name="loBound"/> and if smaller it becomes coarser. /// </param> /// <returns></returns> static public double[] ExponentialSpaceing(double loBound, double hiBound, int N, double alpha) { if (loBound >= hiBound) { throw new ArgumentException("loBound >= hiBound"); } if (alpha < 0.0) { throw new ArgumentException("stretching out of range."); } if (Math.Abs(alpha - 1.0) <= 0.0001) { return(GenericBlas.Linspace(loBound, hiBound, N)); } else { double[] ret = new double[N]; N--; for (int i = 0; i <= N; i++) { ret[i] = loBound + ((Math.Pow(alpha, i) - 1.0) / (Math.Pow(alpha, N) - 1.0)) * (hiBound - loBound); } return(ret); } }
protected override GridCommons CreateOrLoadGrid() { double[] xnodes1 = GenericBlas.Linspace(-1, 0, a1 + 1); double[] xnodes2 = GenericBlas.Linspace(0, 0.5, a2 + 1); double[] xnodes3 = GenericBlas.Linspace(0.5, 1, a3 + 1); double[] xComplete = new double[xnodes1.Length + xnodes2.Length + xnodes3.Length - 2]; for (int i = 0; i < xnodes1.Length; i++) { xComplete[i] = xnodes1[i]; } for (int i = 1; i < xnodes2.Length; i++) { xComplete[i + xnodes1.Length - 1] = xnodes2[i]; } for (int i = 1; i < xnodes3.Length; i++) { xComplete[i + xnodes1.Length + xnodes2.Length - 2] = xnodes3[i]; } double[] ynodes = GenericBlas.Linspace(0, 0.1, 2); GridCommons grd = Grid2D.Cartesian2DGrid(xComplete, ynodes, CellType.Square_Linear, true, false); grd.Description = "2D cartesian grid 35x1 cells"; return(grd); }
/// <summary> /// approximately equal /// </summary> /// <param name="other"></param> /// <returns></returns> /// <param name="RelTol">relative tolerance for comparison</param> public bool ApproximateEquals(AffineTrafo other, double RelTol = 1.0e-9) { int D = this.Affine.Length; if (other.Affine.Length != D || other.Matrix.NoOfCols != this.Matrix.NoOfCols || other.Matrix.NoOfRows != this.Matrix.NoOfRows) { throw new ArgumentException("mismatch in spatial dimension."); } double tolAffine = GenericBlas.L2NormPow2(this.Affine) * RelTol; if (GenericBlas.L2DistPow2(this.Affine, other.Affine) > tolAffine) { return(false); } Debug.Assert(this.Matrix.IsContinious && this.Matrix.Index(0, 0) == 0); Debug.Assert(other.Matrix.IsContinious && other.Matrix.Index(0, 0) == 0); double tolTrafo = GenericBlas.L2NormPow2(this.Matrix.Storage) * RelTol; if (GenericBlas.L2DistPow2(other.Matrix.Storage, this.Matrix.Storage) > tolTrafo) { return(false); } return(true); }
/// <summary> /// Computes, for point <paramref name="pt"/>, the closest point on /// the boundary of cell <paramref name="j"/>. /// </summary> /// <param name="j">local cell index</param> /// <param name="pt"> /// input; some point in global coordinates. /// </param> /// <param name="pt_Loc"> /// output, if unequal null: <paramref name="pt"/> in local /// coordinates of cell <paramref name="j"/>. /// </param> /// <param name="closestPoint_global"> /// output, if unequal null: within the boundary of cell /// <paramref name="j"/>, the closest point to /// <paramref name="pt"/>. /// </param> /// <param name="closestPoint_local"> /// output, if unequal null: <paramref name="closestPoint_global"/> /// in global coordinates. /// </param> /// <returns> /// the distance. /// </returns> public double ClosestPointInCell(double[] pt, int j, double[] pt_Loc = null, double[] closestPoint_global = null, double[] closestPoint_local = null) { int D = m_owner.SpatialDimension; if (pt.Length != D) { throw new ArgumentException("length must be equal to spatial dimension", "pt"); } // point to search for MultidimensionalArray _pt = MultidimensionalArray.CreateWrapper(pt, 1, D); MultidimensionalArray _pt_local = AllocHelper(ref pt_Loc, D); //MultidimensionalArray _closestPoint_local = AllocHelper(ref closestPoint_local, D); m_owner.TransformGlobal2Local(_pt, _pt_local, j, null); this.GetRefElement(j).ClosestPoint(pt_Loc, closestPoint_local); MultidimensionalArray _closestPoint_global = AllocHelper(ref closestPoint_global, D); m_owner.TransformLocal2Global(new NodeSet(this.GetRefElement(j), closestPoint_local), _closestPoint_global, j); return(GenericBlas.L2Dist(closestPoint_global, pt)); }
/// <summary> /// Test using SubsonicPressureInlet at the inlet and /// SubsonicOutlet at the outlet. That is, this test case /// uses physically correct boundary conditions /// </summary> /// <returns></returns> public static CNSControl[] EulerSubsonicPressureInletAndOutletTest1D() { CNSControl[] templates = GetTemplates(); foreach (CNSControl c in templates) { int divisions = (int)c.Paramstudy_CaseIdentification.Single(t => t.Item1 == "divisions").Item2; int noOfCells = (2 << divisions) * 8; c.GridFunc = delegate { GridCommons grid = Grid1D.LineGrid( GenericBlas.Linspace(0.0, Math.PI / 2.0 + 0.0, noOfCells + 1)); grid.EdgeTagNames.Add(1, "subsonicPressureInlet"); grid.EdgeTagNames.Add(2, "subsonicOutlet"); grid.DefineEdgeTags((Vector x) => Math.Abs(x[0]) < 1e-14 ? (byte)1 : (byte)2); return(grid); }; c.AddBoundaryValue("subsonicPressureInlet", "p0", totalPressure); c.AddBoundaryValue("subsonicPressureInlet", "T0", totalTemperature); c.AddBoundaryValue("subsonicOutlet", CNSVariables.Pressure, exactPressure); } return(templates); }
public override MultidimensionalArray GetSurfacePoints(LevelSetTracker lsTrk, double[] Position, double Angle) { int SpatialDim = lsTrk.GridDat.SpatialDimension; if (SpatialDim != 2) { throw new NotImplementedException("Only two dimensions are supported at the moment"); } double hMin = lsTrk.GridDat.iGeomCells.h_min.Min(); int NoOfSurfacePoints = Convert.ToInt32(20 * Circumference_P / hMin) + 1; MultidimensionalArray SurfacePoints = MultidimensionalArray.Create(NoOfSurfacePoints, 2); double[] InfinitisemalAngle = GenericBlas.Linspace(0, 2 * Math.PI, NoOfSurfacePoints + 1); if (Math.Abs(10 * Circumference_P / hMin + 1) >= int.MaxValue) { throw new ArithmeticException("Error trying to calculate the number of surface points, overflow"); } for (int j = 0; j < NoOfSurfacePoints; j++) { SurfacePoints[j, 0] = Math.Cos(InfinitisemalAngle[j]) * width_P + Position[0]; SurfacePoints[j, 1] = Math.Sin(InfinitisemalAngle[j]) * width_P + Position[1]; } return(SurfacePoints); }
public static void Init() { bool dummy; ilPSP.Environment.Bootstrap( new string[0], BoSSS.Solution.Application.GetBoSSSInstallDir(), out dummy); //GridCommons grd = Grid2D.Cartesian2DGrid(RandomSpacing(), RandomSpacing()); //grid = new GridData(Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-7, 7, 8), GenericBlas.Linspace(-1, 1, 2))); //grid = new GridData(Grid2D.Cartesian2DGrid(new double[] { -6, -4, -2, 2, 4, 6 }, GenericBlas.Linspace(-1, 1, 2))); grid = new GridData(Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1.5, 1.5, 17), GenericBlas.Linspace(-1.5, 1.5, 17))); MgSeq = CoarseningAlgorithms.CreateSequence(grid); for (int p = 0; p <= 3; p++) // loop over polynomial degrees... { var uMapping = new UnsetteledCoordinateMapping(new Basis(grid, p)); var MgMapSeq = new MultigridMapping[MgSeq.Length]; var BasisSeq = AggregationGridBasis.CreateSequence(MgSeq, uMapping.BasisS); for (int iLevel = 0; iLevel < MgSeq.Length; iLevel++) { MgMapSeq[iLevel] = new MultigridMapping(uMapping, BasisSeq[iLevel], new int[] { p }); } MultigrigMap.Add(p, MgMapSeq); } }
override public MultidimensionalArray GetSurfacePoints(LevelSetTracker lsTrk, double[] Position, double Angle) { int SpatialDim = lsTrk.GridDat.SpatialDimension; if (SpatialDim != 2) { throw new NotImplementedException("Only two dimensions are supported at the moment"); } double hMin = lsTrk.GridDat.iGeomCells.h_min.Min(); int NoOfSurfacePoints = Convert.ToInt32(10 * Circumference_P / hMin); int QuarterSurfacePoints = NoOfSurfacePoints / 4; MultidimensionalArray SurfacePoints = MultidimensionalArray.Create(NoOfSubParticles(), 4 * QuarterSurfacePoints - 2, SpatialDim); double[] InfinitisemalAngle = GenericBlas.Linspace(0, Math.PI / 2, QuarterSurfacePoints + 2); if (Math.Abs(10 * Circumference_P / hMin + 1) >= int.MaxValue) { throw new ArithmeticException("Error trying to calculate the number of surface points, overflow"); } for (int j = 0; j < QuarterSurfacePoints; j++) { SurfacePoints[0, j, 0] = (Math.Pow(Math.Cos(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * length_P * Math.Cos(Angle) - Math.Pow(Math.Sin(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * thickness_P * Math.Sin(Angle)) + Position[0]; SurfacePoints[0, j, 1] = (Math.Pow(Math.Cos(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * length_P * Math.Sin(Angle) + Math.Pow(Math.Sin(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * thickness_P * Math.Cos(Angle)) + Position[1]; SurfacePoints[0, 2 * QuarterSurfacePoints + j - 1, 0] = (-(Math.Pow(Math.Cos(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * length_P) * Math.Cos(Angle) + Math.Pow(Math.Sin(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * thickness_P * Math.Sin(Angle)) + Position[0]; SurfacePoints[0, 2 * QuarterSurfacePoints + j - 1, 1] = (-(Math.Pow(Math.Cos(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * length_P) * Math.Sin(Angle) - Math.Pow(Math.Sin(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * thickness_P * Math.Cos(Angle)) + Position[1];; } for (int j = 1; j < QuarterSurfacePoints; j++) { SurfacePoints[0, 2 * QuarterSurfacePoints - j - 1, 0] = (-(Math.Pow(Math.Cos(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * length_P) * Math.Cos(Angle) - Math.Pow(Math.Sin(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * thickness_P * Math.Sin(Angle)) + Position[0]; SurfacePoints[0, 2 * QuarterSurfacePoints - j - 1, 1] = (-(Math.Pow(Math.Cos(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * length_P) * Math.Sin(Angle) + Math.Pow(Math.Sin(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * thickness_P * Math.Cos(Angle)) + Position[1]; SurfacePoints[0, 4 * QuarterSurfacePoints - j - 2, 0] = (Math.Pow(Math.Cos(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * length_P * Math.Cos(Angle) + Math.Pow(Math.Sin(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * thickness_P * Math.Sin(Angle)) + Position[0]; SurfacePoints[0, 4 * QuarterSurfacePoints - j - 2, 1] = (Math.Pow(Math.Cos(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * length_P * Math.Sin(Angle) - Math.Pow(Math.Sin(InfinitisemalAngle[j]), 2 / superEllipsoidExponent) * thickness_P * Math.Cos(Angle)) + Position[1]; } return(SurfacePoints); }