A Simple Cylinder Mesh Generator for Panel Method by MATLAB

Meshing a body surface and definition of the panel distribution are the previous steps when using linear radiation/diffraction panel codes for studying hydrodynamics. A cylinder mesh generator and panel distribution approach is provided by this post.

R=3;   % radius of cylinder
H=-20; % cylinder height, negative quantity means the draft
Nr=15; % No. of nodes in radius direction
Nt=20; % No. of nodes in circuferential direction
Nz=25; % No. of nodes in vertical direction

nodes=zeros(Nt*(Nz-1)+Nt*Nr+1,3); %total nodes' coodinate
triangles=zeros(Nt,3);            %triangular panels
quads=zeros(Nt*(Nr+Nz-2),4);      %quadrangular panels

% bottom center
c=1;
nodes(c,1)=0.0;
nodes(c,2)=0.0;
nodes(c,3)=H;

%bottom surface
for j=1:Nr %
    for i=1:Nt %
        c=c+1; 
        nodes(c,1)=R*j/Nr*cosd(360*(i-1)/Nt);
        nodes(c,2)=R*j/Nr*sind(360*(i-1)/Nt); 
        nodes(c,3)=H;
    end
end

% side wall
for j=1:Nz-1
    for i=1:Nt
        c=c+1;
        nodes(c,1)=R*cosd(360*(i-1)/Nt);
        nodes(c,2)=R*sind(360*(i-1)/Nt); 
        nodes(c,3)=H-H/(Nz-1)*j;
    end
end

%Triangles panel
%------------
nt=0;
for i=2:Nt % right-hand rule, and direct downward
    nt=nt+1;
    triangles(i-1,1)=i+1;
    triangles(i-1,2)=i; 
    triangles(i-1,3)=1;    
end
nt=nt+1;
i=i+1;
triangles(i-1,1)=2;
triangles(i-1,2)=i; 
triangles(i-1,3)=1;   

%Quads panel
%------------
%bottom
nq=0;
for j=1:Nr-1
    for i=2:Nt
        nq=nq+1;  
        quads(nq,1)=Nt*(j-1)+i;
        quads(nq,2)=Nt*(j-1)+i+1;
        quads(nq,3)=Nt*j+i+1;
        quads(nq,4)=Nt*j+i;
    end
    nq=nq+1;
    i=i+1;
    quads(nq,1)=Nt*(j-1)+i;
    quads(nq,2)=Nt*(j-1)+2;
    quads(nq,3)=Nt*j+2;
    quads(nq,4)=Nt*j+i;
end

% wall
for j=1:Nz-1
    for i=2:Nt
        nq=nq+1;
        quads(nq,1)=Nt*(Nr-1)+(j-1)*Nt+i;
        quads(nq,2)=Nt*(Nr-1)+(j-1)*Nt+i+1;
        quads(nq,3)=Nt*(Nr-1)+j*Nt+i+1;
        quads(nq,4)=Nt*(Nr-1)+j*Nt+i;
    end
    nq=nq+1;
    i=i+1;
    quads(nq,1)=Nt*(Nr-1)+(j-1)*Nt+i;
    quads(nq,2)=Nt*(Nr-1)+(j-1)*Nt+2;
    quads(nq,3)=Nt*(Nr-1)+j*Nt+2;
    quads(nq,4)=Nt*(Nr-1)+j*Nt+i;
end
Surface mesh (without water plane)
Normal direction of each panel points outside.

Leave a Comment

Your email address will not be published. Required fields are marked *