function ToHypermesh_FEM(p,t,filename) %------- Elements must be all tetrahedral or all hexahedral ----------------- [row,col]=size(p); if row~=3 && col==3 p = p'; end [~,col]=size(t); if (col==4||col==8) t = t'; end if ~ismember(".fem",filename) content = strsplit(filename,'.'); filename =[ content{1},'.fem']; end fid = fopen(filename,'w'); % % % --------------- Print start mark ---------------------------+ fprintf(fid, '%s\n', 'BEGIN BULK'); % % % --------------- Print nodes ---------------------------+ for ii=1:size(p,2) fprintf(fid, '%s', 'GRID,' ); fprintf(fid, '%d,,', ii ); fprintf(fid, '%f,%f,%f\n', p(:,ii)' ); end fprintf(fid, '%s\n', '$'); % % % --------------- Print elements ---------------------------+ if(size(t,1)==4) for ii=1:size(t,2) fprintf(fid, '%s, ', 'CTETRA' ); fprintf(fid, '%d, ', ii ); fprintf(fid, '%d, ', 1 ); fprintf(fid, '%d,%d,%d,%d\n', t(1:4,ii)' ); end elseif(size(t,1)==8) for ii=1:size(t,2) fprintf(fid, '%s, ', 'CHEXA' ); fprintf(fid, '%d, ', ii ); fprintf(fid, '%d, ', 1 ); fprintf(fid, '%d,%d,%d,%d,%d,%d\n', t(1:6,ii)' ); %% fixed_format fprintf(fid, '%s', ' ,'); fprintf(fid, '%d,%d\n', t(7:8,ii)' ); end end fprintf(fid, '%s\n', '$'); % % % --------------- Print end mark ---------------------------+ fprintf(fid, '%s\n', 'ENDDATA'); fclose(fid);View Code
Htpermesh ---import---Optistuct