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