0001 function mdl = create_circle_mesh_gmsh(basename, center, rad, elem_size )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 if ischar(basename) && strcmp(basename,'UNIT_TEST'),do_unit_test,return,end
0012
0013 geo_filename = sprintf('%s.geo', basename);
0014 geo_fid= fopen(geo_filename,'w');
0015
0016 point_no = 1;
0017
0018 center_no = point_no;
0019 fprintf(geo_fid,'Point(%d) = {%f, %f, 0, %f};\n',center_no, ...
0020 center(1), center(2), 1);
0021 point_no = point_no + 1;
0022 inpoint1_no = point_no;
0023 fprintf(geo_fid,'Point(%d) = {%f, %f, 0, %f};\n',inpoint1_no, ...
0024 center(1)+rad, center(2), elem_size);
0025 point_no = point_no + 1;
0026 inpoint2_no = point_no;
0027 fprintf(geo_fid,'Point(%d) = {%f, %f, 0, %f};\n',inpoint2_no, ...
0028 center(1)-rad, center(2), elem_size);
0029 point_no = point_no + 1;
0030
0031
0032 line_no = 1;
0033
0034 circle1_no = line_no;
0035 line_no = line_no + 1;
0036 fprintf(geo_fid,'Circle(%d) = {%d, %d, %d};\n', circle1_no, inpoint1_no, ...
0037 center_no, inpoint2_no);
0038 circle2_no = line_no;
0039 line_no = line_no + 1;
0040 fprintf(geo_fid,'Circle(%d) = {%d, %d, %d};\n', circle2_no, inpoint2_no, ...
0041 center_no, inpoint1_no);
0042
0043 loop_no = line_no;
0044 line_no = line_no + 1;
0045 fprintf(geo_fid,'Line Loop(%d) = {%d,%d};\n', loop_no, circle1_no, ...
0046 circle2_no);
0047
0048 fprintf(geo_fid, 'Plane Surface(%d) = {%d};\n', line_no, loop_no);
0049 line_no = line_no + 1;
0050
0051 fprintf(geo_fid, 'Mesh 2;');
0052
0053 fclose(geo_fid);
0054
0055
0056 disp('Calling Gmsh. Please wait ...');
0057 call_gmsh( geo_filename);
0058
0059 msh_filename = sprintf('%s.msh', basename);
0060
0061 disp(['Now reading back data from file: ' msh_filename])
0062
0063 [srf,vtx,fc,bc,simp,edg,mat_ind] = gmsh_read_mesh('circle.msh');
0064 mdl.type = 'fwd_model';
0065 mdl.name = 'GMSH Circle';
0066 mdl.nodes = vtx;
0067 mdl.elems = simp;
0068 mdl= eidors_obj('fwd_model', mdl);
0069
0070
0071 function do_unit_test
0072 object_center = [0.0, 0.1];
0073 object_radius = 0.6;
0074
0075 mdl = create_circle_mesh_gmsh('circle', object_center, object_radius, 0.04 );
0076 show_fem(mdl);