find_electrode_bdy

PURPOSE ^

FIND_ELECTRODE_BDY: find the boundary index area for electrode

SYNOPSIS ^

function [bdy_idx, bdy_area] = find_electrode_bdy( bdy, vtx, elec_nodes)

DESCRIPTION ^

 FIND_ELECTRODE_BDY: find the boundary index area for electrode
 Input:
   bdy => boundary (from fwd_model.boundary) bdy simplices x nodes index 
   vtx => node pts (from fwd_model.nodes)
   elec_nodes => index of nodes in the electrode
 Output:
   bdy_idx  => vector of boundary simplices in this electrode
   bdy_area => boundary area of each simplex in bdy_idx
  if the nodes in the electrode are points, then
   bdy_area is the area corresponding to these point electrodes

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [bdy_idx, bdy_area] = find_electrode_bdy( bdy, vtx, elec_nodes)
0002 % FIND_ELECTRODE_BDY: find the boundary index area for electrode
0003 % Input:
0004 %   bdy => boundary (from fwd_model.boundary) bdy simplices x nodes index
0005 %   vtx => node pts (from fwd_model.nodes)
0006 %   elec_nodes => index of nodes in the electrode
0007 % Output:
0008 %   bdy_idx  => vector of boundary simplices in this electrode
0009 %   bdy_area => boundary area of each simplex in bdy_idx
0010 %  if the nodes in the electrode are points, then
0011 %   bdy_area is the area corresponding to these point electrodes
0012 
0013 % (C) 2008 Andy Adler. License: GPL version 2 or version 3
0014 % $Id: find_electrode_bdy.m 4105 2013-05-29 13:21:32Z aadler $
0015 
0016 [bdy_idx, point] = find_bdy_idx( bdy, elec_nodes);
0017 if nargout==1; return;end
0018 
0019 l_bdy_idx= length(bdy_idx);
0020 l_point= length(point);
0021 
0022 if l_bdy_idx > 0 && l_point ==0
0023    bdy_area= zeros(1, l_bdy_idx);
0024 
0025    for i=1:l_bdy_idx
0026       bdy_nodes   = bdy(bdy_idx(i),:);
0027       bdy_area(i) = tria_area( vtx(bdy_nodes,:) );
0028    end
0029 elseif l_bdy_idx == 0 && l_point >0
0030    dims = size(bdy,2); 
0031    l_point= length(point);
0032    bdy_area = zeros(l_point,1);
0033    for i=1:l_point
0034      ff= find( any(bdy== point(i),2) );
0035      this_area= 0;
0036      for ffp=ff(:)'
0037         xyz= vtx( bdy(ffp,:),:);
0038         this_area= this_area + tria_area( xyz );
0039      end
0040      bdy_area(i)= bdy_area(i) + this_area/dims;
0041    end
0042 else
0043    error('Can''t model this electrode. It has %d CEM and %d point nodes.', ...
0044             l_bdy_idx, l_point )
0045 end
0046    
0047 
0048 
0049 % Find which boundary nodes are part of a
0050 % complete simplex. These nodes can be made
0051 % into complete electrode model elements
0052 %
0053 % Any nodes left will be treated as point electrodes
0054 function [ffb,unused] = find_bdy_idx( bdy, elec_nodes);
0055    bdy_els = zeros(size(bdy,1),1);
0056    elec_nodes = unique(elec_nodes);
0057    for nd= elec_nodes(:)'
0058       bdy_els = bdy_els + any(bdy==nd,2);
0059    end
0060    ffb = find(bdy_els == size(bdy,2));
0061 
0062 %  find if all nodes are used
0063    used_nodes= reshape( bdy(ffb,:), 1,[]);
0064    unused=     setdiff( elec_nodes, used_nodes);
0065    
0066 
0067 % bdy points is [x1,y1,z1;x2,y2,z2; etc]
0068 function area= tria_area( bdy_pts ); 
0069    vectors= diff(bdy_pts); 
0070    if size(vectors,1)==2
0071       vectors= cross(vectors(1,:),vectors(2,:));
0072    end
0073    d= size(bdy_pts,1);
0074    area= sqrt( sum(vectors.^2) )/( d-1 );
0075

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