dm_2d_pt_elecs

PURPOSE ^

DM_2D_PT_ELECS: Create circle mesh (or radius 1) refined

SYNOPSIS ^

function fmdl = dm_2d_pt_elecs( elec_pts, pfix, params, shapefn, bbox);

DESCRIPTION ^

 DM_2D_PT_ELECS: Create circle mesh (or radius 1) refined
     at points on the electrodes

 fmdl = dm_2d_circ_pt_elecs( elec_pts, pfix, spacinf, shapefn, bbox)

 elec_pts = cell fcn of N x [x,y,{z}] for each electrode
    normally one or two points are specified (at start and end of electrode)
    eg elec_pts{1} = [-.1,1;.1,1];
 pfix = any fixed points to provide to the model (default = [])

 params is a structure with fields (you can add more as required)
   params.base_spacing - edge length away from refined nodes (eg 0.1)
   params.refine_ratio - relative refinement near points (eg. 10)
   params.gradient     - transition slope of refinement (eg 0.1)

 shapefn = distmesh shapefn (calculates distance to boundary)

 bbox = bounding box of the space

 Example:
  elec_pts = {[1,0],[0,1;sin(0.2),cos(0.2)],[0.5,0.5]};
  shapefn = inline('sqrt(sum(p.^2,2))-params.rad','p','params'); % Circle
  params.rad = 1;
  params.base_spacing = 0.06;
  params.refine_ratio = 10;
  params.gradient     = 0.05;
  fmdl= dm_2d_pt_elecs( elec_pts, [], params, shapefn, [-1,-1;1,1] );

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function fmdl = dm_2d_pt_elecs( elec_pts, pfix, params, shapefn, bbox);
0002 % DM_2D_PT_ELECS: Create circle mesh (or radius 1) refined
0003 %     at points on the electrodes
0004 %
0005 % fmdl = dm_2d_circ_pt_elecs( elec_pts, pfix, spacinf, shapefn, bbox)
0006 %
0007 % elec_pts = cell fcn of N x [x,y,{z}] for each electrode
0008 %    normally one or two points are specified (at start and end of electrode)
0009 %    eg elec_pts{1} = [-.1,1;.1,1];
0010 % pfix = any fixed points to provide to the model (default = [])
0011 %
0012 % params is a structure with fields (you can add more as required)
0013 %   params.base_spacing - edge length away from refined nodes (eg 0.1)
0014 %   params.refine_ratio - relative refinement near points (eg. 10)
0015 %   params.gradient     - transition slope of refinement (eg 0.1)
0016 %
0017 % shapefn = distmesh shapefn (calculates distance to boundary)
0018 %
0019 % bbox = bounding box of the space
0020 %
0021 % Example:
0022 %  elec_pts = {[1,0],[0,1;sin(0.2),cos(0.2)],[0.5,0.5]};
0023 %  shapefn = inline('sqrt(sum(p.^2,2))-params.rad','p','params'); % Circle
0024 %  params.rad = 1;
0025 %  params.base_spacing = 0.06;
0026 %  params.refine_ratio = 10;
0027 %  params.gradient     = 0.05;
0028 %  fmdl= dm_2d_pt_elecs( elec_pts, [], params, shapefn, [-1,-1;1,1] );
0029 
0030 % (C) 2009 Andy Adler. License: GPL version 2 or version 3
0031 % $Id: dm_2d_pt_elecs.m 3233 2012-06-30 09:41:01Z bgrychtol $
0032 
0033 
0034 epfix = vertcat(elec_pts{:});
0035 params.refine_pts   = epfix;
0036 
0037 [p,t] = distmeshnd(shapefn,@dm_refine_points,params.base_spacing/2,  ...
0038            bbox,[pfix;epfix],params);
0039 
0040 bdy = find_boundary(t);
0041 ubn = unique(bdy(:));
0042 
0043 for i=1:length(elec_pts);
0044    electrode(i).nodes     = get_elec_nodes(elec_pts{i}, p, ubn);
0045    electrode(i).z_contact = 0.01; % nominal
0046 end
0047 
0048 fmdl.nodes= p;
0049 fmdl.elems= t;
0050 fmdl.boundary = bdy;
0051 fmdl.type = 'fwd_model';
0052 fmdl.name = 'dm_2d_pt_elec';
0053 fmdl.electrode = electrode;
0054 fmdl.gnd_node=           1;
0055 
0056 
0057 % Find the nodes associated with a given electrode
0058 %   electrode(i).nodes = get_elec_nodes(elec_pts{i}, p, ubn);
0059 % electrode points are no further from each end point
0060 %   than the elecs are from each other
0061 function nodes= get_elec_nodes( epts, p, ubn);
0062    tol = 1e-6;
0063    nodes = ubn;
0064    bp    = p(ubn,:); % Unique points on the boundary
0065    lep = size(epts,1);
0066    oep = ones(lep,1);
0067    onp = ones(size(ubn,1),1);
0068    for i=1:lep
0069       el = epts(i,:);
0070       % Distance to other electrodes
0071       de = oep*el - epts;
0072       de = sqrt( sum( de.^2,2 ));
0073       mde= max(de);
0074       % Distance to other points
0075       dp = onp*el - bp;
0076       dp = sqrt( sum( dp.^2,2 ));
0077       % Zero outside points
0078       nodes( dp > mde+tol ) = 0;
0079    end
0080    nodes = nodes( nodes>0 );

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