mk_hollow_electrode

PURPOSE ^

MK_HOLLOW_ELECTRODE: remove nodes with indicated electrdoes

SYNOPSIS ^

function fmdl = mk_hollow_electrode(fmdl, elec_idx)

DESCRIPTION ^

 MK_HOLLOW_ELECTRODE: remove nodes with indicated electrdoes
 fmdl_out = mk_hollow_electrode(fmdl, elec_idx)
   fmdl:     input model
   elec_idx: electrodes for which we remove internal nodes
             if not provided, remove for all electrodes
   fmdl_out: output model

 This function is useful for internal electrodes created by
   meshing software in which we don't want to calculate current
   flow within the electrode

 Limitations: currently works for 2D fems only
 Recommended replacement: mat_idx_to_electrode

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function fmdl = mk_hollow_electrode(fmdl, elec_idx)
0002 % MK_HOLLOW_ELECTRODE: remove nodes with indicated electrdoes
0003 % fmdl_out = mk_hollow_electrode(fmdl, elec_idx)
0004 %   fmdl:     input model
0005 %   elec_idx: electrodes for which we remove internal nodes
0006 %             if not provided, remove for all electrodes
0007 %   fmdl_out: output model
0008 %
0009 % This function is useful for internal electrodes created by
0010 %   meshing software in which we don't want to calculate current
0011 %   flow within the electrode
0012 %
0013 % Limitations: currently works for 2D fems only
0014 % Recommended replacement: mat_idx_to_electrode
0015 
0016 % (C) 2017 Andy Adler and Bartek Grychtol. License: GPL v2 or v3. $Id: mk_hollow_electrode.m 6316 2022-04-21 11:14:35Z aadler $
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(:)'; % Row vector to index for loop
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 % find all electrode elems
0031 ELELEM = sum(ELNODES(fmdl.elems),2)==3;
0032 % remove internal electrode elements
0033 fmdl.elems = fmdl.elems(~ELELEM,:);
0034 % used nodes
0035 unodes = unique(fmdl.elems);
0036 % remove internal electrode nodes
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 % remove unused nodes
0045 fmdl.nodes = fmdl.nodes(unodes,:);
0046 %remap elems
0047 fmdl.elems = nodemap(fmdl.elems);
0048 %remap elecs
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 % if not in specified index, don't reorder loop
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);

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005