/// <summary> /// 对所有单元进行合并 /// </summary> /// <param name="Ns"></param> /// <param name="Es"></param> /// <param name="MP"></param> public static void Elements_Combine(ref Node[] Ns, ref Element[] Es, ref WMesh2D_Para MP) { for (int i = 0; i < Es.Length; i++) { Element_Combine(ref Ns, ref Es, i, MP.MaxAngle_Qua); } }
/// <summary> /// 从一个Poly文件,Mesh后形成Mesh2D类 /// </summary> /// <param name="MP"></param> /// <param name="Name">简短文件名</param> /// <returns></returns> public static WMesh2D_Mesh Triangle_Mesh(ref WMesh2D_Para MP, string Name) { Tiangle_Call New_Call = new Tiangle_Call(MP.Path + Name + ".poly", ref MP); #region 多线程 ThreadStart start = new ThreadStart(New_Call.Triangulate_Refine); Thread thread = new Thread(start); thread.Name = "Tiangle_Call"; thread.Start(); while (true) { if (thread.ThreadState == System.Threading.ThreadState.Stopped) { break; } } #endregion #region 单线程 //New_Call.Triangulate_Refine(); #endregion bool C = New_Call.Out; if (C == false) { return(null); } Mesh mesh = New_Call.Mesh; Node[] Ns = new Node[0]; /////注意该数组是从1开始的,目的是为了Element使用方便 Element[] Es = new Element[0]; FileWriter.WritePoly(mesh, MP.Path + Name + "_.poly"); FileWriter.Trans_Mesh(mesh, ref Ns, ref Es); Mesh2D_TriangleComb.Elements_Combine(ref Ns, ref Es, ref MP); ///// WMesh2D_Mesh Mesh = new WMesh2D_Mesh(Name); Mesh.Q_FreeNs = MP.QN_Ini; for (int i = 1; i < Ns.Length; i++) { Mesh.Nodes.Add(new WNode2D(i, Ns[i].x, Ns[i].y, 0)); } for (int i = 0; i < Es.Length; i++) { if (Es[i].Valid == false) { continue; } Mesh.Elements.Add(new WElement2D(Es[i].Kind, Es[i].N1, Es[i].N2, Es[i].N3, Es[i].N4)); } File.Delete(MP.Path + Name + ".poly"); File.Delete(MP.Path + Name + "_.poly"); Ns = null; Es = null; mesh = null; return(Mesh); }
public static WMesh2D_Mesh Mesh_SingleRim(ref WEntity2D[] Rim, string Name, ref WMesh2D_Para MP) { WShapeRim2D Shape = Rim_Output(ref Rim, MP.Path, Name); if (Shape == null) { return(null); } Poly_SingleRim(Shape.Count, MP.Path, Name); WMesh2D_Mesh Mesh = Mesh2D_TriangleMesh.Triangle_Mesh(ref MP, Name); /////调用 if (Mesh == null) { return(null); } Mesh.Shapes.Add(Shape); Mesh.Input_Bound(Shape.Xmin, Shape.Xmax, Shape.Ymin, Shape.Ymax); return(Mesh); }
/// <summary> /// 从一个Poly文件,Mesh后形成mesh文件 /// </summary> /// <param name="Name">poly文件的完整文件名</param> /// <param name="MP"></param> /// <returns></returns> public static bool Triangle_Mesh(string Name, ref WMesh2D_Para MP) { Tiangle_Call New_Call = new Tiangle_Call(MP.Path + Name + ".poly", ref MP); #region 多线程 ThreadStart start = new ThreadStart(New_Call.Triangulate_Refine); Thread thread = new Thread(start); thread.Name = "Tiangle_Call"; thread.Start(); while (true) { if (thread.ThreadState == System.Threading.ThreadState.Stopped) { break; } } #endregion #region 单线程 //New_Call.Triangulate_Refine(); #endregion bool C = New_Call.Out; if (C == false) { return(false); } Mesh mesh = New_Call.Mesh; Node[] Ns = new Node[0]; /////注意该数组是从1开始的,目的是为了Element使用方便 Element[] Es = new Element[0]; FileWriter.WritePoly(mesh, MP.Path + Name + "_.poly"); FileWriter.Trans_Mesh(mesh, ref Ns, ref Es); Mesh2D_TriangleComb.Elements_Combine(ref Ns, ref Es, ref MP); Mesh_Output(MP.Path, Name, ref Ns, ref Es, MP.QN_Ini); File.Delete(MP.Path + Name + ".poly"); File.Delete(MP.Path + Name + "_.poly"); return(true); }
public static WElement2D[] Do_Mesh(ref WEntity2D[] Rim_Curves, string Name, ref WMesh2D_Para MP) { List <WPoint2D> Ps = new List <WPoint2D>(); ///// 节点集 List <int> Ns = new List <int>(); ///// 节点编号集 Get_Rim(ref Rim_Curves, ref Ps, ref Ns); int[] Corner = Find_Corner(ref Ps); WElement2D[] Es = new WElement2D[0]; if (Corner.Length == 3) { Es = Mesh_TriCorner(ref Corner, Ns, Ps); } if (Corner.Length == 4) { Es = Mesh_FourCorner(ref Corner, Ns, Ps); } return(Es); }
private static void Out_toMesh(ref List <int>[] Rims, ref WMesh2D_Para MP, ref WEntity2D[] Poles, ref WMesh2D_Mesh Mesh) { WEntity2D[] Rim_Curves; WMesh2D_Mesh[] Meshs_t = new WMesh2D_Mesh[Rims.Length]; for (int i = 0; i < Rims.Length; i++) { Rim_Curves = new WEntity2D[Rims[i].Count]; for (int j = 0; j < Rims[i].Count; j++) { Rim_Curves[j] = (WEntity2D)Poles[Rims[i][j]]; } Meshs_t[i] = Mesh2D_MeshFree.Mesh_SingleRim(ref Rim_Curves, Convert.ToString(i), ref MP); } Mesh = Meshs_t[0]; for (int i = 1; i < Rims.Length; i++) { Mesh = Mesh2D_Merge_Mesh2Mesh.Mesh_Combine(Mesh, Meshs_t[i], "Pole"); } Meshs_t = null; }
private static void MeshNum_Update(ref Node[] Ns, ref Element[] Es, ref WMesh2D_Para MP) { int[] Ns_U = new int[Ns.Length]; Ns_U[0] = 0; for (int i = 1; i <= MP.QN_Ini; i++) { Ns_U[i] = Ns[i].ID; } for (int i = MP.QN_Ini + 1; i < Ns.Length; i++) { Ns[i].ID = MP.Num_NodeLatest + i - MP.QN_Ini; Ns_U[i] = Ns[i].ID; } for (int i = 0; i < Es.Length; i++) { Es[i].ID = MP.Num_EleLatest + i + 1; //Es[i].N1t = Ns_U[Es[i].N1]; //Es[i].N2t = Ns_U[Es[i].N2]; //Es[i].N3t = Ns_U[Es[i].N3]; //Es[i].N4t = Ns_U[Es[i].N4]; } }
public Tiangle_Call(string File_Name, ref WMesh2D_Para MP) { this.File_Name = File_Name; this.MP = MP; Out = false; }
public static WElement2D[] Mesh_SingleRim(ref List <int> Nums, ref List <WPoint2D> Ps, ref WMesh2D_Para MP, string Name) { StreamWriter Sw = new System.IO.StreamWriter(MP.Path + Name + ".rim"); List <int> Ns = new List <int>(); int N = 0; N = WMFuncs2D.NsID_App(ref Ps, ref Ns, N); /////形成节点编号 WMFuncs2D.Ns_Out(ref Ps, ref Ns, false, 0, ref Sw); Sw.Close(); Poly_SingleRim(Ps.Count, MP.Path, Name); WMesh2D_Mesh Mesh = Mesh2D_TriangleMesh.Triangle_Mesh(ref MP, Name); /////调用 if (Mesh == null) { return(null); } for (int i = 0; i < Mesh.QEs; i++) { if (Mesh.Elements[i].Kind == 4) { Mesh.Elements[i] = new WElement2D(Mesh.Elements[i].Kind, Nums[Mesh.Elements[i].N1], Nums[Mesh.Elements[i].N2], Nums[Mesh.Elements[i].N3], Nums[Mesh.Elements[i].N4]); } else if (Mesh.Elements[i].Kind == 3) { Mesh.Elements[i] = new WElement2D(Mesh.Elements[i].Kind, Nums[Mesh.Elements[i].N1], Nums[Mesh.Elements[i].N2], Nums[Mesh.Elements[i].N3], 0); } } return(Mesh.Elements.ToArray()); }
public static WMesh2D_Mesh Mesh_DoubleRim(ref WEntity2D[] Rim_Outer, ref WEntity2D[] Rim_Inner, string Name, ref WMesh2D_Para MP) { int N = 0; int Quan_In = Rim_Output(ref Rim_Inner, MP.Path, Name + "_Inner", N); if (Quan_In == -1) { return(null); } N = Quan_In; int Quan_Out = Rim_Output(ref Rim_Outer, MP.Path, Name + "_Outer", N); if (Quan_Out == -1) { return(null); } N += Quan_Out; /// double xmin = double.MaxValue; double xmax = double.MinValue; double ymin = double.MaxValue; double ymax = double.MinValue; WCurve2D C; for (int i = 0; i < Rim_Inner.Length; i++) { C = (WCurve2D)Rim_Inner[i]; xmin = Math.Min(xmin, C.Xmin); xmax = Math.Max(xmax, C.Xmax); ymin = Math.Min(ymin, C.Ymin); ymax = Math.Max(ymax, C.Ymax); } Poly_DoubleRim(Quan_In, Quan_Out, MP.Path, Name, new WPoint2D((xmin + xmax) / 2, (ymin + ymax) / 2)); return(Mesh2D_TriangleMesh.Triangle_Mesh(ref MP, Name)); /////调用 }