Changeset 14862


Ignore:
Timestamp:
05/02/13 15:21:57 (12 years ago)
Author:
bdef
Message:

NEW: export md.mesh to gmsh format

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/mesh/ExportGmsh.m ΒΆ

    r14845 r14862  
    99fid=fopen(filename,'w');
    1010
    11 %initialiation
    12 fprintf(fid,'\n%s\n%i\n','MeshVersionFormatted',1);
     11%initialiaion
     12fprintf(fid,'$MeshFormat \n');
     13fprintf(fid,'2.2 0 8 \n');
     14fprintf(fid,'$EndMeshFormat \n');
     15fprintf(fid,'$Nodes \n');
     16fprintf(fid,'%i \n',md.mesh.numberofvertices);
     17np=0;
     18%printing point positions
     19for ii=1:md.mesh.numberofvertices
     20        np = np+1;
     21        fprintf(fid,'%g %14.7e %14.7e 0.0 \n',np,md.mesh.x(np),md.mesh.y(np));
     22end
    1323
    14 %dimension
    15 fprintf(fid,'\n%s\n%i\n','Dimension',2);
     24fprintf(fid,'$EndNodes \n');
     25fprintf(fid,'$Elements \n');
     26fprintf(fid,'%i \n',md.mesh.numberofelements+size(md.mesh.segments,1));
     27np=0;
    1628
    17 %Vertices
    18 fprintf(fid,'\n%s\n%i\n\n','Vertices',md.mesh.numberofvertices);
    19 fprintf(fid,'%8g %8g %i\n',[md.mesh.x md.mesh.y zeros(md.mesh.numberofvertices,1)]');
     29%printing elements caracteristics for boundaries
    2030
    21 %Triangles
    22 fprintf(fid,'\n\n%s\n%i\n\n','Triangles',md.mesh.numberofelements);
    23 fprintf(fid,'%i %i %i %i\n',[md.mesh.elements zeros(md.mesh.numberofelements,1)]');
    24 
     31for ii=1:size(md.mesh.segments,1)
     32        np = np+1;
     33        if(md.mesh.x(md.mesh.segments(np,1))==max(md.mesh.x(:))&&md.mesh.x(md.mesh.segments(np,2))==max(md.mesh.x(:))),
     34                bc_id=1;
     35        elseif(md.mesh.y(md.mesh.segments(np,1))==max(md.mesh.y(:))&&md.mesh.y(md.mesh.segments(np,2))==max(md.mesh.y(:))),
     36                bc_id=2;
     37        elseif(md.mesh.x(md.mesh.segments(np,1))==min(md.mesh.x(:))&&md.mesh.x(md.mesh.segments(np,2))==min(md.mesh.x(:))),
     38                bc_id=3;
     39        elseif(md.mesh.y(md.mesh.segments(np,1))==min(md.mesh.y(:))&&md.mesh.y(md.mesh.segments(np,2))==min(md.mesh.y(:))),
     40                bc_id=4;
     41  end
     42                fprintf(fid,'%g 1 2 %g 1 %g %g \n',np,bc_id,md.mesh.segments(np,1),md.mesh.segments(np,2));
     43end
     44%and for the body
     45body_id=1;
     46for ii=1:md.mesh.numberofelements
     47  np = np+1;
     48  fprintf(fid,'%g 2 2 %g 3 %g %g %g \n',np,body_id,md.mesh.elements(ii,1),md.mesh.elements(ii,2),md.mesh.elements(ii,3));
     49end
     50fprintf(fid,'$EndElements \n');
    2551%close
    2652fclose(fid);
    2753t2=clock;fprintf('%s\n',[' done (' num2str(etime(t2,t1)) ' seconds)']);
     54
Note: See TracChangeset for help on using the changeset viewer.