How to Read 2d Mesh in Matlab
Mesh Generation for a Curved Structure
clc
clear
M=eight;
N=eight;
L=viii;
LX=1;
LY=ane;
LZ=1;
dx=60/M;
dy=LY/N;
dz=LZ/L;
for i=1:Thousand;
for j=ane:North;
for k=1:L;
x(i,j,k)=i*dx;
y0(i,j,k)=j*dy;
y(i,j,k)=(x(i,j,m))^2+y0(i,j,k);
z(i,j,chiliad)=k*dz;
end
cease
end
for i=1:1000;
for j=1:N;
for k=one:Fifty;
plot3(x(i,j,thousand),y(i,j,k),z(i,j,k),'*r')
concur on
filigree on
xlabel('10')
ylabel('y')
zlabel('z')
terminate
end
stop
for k=one:50;
for i=ane:M;
for j=i:N;
if (i<Thousand)
xx=[ x(i+1,j,grand) 10(i,j,yard) ];
yy=[ y(i+one,j,k) y(i,j,k) ];
zz=[ z(i,j,thousand) z(i,j,g) ];
f=line(20,yy,zz);
elseif (i==K)
xx=[ 10(i,j,k) x(i,j,m) ];
yy=[ y(i,j,grand) y(i,j,k) ];
zz=[ z(i,j,k) z(i,j,1000)];
f=line(xx,yy,zz);
terminate
finish
finish
end
for k=1:50;
for i=1:M;
for j=1:Due north;
if (j<Due north)
xxx=[ x(i,j+one,k) x(i,j,chiliad) ];
yyy=[ y(i,j+1,1000) y(i,j,1000) ];
zzz=[ z(i,j,1000) z(i,j,k) ];
f=line(xxx,yyy,zzz);
elseif (j==N)
30=[ 10(i,j,chiliad) x(i,j,k) ];
yyy=[ y(i,j,k) y(i,j,k) ];
zzz=[ z(i,j,k) z(i,j,thou) ];
f=line(xxx,yyy,zzz);
end
finish
end
stop
for k=i:50;
for i=1:K;
for j=1:N;
if (thousand<L)
xxxx=[ x(i,j,k) 10(i,j,k) ];
yyyy=[ y(i,j,yard) y(i,j,k) ];
zzzz=[ z(i,j,k+1) z(i,j,thousand) ];
f=line(xxxx,yyyy,zzzz);
elseif (k==L)
xxxx=[ 10(i,j,thou) ten(i,j,chiliad) ];
yyyy=[ y(i,j,k) y(i,j,g) ];
zzzz=[ z(i,j,k) z(i,j,one thousand) ];
f=line(xxxx,yyyy,zzzz);
terminate
finish
end
end
Mesh Generation in Cartesian Coordinates
clc
clear
M=7;
N=7;
L=7;
LX=1;
LY=i;
LZ=1;
dx=Lx/M;
dy=LY/N;
dz=LZ/L;
for k=1:L;
if (k==one |k==Fifty)
c=0;
else
c=1;
finish
for i=1:M;
for j=i:N;
if (j==i | i==1)
u(i,j,k)=0*c;
elseif (j==N | i==M)
u(i,j,k)=0;
else u(i,j,k)=c*randn(one,i);
finish
end
end
stop
for i=1:M;
for j=1:N;
for k=ane:L;
x(i,j,k)=i*dx;
y(i,j,m)=j*dy;
z(i,j,k)=m*dz;
end
end
end
figure
for i=1:Yard;
for j=1:N;
for m=1:L;
plot3(x(i,j,m),y(i,j,thousand),z(i,j,k),'*r')
end
hold on
end
finish
title('Domain Points')
xlabel('x')
ylabel('y')
zlabel('z')
tic
for i=1:One thousand;
for j=1:N;
for k=1:50;
xc=10(i,j,m);
yc=y(i,j,k);
zc=z(i,j,thou);
hold on
plot3(90,yc,zc,'*b')
axis equal
%--------------------------------------------------------
%Bottom Plane
xc1=ninety+dx/2;
yc1=yc+dy/2;
zc1=zc-dz/2; xc2=xc-dx/2; yc2=yc+dy/ii; zc2=zc-dz/ii; xc3=xc-dx/2; yc3=yc-dy/two; zc3=zc-dz/two;
xc4=90+dx/ii; yc4=yc-dy/ii; zc4=zc-dz/2; v1=[xc1,xc2]; v2=[yc1,yc2]; v3=[zc1,zc2]; f=line(v1,v2,v3); v1=[xc2,xc3];
v2=[yc2,yc3]; v3=[zc2,zc3]; f=line(v1,v2,v3); v1=[xc3,xc4]; v2=[yc3,yc4]; v3=[zc3,zc4]; f=line(v1,v2,v3); v1=[xc4,xc1];
v2=[yc4,yc1]; v3=[zc4,zc1]; f=line(v1,v2,v3); %--------------------------------------------------------
%Summit Plane xc5=xc+dx/ii;
yc5=yc+dy/2;
zc5=zc+dz/2; xc6=xc-dx/two; yc6=yc+dy/2; zc6=zc+dz/2; xc7=xc-dx/2; yc7=yc-dy/2;
zc7=zc+dz/ii;
xc8=xc+dx/2;
yc8=yc-dy/two;
zc8=zc+dz/2;
v1=[xc5,xc6];
v2=[yc5,yc6];
v3=[zc5,zc6];
f=line(v1,v2,v3);
v1=[xc6,xc7];
v2=[yc6,yc7];
v3=[zc6,zc7];
f=line(v1,v2,v3);
v1=[xc7,xc8];
v2=[yc7,yc8];
v3=[zc7,zc8];
f=line(v1,v2,v3);
v1=[xc8,xc5];
v2=[yc8,yc5];
v3=[zc8,zc5];
f=line(v1,v2,v3);
%--------------------------------------------------------
% Side Planes
v1=[xc1,xc5];
v2=[yc1,yc5];
v3=[zc1,zc5];
f=line(v1,v2,v3);
v1=[xc2,xc6];
v2=[yc2,yc6];
v3=[zc2,zc6];
f=line(v1,v2,v3);
v1=[xc3,xc7];
v2=[yc3,yc7];
v3=[zc3,zc7];
f=line(v1,v2,v3);
v1=[xc4,xc8];
v2=[yc4,yc8];
v3=[zc4,zc8];
f=line(v1,v2,v3);
%--------------------------------------------------------
end
cease
end
toc
Case Mesh Generation
clc
clear
x0=-1;
x00=1;
y0=ane;
y00=-1;
M=xxx;
N=30;
dx=(x00-x0)/K;
dy=(y00-y0)/North;
[x,y] = meshgrid(x0:dx:x00,y0:dy:y00);
for i=i:One thousand+one;
for j=1:N+ane;
z(i,j)=0;
end
end
tri = delaunay(x,y);
trisurf(tri,ten,y,z)
Instance Generating a Mesh
clc
articulate
10=[1:1:10];
y=[1:1:10];
1000=ten;
tt=12;
d=0;
for tt=i:M;
d=d+0.01;
%for i=one:M
yy=d*y;
h=plot(x,yy,'.');
grid on
hold on
% end
set(h,'EraseMode');
end
Example Generation a Surface
clc
clear
x0=0;
x00=6;
M=16;
dz=x00-x0;
dx=dz/Chiliad;
k=ii;
m=one;
y0=0
for j=1:1000;
z=j*dz;
for i=one:G;
x(i)=i*dx
y(i)=m*(x(i)-z)+y0;
filigree on
plot(ten,y)
grid on
xlabel('x')
ylabel('y')
hold on
end
end
Plotting Matrix Nodes, Nodes Coordinates, Mesh Function
clc for I=one:N figure(2) figure(3)
articulate
LX=1
LY=i
North=12
M=12
DX=LX/N
DY=LY/M
for I=one:N
for J=i:K
x(I,J)=I*DX;
y(I,J)=J*DY;
A(I,J)=sin(10(I,J)*y(I,J))/(10(I,J)*y(I,J))+0.01*randn(i,ane);
end
end
for J=1:One thousand
plot (I,J,'.')
agree on
filigree on
end
cease
title('Relationship Between M and N')
xlabel('Due north Number of Nodes')
ylabel('G Number of Nodes')
for I=1:N
for J=1:M
plot (x(I,J),y(I,J),'.')
agree on
grid on
terminate
end
championship('Human relationship Between 1000 and N')
xlabel('Node Coordinate in 10 direction')
ylabel('Node Coordinate in y direction')
mesh(10,y,A)
Staggered Grid
clc
clear
%Accented Referance Mesh Input Data x0=0; x00=ane; y0=0; y00=1; lx=x00-x0; ly=y00-y0; Thousand=10; N=10; dx=lx/M; dy=ly/North; %offseting Distance ddx=+0.5; ddy=+0.5; %Relative Referance Mesh Input Data x10=0; x11=one; y10=0; y11=1; lx1=(x11-x10)+ddx;
ly1=(y11-y10)+ddy;
M1=10;
N1=10;
dx1=lx1/M1;
dy1=ly1/N1;
% Matrix Mesh Generation matlab Command
[x,y]=meshgrid(x0:dx:x00,y0:dy:y00);
[x1,y1]=meshgrid(x10:dx1:x11,y10:dy1:y11);
% Output Data Visulization
% figure(1)
% plot(ten,y,'*b')
% %figure(2)
% hold on
% plot(x1,y1,'*r')
% agree off
% grid on
figure(1)
subplot(2,ii,1)
plot(x,y,'*b')
xlabel('x')
ylabel('y')
filigree on
title('Offset Grid ')
subplot(2,two,2)
plot(x1,y1,'*r')
xlabel('10')
ylabel('y')
grid on
championship('Second Grid ')
subplot(2,2,[3 4])
plot(ten,y,'*b',x1,y1,'*r')
xlabel('10')
ylabel('y')
filigree(gca,'minor')
title('Staggered Grid ')
Generation of 3D Grids Points
clc
clear
M=7;
N=seven;
L=7;
LX=1;
LY=one; LZ=ane;
dx=LX/M;
dy=LY/Due north;
dz=LZ/L;
for k=one:50;
if (1000==1 |k==L) c=0;
else c=i;
end
for i=i:Grand;
for j=one:Northward;
if (j==1 | i==one)
u(i,j,yard)=0*c;
elseif (j==Due north | i==M)
u(i,j,k)=0;
else
u(i,j,k)=c*randn(ane,1);
end
finish
stop
end
for i=one:M;
for j=1:N;
for k=i:L;
x(i,j,thousand)=i*dx;
y(i,j,1000)=j*dy;
z(i,j,grand)=k*dz;
terminate
end
end
figure(1)
for i=i:Chiliad;
for j=i:Due north;
for thousand=i:L;
if (i==1|i==G)
plot3(x(i,j,grand),y(i,j,thousand),z(i,j,thousand),'*b')
else
plot3(x(i,j,k),y(i,j,k),z(i,j,thou),'*r')
end
hold on
end
terminate
finish
title('Xplane')
xlabel('10')
ylabel('y')
zlabel('z')
effigy(ii)
for i=1:One thousand;
for j=one:Northward;
for 1000=i:L; if (j==one|j==N) plot3(x(i,j,m),y(i,j,thou),z(i,j,yard),'*b')
else
plot3(ten(i,j,g),y(i,j,k),z(i,j,k),'*r')
end hold on
end
terminate
end
championship('Yplane')
xlabel('ten')
ylabel('y')
zlabel('z')
effigy(3)
for i=1:Thou;
for j=i:N;
for k=one:50;
if (k==one|chiliad==L)
plot3(ten(i,j,g),y(i,j,k),z(i,j,thou),'*b')
else plot3(x(i,j,g),y(i,j,m),z(i,j,m),'*r')
finish
agree on
end
end
end
championship('Zplane') xlabel('ten') ylabel('y') zlabel('z') figure(iv)
for i=i:Thousand;
for j=1:N;
for thou=1:50;
plot3(x(i,j,k),y(i,j,k),z(i,j,one thousand),'*r')
end
concur on
end
end
title('Domain Points')
xlabel('x')
ylabel('y')
zlabel('z')
Unless otherwise noted, all content on this site is @Copyright past Ahmed Al Makky 2012-2013 - http://cfd2012.com
Source: https://cfd2012.com/matlab-mesh-generation.html
0 Response to "How to Read 2d Mesh in Matlab"
Post a Comment