Mesh2D
介绍
Mesh2D用来建立二维网格,可以导入Surface2D来进行网格划分。
原理
MESH2D: Delaunay-based unstructured mesh-generation
Baffalo 采用MESH2D$^{[1]}$作为2D网格划分求解器,它可基于给定的边界采用Delaunay三角形进行网格划分。
![]() | ![]() |
案例
Create gear obj (Flag=1)
a=Point2D('Point Ass1');
neg=8;
OR1=2.5;OR2=2;IR=1;
D_theta=3/180*pi;
a=AddPoint(a,0,0);
for i=1:neg
x1=OR1*cos(pi/neg/2-D_theta-pi/neg*2*(i-1));
y1=OR1*sin(pi/neg/2-D_theta-pi/neg*2*(i-1));
x2=OR1*cos(-pi/neg/2+D_theta-pi/neg*2*(i-1));
y2=OR1*sin(-pi/neg/2+D_theta-pi/neg*2*(i-1));
x3=OR2*cos(-pi/neg/2-pi/neg*2*(i-1));
y3=OR2*sin(-pi/neg/2-pi/neg*2*(i-1));
x4=OR2*cos(-pi/neg/2*3-pi/neg*2*(i-1));
y4=OR2*sin(-pi/neg/2*3-pi/neg*2*(i-1));
x5=OR1*cos(pi/neg/2-D_theta-pi/neg*2*i);
y5=OR1*sin(pi/neg/2-D_theta-pi/neg*2*i);
xx=[x1;x2];yy=[y1;y2];
a=AddPoint(a,xx,yy);
xx=[x2;x3];yy=[y2;y3];
a=AddPoint(a,xx,yy);
xx=[x3;x4];yy=[y3;y4];
a=AddPoint(a,xx,yy);
xx=[x4;x5];yy=[y4;y5];
a=AddPoint(a,xx,yy);
end
b=Line2D('Line Ass1');
for i=1:neg
b=AddLine(b,a,2+(i-1)*4);
b=AddLine(b,a,3+(i-1)*4);
b=AddCircle(b,OR2,a,1,'sang',-180/neg/2-180/neg*2*(i-1),'ang',-180/neg);
b=AddLine(b,a,5+(i-1)*4);
end
S=Surface2D(b);
a1=Point2D('Point Group2');
a1=AddPoint(a1,0,0);
h=Line2D('Hole Group1');
h=AddCircle(h,IR,a1,1);
S= AddHole(S,h);
m=Mesh2D('Mesh1');
m=AddSurface(m,S);
m=SetSize(m,0.2);
m=Mesh(m);
Plot(m);
对一个类齿轮的封闭平面网格划分:

Create quad circle (Flag=2)
m=Mesh2D('Mesh1');
m=MeshQuadCircle(m,'n',4);
Plot(m);
m=SmoothFace(m,100);
Plot(m);
采用四边形网格划分圆。
![]() | ![]() |
Create quad plate (Flag=3)
m=Mesh2D('Mesh1');
m=MeshQuadPlate(m,[10,10]);
Plot(m);
矩形平板四边形网格划分:

Add Elements (Flag=4)
m=Mesh2D('Mesh1');
P=[0,0;0,1;1,1;1,0;0,2;1,2];
m.Vert=P;
m=AddElements(m,[1,2,3,4;2,5,6,3]);
Plot(m);
加入网格,采用AddElements加入网格时需要自己定义好网格的节点。

Convhull (Flag=5)
[X,Y]=meshgrid(0:0.1:1);
points1=[X(:),Y(:)];
a=Point2D('Point Ass1');
a=AddPoint(a, points1(:,1), points1(:,2));
f=@(x,y)(x>0.5 &y>0.2 & y<0.8);
a=DeletePoint(a,1,'fun',f);
Plot(a);
m=Mesh2D('Mesh1');
m=Convhull(m,a,'keep',0,'simplity',true);
Plot(m);
计算电集的凸包,根据凸包生成网格、
![]() | ![]() |
Convcave1 (Flag=6)
[X,Y]=meshgrid(0:0.1:1);
points1=[X(:),Y(:)];
a=Point2D('Point Ass1');
a=AddPoint(a, points1(:,1), points1(:,2));
logic=points1(:,1)>0.5 & points1(:,2)>0.2 & points1(:,2)<0.8;
m=Mesh2D('Mesh1');
m=Convcave(m,a,'logic',logic);
Plot(m);

Convcave2 (Flag=7)
points1=rand(100,2);
a=Point2D('Point Ass1');
a=AddPoint(a, points1(:,1), points1(:,2));
logic=points1(:,1)>0.5 & points1(:,2)>0.2 & points1(:,2)<0.8;
m=Mesh2D('Mesh1');
m=Convcave(m,a,'logic',logic);
Plot(m);

Covert quad to tri (Flag=8)
m=Mesh2D('Mesh1');
m=MeshQuadCircle(m,'n',8);
Plot(m);
m=Quad2Tri(m);
Plot(m);
将四边形网格转换为三角形单元。
![]() | ![]() |
Mesh 2D Tensor Grid (Flag=9)
m=Mesh2D('Mesh1');
dx = 1-0.5*cos((-1:0.1:1)*pi);
x = -1.15+0.1*cumsum(dx);
y = 0:0.05:1;
m=MeshTensorGrid(m,x,sqrt(y));
Plot(m);
MRST$^{[1]}$提供了很好用的四边形和六面体网格的函数,Baffalo借鉴了部分函数集成到网格划分中。

Mesh 2D Grid (Flag=10)
m=Mesh2D('Mesh1');
nx=6;ny=12;
lx=6;ly=12;
m=MeshGrid(m,[nx, ny],[lx,ly],'twist',0.03);
Plot(m);
c = m.Vert;
I = any(c==0,2) | any(c(:,1)==nx,2) | any(c(:,2)==ny,2);
m.Vert(~I,:) = c(~I,:) + 0.6*rand(sum(~I),2)-0.3;
Plot(m);
![]() | ![]() |
Compute MRST G (Flag=11)
m=Mesh2D('Mesh1');
nx=30;ny=20;
lx=30;ly=20;
m=MeshGrid(m,[nx, ny],[lx,ly],'twist',0.05);
Plot(m);
m= ComputeGeometryG(m);
PlotG(m,'volume',1);
ComputeGeometryG用于计算四边形网格的集合信息(中心, 体积, 面积)。
![]() | ![]() |
Load msh file (Flag=12)
m=Mesh2D('Mesh1');
m=LoadMsh(m,'airfoil.msh');
Plot(m);
读取msh格式网格。

MeshDual (Flag=13)
m=Mesh2D('Mesh1');
m=LoadMsh(m,'airfoil.msh');
Plot(m,'xlim',[-0.2,1.1],'ylim',[-0.2,1.1]);
m=MeshDual(m);
PlotDual(m,'xlim',[-0.2,1.1],'ylim',[-0.2,1.1]);
DUALMESH $^{[3]}$可以将三角形网格重新划分为多边形网格。

Plot Dual center and area (Flag=14)
m=Mesh2D('Mesh1');
m=LoadMsh(m,'airfoil.msh');
m=MeshDual(m);
[pc,ac]=ComputeGeometryDual(m); %#ok<ASGLU>
PlotDual(m,'xlim',[-0.2,1.1],'ylim',[-0.2,1.1],'area',1,'center',1);
显示多边形网格的中心,并依据面积设置不同的颜色。

Calculate geometry information (Flag=15)
% Semi circle
a=Point2D('Circle center');
a=AddPoint(a,0,0);
a=AddPoint(a,[-5;5],[0;0]);
b=Line2D('Semi circle');
b=AddCircle(b,5,a,1,'ang',180);
b=AddLine(b,a,2);
S=Surface2D(b);
Plot(S);
m=Mesh2D('Mesh1');
m=AddSurface(m,S);
m=SetSize(m,0.5);
m=Mesh(m);
Plot(m);
[Area,Center,Ixx,Iyy,Ixy]= CalculateGeometry(m); %#ok<ASGLU>
计算网格截面的几何信息。
![]() | ![]() |
Plot Mesh2D in paraview (Flag=16)
m=Mesh2D('Mesh1');
m=LoadMsh(m,'airfoil.msh');
Plot2(m);
在Paraciew中显示网格。

Plot Mesh2D G and celldata in paraview (Flag=17)
m=Mesh2D('Mesh1');
nx=30;ny=20;
lx=30;ly=20;
m=MeshGrid(m,[nx, ny],[lx,ly],'twist',0.05);
m= ComputeGeometryG(m);
volume=m.G.cells.volumes;
m=AddCellData(m,volume);
PlotG2(m);
将计算的体积信息导入到celldata中,即可在paraview中显示相关信息。

Mesh edge (Flag=18)
a=Point2D('Temp');
a=AddPoint(a,0,0);
% Add outline
b1=Line2D('Out');
b1=AddCircle(b1,14,a,1);
% Add innerline
b2=Line2D('Inner');
b2=AddCircle(b2,5,a,1,'seg',40);
% Add assembly hole
h=Line2D('Hole');
h=AddCircle(h,3.5/2,a,1,'seg',16);
S=Surface2D(b1);
S=AddHole(S,b2);
for i=1:4
S=AddHole(S,h,'dis',[10*cos(pi/2*(i-1)),10*sin(pi/2*(i-1))]);
end
m=Mesh2D('Temp');
m=AddSurface(m,S);
m=SetSize(m,5);
m=Mesh(m);
Plot(m)
% Mesh edge
m=MeshEdge(m,2);
Plot(m)
m=MeshEdge(m,2);
Plot(m)
m=MeshEdge(m,2);
Plot(m)
m=MeshEdge(m,2);
Plot(m)
MeshEdge在原始模型的边界划分网格。

![]() | ![]() |
![]() | ![]() |
Mesh ring (Flag=19)
m1=Mesh2D('Mesh1');
m1=MeshRing(m1,4,5);
m2=Mesh2D('Mesh2');
m2=MeshRing(m2,4,5,'ElementType','tri');
Plot(m1);
Plot(m2);
绘制一个环。
![]() | ![]() |
Mesh edge layer (Flag=20)
a=Point2D('Temp');
a=AddPoint(a,0,0);
% Add outline
b1=Line2D('Out');
b1=AddCircle(b1,14,a,1);
% Add innerline
b2=Line2D('Inner');
b2=AddCircle(b2,5,a,1,'seg',40);
% Add assembly hole
h=Line2D('Hole');
h=AddCircle(h,3.5/2,a,1,'seg',16);
S=Surface2D(b1);
S=AddHole(S,b2);
for i=1:4
S=AddHole(S,h,'dis',[10*cos(pi/2*(i-1)),10*sin(pi/2*(i-1))]);
end
m=Mesh2D('Temp');
m=AddSurface(m,S);
m=SetSize(m,5);
m=Mesh(m);
Plot(m)
% Mesh Layer edge
m=MeshLayerEdge(m,2,2);
Plot(m)
% Mesh Layer edge
m=MeshLayerEdge(m,3,1);
Plot(m)
在现有网格的边界绘制层网格。
![]() | ![]() |
Data=load('Data.mat').Data;
a=Point2D('Temp');
a=AddPoint(a,Data(:,1),Data(:,2));
% Add outline
b=Line2D('Out');
b=AddCurve(b,a,1);
S=Surface2D(b);
m=Mesh2D('Temp');
m=AddSurface(m,S);
m=SetSize(m,20);
m=Mesh(m);
Center = CenterCal(m);
m=AddCellData(m,Center(:,1).^2+Center(:,2).^2);
Plot2(m)
首先准备外轮廓的电,绘制曲线和封闭曲面,利用Mesh2D生成网格,导入到Paraview中。
调整背景色,
并设置自己喜欢的色阶,

CheatTable
Name | Varargin | Description |
---|---|---|
AddCellData(obj,Data) | Add cell data to mesh | |
AddElements(obj,Face) | ‘position’ | Add elements to Mesh2D |
AddPointData(obj,Data) | Add point data to nodes | |
AddPointVector(obj,Vec) | Add Point vector to nodes | |
AddSurface(obj,Surface) | Add surface to Mesh2D | |
CalculateGeometry(obj) | Calculate mesh Geometry information | |
CenterCal(obj) | Calculate center of elements | |
ComputeGeometryDual(obj) | Compute Dual mesh information | |
ComputeGeometryG(obj) | Compute Geometry MRST G information | |
Convcave(obj,Point) | ‘logic’ | Create convcave |
Convert2Order2(obj) | Change element order | |
Convhull(obj,Point,varargin) | ‘simplity’,’keep’ | Create convhull |
DelNullElement(obj) | Delete Null elements and compress elements | |
LoadMsh(obj,name) | Load msh file to Mesh2D | |
FindBoundary(obj) | Find boundary of mesh | |
EdgeGroup(obj) | Find edge group | |
MergeNode(obj) | Merge obj face node | |
Mesh(obj) | ‘kind’,’ref1’,’ref2’,’siz1’,’siz2’ | Mesh 2D elements |
MeshEdge(obj,edgeno) | Mesh edge elemnts | |
MeshGrid(obj,n,l) | ‘twist’ | Mesh grid elements |
MeshLayerEdge(obj,edgeno,Thickness) | ‘Num’,’ElementType’,’Dir’ | Mesh layer edge elements |
MeshQuadCircle(obj) | ‘n’,’r’,’f’ | Mesh a circle using quadrilaterial elements |
MeshQuadPlate(obj,plateDim,plateEl) | Mesh quad plate | |
MeshRing(obj,IR,OR) | ‘Num’,’ElementType’,’Seg’ | Mesh ring |
MeshTensorGrid(obj,x,y) | ‘twist’ | Mesh tensor grid element |
PatchBoundaryCentre(obj) | Get center of boundary | |
Plot(obj) | ‘grid’,’axe’,equal’,’base_size’, ‘xlim’,’ylim’ |
Plot Mesh2D object |
Plot2(obj) | Plot Mesh2D object in Paraview | |
PlotDual(obj) | ‘grid’,’area’,’center’,’axe’, ‘equal’,’base_size’,’xlim’,’ylim’ |
Plot dual mesh |
PlotG(obj) | ‘volume’,’grid’,’name’,’axe’, ‘equal’,’base_size’,’xlim’,’ylim’ |
Plot MRST G |
PlotG2(obj) | Plot MRST G in Paraview | |
Quad2Tri(obj) | ‘type’ | Covert quad mesh to tri mesh |
RemoveCells(obj,cells) | Rmove MRST G cells | |
ScaleMesh(obj,Scale) | Scale mesh | |
SetSize(obj,edgesize) | Set mesh edge size | |
SmoothFace(obj,N) | Smooth face elements | |
VTKWrite(obj) | Write VTK file of Mesh2D | |
VTKWriteG(obj) | Write VTK file of Mesh2D G | |
WriteSTL(obj) | Write STL file of mesh |
参考文献
[2] https://www.sintef.no/projectweb/mrst/
本网站基于Hexo 3-Hexz主题生成。如需转载请标注来源,如有错误请批评指正,欢迎邮件至 392176462@qq.com