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 fclose(geo_fid);
0052
0053
0054 disp('Calling Gmsh. Please wait ...');
0055 call_gmsh( geo_filename);
0056
0057 msh_filename = sprintf('%s.msh', basename);
0058
0059 disp(['Now reading back data from file: ' msh_filename])
0060
0061 [srf,vtx,fc,bc,simp,edg,mat_ind] = gmsh_read_mesh('circle.msh');
0062 mdl.type = 'fwd_model';
0063 mdl.name = 'GMSH Circle';
0064 mdl.nodes = vtx;
0065 mdl.elems = simp;
0066 mdl= eidors_obj('fwd_model', mdl);
0067
0068
0069 function do_unit_test
0070 object_center = [0.0, 0.1];
0071 object_radius = 0.6;
0072
0073 mdl = create_circle_mesh_gmsh('circle', object_center, object_radius, 0.04 );
0074 show_fem(mdl);