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 5764 2018-05-20 11:52:19Z aadler $
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    nodesi = get_elec_nodes(elec_pts{i}, p, ubn);
0045    if isempty(nodesi);
0046       % If not on boundary, try all nodes
0047       nodesi = get_elec_nodes(elec_pts{i}, p, (1:size(p,1))');
0048    end
0049    electrode(i).nodes     = nodesi;
0050    electrode(i).z_contact = 0.01; % nominal
0051 end
0052 
0053 fmdl.nodes= p;
0054 fmdl.elems= t;
0055 fmdl.boundary = bdy;
0056 fmdl.type = 'fwd_model';
0057 fmdl.name = 'dm_2d_pt_elec';
0058 fmdl.electrode = electrode;
0059 fmdl.gnd_node=           1;
0060 
0061 
0062 % Find the nodes associated with a given electrode
0063 %   electrode(i).nodes = get_elec_nodes(elec_pts{i}, p, ubn);
0064 % electrode points are no further from each end point
0065 %   than the elecs are from each other
0066 function nodes= get_elec_nodes( epts, p, ubn);
0067    tol = 1e-6;
0068    nodes = ubn;
0069    bp    = p(ubn,:); % Unique points on the boundary
0070    lep = size(epts,1);
0071    oep = ones(lep,1);
0072    onp = ones(size(ubn,1),1);
0073    for i=1:lep
0074       el = epts(i,:);
0075       % Distance to other electrodes
0076       de = oep*el - epts;
0077       de = sqrt( sum( de.^2,2 ));
0078       mde= max(de);
0079       % Distance to other points
0080       dp = onp*el - bp;
0081       dp = sqrt( sum( dp.^2,2 ));
0082       % Zero outside points
0083       nodes( dp > mde+tol ) = 0;
0084    end
0085    nodes = nodes( nodes>0 );

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