Mesh Format for HAMS by MATLAB

HAMS is an open-source computer program for the analysis of wave diffraction and radiation of three-dimensional floating or submerged structures. In the following, a mesh formatting method by MATLAB for HAMS is given. The input parameters are the node and panel information of hull and water plane, respectively. An example of generating mesh of a cylinder is explained here.

function mesh4HAMS(nodes,triangles,quads,wpnodes,wptriangles,wpquads)

c=size(nodes,1);
nt=size(triangles,1);
nq=size(quads,1);

% hull
Syx=0;
Syy=0;
filename = 'HullMesh.pnl';
fid=fopen(filename,'w');
fprintf(fid,' --------------Hull Mesh File---------------\r\n\n');
fprintf(fid,'# Number of Panels, Nodes, X-Symmetry and Y-Symmetry\r\n');
fprintf(fid,'%d\t%d\t%d\t%d\r\n\n',nt+nq,c,Syx,Syy);
fprintf(fid,'#Start Definition of Node Coordinates     ! node_number   x   y   z\r\n');
for i=1:c
    fprintf(fid,'%d\t',i);
    fprintf(fid,'%10.6f\t%10.6f\t%10.6f\r\n',nodes(i,:));
end
fprintf(fid,'#End Definition of Node Coordinates\r\n\n');

fprintf(fid,'#Start Definition of Node Relations   ! panel_number number_of_vertices   Vertex1_ID   Vertex2_ID   Vertex3_ID   (Vertex4_ID)\r\n');
type=3;
for i=1:nt
    fprintf(fid,'%d\t',i);
    fprintf(fid,'%d\t',type);
    fprintf(fid,'%d\t%d\t%d\r\n',triangles(i,:));
end
type=4;
for i=nt+1:nt+nq
    fprintf(fid,'%d\t',i);
    fprintf(fid,'%d\t',type);
    fprintf(fid,'%d\t%d\t%d\t%d\r\n',quads(i-nt,:));
end
fprintf(fid,'#End Definition of Node Relations\r\n\n');
fprintf(fid,'--------------End Hull Mesh File---------------\r\n');
fclose(fid);

nw=size(wpnodes,1);
nt=size(wptriangles,1);
nq=size(wpquads,1);

% waterplane
Syx=0;
Syy=0;
filename = 'WaterplaneMesh.pnl';
fid=fopen(filename,'w');
fprintf(fid,' --------------Waterplane Mesh File---------------\r\n\n');
fprintf(fid,'# Number of Panels, Nodes, X-Symmetry and Y-Symmetry\r\n');
fprintf(fid,'%d\t%d\t%d\t%d\r\n\n',nt+nq,nw,Syx,Syy);
fprintf(fid,'#Start Definition of Node Coordinates     ! node_number   x   y   z\r\n');
for i=1:nw
    fprintf(fid,'%d\t',i);
    fprintf(fid,'%10.6f\t%10.6f\t%10.6f\r\n',wpnodes(i,:));
end
fprintf(fid,'#End Definition of Node Coordinates\r\n\n');

fprintf(fid,'#Start Definition of Node Relations   ! panel_number number_of_vertices   Vertex1_ID   Vertex2_ID   Vertex3_ID   (Vertex4_ID)\r\n');
type=3;
for i=1:nt
    fprintf(fid,'%d\t',i);
    fprintf(fid,'%d\t',type);
    fprintf(fid,'%d\t%d\t%d\r\n',wptriangles(i,:));
end
type=4;
for i=nt+1:nt+nq
    fprintf(fid,'%d\t',i);
    fprintf(fid,'%d\t',type);
    fprintf(fid,'%d\t%d\t%d\t%d\r\n',wpquads(i-nt,:));
end
fprintf(fid,'#End Definition of Node Relations\r\n\n');
fprintf(fid,'--------------End Waterplane Mesh File---------------\r\n');
fclose(fid);

Leave a Comment

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