create_circle_mesh_gmsh

PURPOSE ^

Create a 2D Circular FEM using GMSH

SYNOPSIS ^

function mdl = create_circle_mesh_gmsh(basename, center, rad, elem_size )

DESCRIPTION ^

 Create a 2D Circular FEM using GMSH
 mdl= CREATE_GMSH_2D_CIRCLE(rad, n_elec)

 mdl - EIDORS forward model
 rad - model radius

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function mdl = create_circle_mesh_gmsh(basename, center, rad, elem_size )
0002 % Create a 2D Circular FEM using GMSH
0003 % mdl= CREATE_GMSH_2D_CIRCLE(rad, n_elec)
0004 %
0005 % mdl - EIDORS forward model
0006 % rad - model radius
0007 
0008 % (C) 2009 Bartosz Sawicki. License: GPL version 2 or version 3
0009 % $Id: create_circle_mesh_gmsh.m 4954 2015-05-09 13:03:04Z bgrychtol $
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 % Points to define circle
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 % Internal circle and loop
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 % Call Gmsh
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.nodes    = vtx;
0063 mdl.elems    = simp;
0064 mdl.name = 'Circle';
0065 mdl= eidors_obj('fwd_model', mdl);
0066 
0067 
0068 function do_unit_test
0069 object_center = [0.0, 0.1];
0070 object_radius = 0.6;
0071 
0072 mdl = create_circle_mesh_gmsh('circle', object_center, object_radius, 0.04 );
0073 show_fem(mdl)

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005