0001 function fmdl = mk_hollow_electrode(fmdl, elec_idx)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if ischar(fmdl) && strcmp(fmdl,'UNIT_TEST'); do_unit_test; return; end
0021
0022 if nargin==1; elec_idx = 1:length(fmdl.electrode); end
0023 elec_idx = elec_idx(:)';
0024
0025 elidx=[];
0026 for i = elec_idx
0027 elidx = [elidx, fmdl.electrode(i).nodes];
0028 end
0029
0030 ELNODES = zeros(size(fmdl.nodes,1),1);
0031 ELNODES(elidx) = 1;
0032
0033 ELELEM = sum(ELNODES(fmdl.elems),2)==3;
0034
0035 fmdl.elems = fmdl.elems(~ELELEM,:);
0036
0037 unodes = unique(fmdl.elems);
0038
0039 for i = elec_idx
0040 idx = ismember(fmdl.electrode(i).nodes,unodes);
0041 fmdl.electrode(i).nodes = fmdl.electrode(i).nodes(idx);
0042 end
0043
0044 nodemap = zeros(size(fmdl.nodes,1),1);
0045 nodemap(unodes) = 1:numel(unodes);
0046
0047 fmdl.nodes = fmdl.nodes(unodes,:);
0048
0049 fmdl.elems = nodemap(fmdl.elems);
0050
0051 for i = 1:length(fmdl.electrode)
0052 idx = ismember(fmdl.electrode(i).nodes,unodes);
0053 nidx = nodemap( fmdl.electrode(i).nodes(idx) );
0054 if any(i==elec_idx);
0055 npts = fmdl.nodes(nidx,:);
0056 [npts_o, nnidx] = order_loop(npts);
0057 fmdl.electrode(i).nodes = nidx(nnidx);
0058 else
0059 fmdl.electrode(i).nodes = nidx;
0060 end
0061 end
0062
0063
0064 fmdl.boundary = find_boundary(fmdl);
0065
0066 [~,idx] = min(sum(fmdl.nodes.^2,2));
0067 fmdl.gnd_node = idx(1);
0068
0069
0070 fmdl = eidors_obj('set', fmdl);
0071
0072 function do_unit_test
0073 fmdl = unit_test_model1;
0074 subplot(221); show_fem(fmdl); axis([-.1,.3,0.4,0.8])
0075 title 'original model - filled electrodes';
0076 fmdl1= mk_hollow_electrode(fmdl,[1,2,5]);
0077
0078 subplot(222); show_fem(fmdl1); axis([-.1,.3,0.4,0.8])
0079 title 'original model - hollow electrode #1';
0080
0081 fmdl2= mk_hollow_electrode(fmdl);
0082 subplot(223); show_fem(fmdl2); axis([-.1,.3,0.4,0.8])
0083 title 'original model - all hollow electrode';
0084
0085 fmdl = unit_test_model2;
0086 fmdl4= mk_hollow_electrode(fmdl, length(fmdl.electrode));
0087 subplot(224); show_fem(fmdl4); axis([-1,1,-1,1])
0088 title 'original model - one electrode';
0089
0090
0091 function fmdl = unit_test_model1
0092 R=0.65; Nel = 16;
0093 shape_str = [ ...
0094 'solid incyl = cylinder (0,0,0; 0,0,1; 0.125) -maxh=0.015;\n', ...
0095 'solid farcyl = cylinder (0,0,0; 0,0,1;0.75) -maxh=0.55;\n' ...
0096 'solid pl1 = plane(0,0,-0.09;0,0,-1);\n' ...
0097 'solid top = plane(0,0,0; 0,0,1) -maxh=0.13;\n' ...
0098 'solid mainobj= pl1 and top and farcyl and not incyl;\n'];
0099 elec_pos = zeros(Nel,6);
0100 Theta = 0:360/Nel:360-360/Nel;
0101 for i = 1:Nel
0102 elec_pos(i,1) = R*sind(Theta(i));
0103 elec_pos(i,2) = R*cosd(Theta(i));
0104 elec_pos(i,6) = 1;
0105 elec_obj(i) = {'top'};
0106 end
0107 elec_shape=[0.025];
0108 fmdl = ng_mk_gen_models(shape_str, elec_pos, elec_shape, elec_obj);
0109 fmdl = mdl2d_from3d(fmdl);
0110
0111 function fmdl = unit_test_model2
0112 extra={'ball', ...
0113 ['solid cyls= cylinder(0.2,0.2,0;0.2,0.2,1;0.2) -maxh=0.05;' ...
0114 'solid ball= cyls and orthobrick(-1,-1,0;1,1,0.5);']};
0115 fmdl= ng_mk_cyl_models(0,[6],[0.1,0,0.05],extra);
0116 eln = find(elem_select(fmdl, '(x-0.2).^2+(y-0.2).^2<0.2^2'));
0117 eln = unique(fmdl.elems(eln,:));
0118 fmdl.electrode(end+1) = struct('nodes', eln(:)', 'z_contact', .01);