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] );
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 6926 2024-05-31 15:34:13Z bgrychtol $ 0032 0033 if ischar(elec_pts) && strcmp(elec_pts,'UNIT_TEST'), do_unit_test; return; end 0034 0035 epfix = vertcat(elec_pts{:}); 0036 params.refine_pts = epfix; 0037 0038 [p,t] = distmeshnd(shapefn,@dm_refine_points,params.base_spacing/2, ... 0039 bbox,[pfix;epfix],params); 0040 0041 bdy = find_boundary(t); 0042 ubn = unique(bdy(:)); 0043 0044 for i=1:length(elec_pts); 0045 nodesi = get_elec_nodes(elec_pts{i}, p, ubn); 0046 if isempty(nodesi); 0047 % If not on boundary, try all nodes 0048 nodesi = get_elec_nodes(elec_pts{i}, p, (1:size(p,1))'); 0049 end 0050 electrode(i).nodes = nodesi; 0051 electrode(i).z_contact = 0.01; % nominal 0052 end 0053 0054 fmdl.nodes= p; 0055 fmdl.elems= t; 0056 fmdl.boundary = bdy; 0057 fmdl.name = 'dm_2d_pt_elec'; 0058 fmdl.electrode = electrode; 0059 fmdl.gnd_node= 1; 0060 0061 fmdl = eidors_obj('fwd_model', fmdl); 0062 0063 % Find the nodes associated with a given electrode 0064 % electrode(i).nodes = get_elec_nodes(elec_pts{i}, p, ubn); 0065 % electrode points are no further from each end point 0066 % than the elecs are from each other 0067 function nodes= get_elec_nodes( epts, p, ubn); 0068 tol = 1e-6; 0069 nodes = ubn; 0070 bp = p(ubn,:); % Unique points on the boundary 0071 lep = size(epts,1); 0072 oep = ones(lep,1); 0073 onp = ones(size(ubn,1),1); 0074 for i=1:lep 0075 el = epts(i,:); 0076 % Distance to other electrodes 0077 de = oep*el - epts; 0078 de = sqrt( sum( de.^2,2 )); 0079 mde= max(de); 0080 % Distance to other points 0081 dp = onp*el - bp; 0082 dp = sqrt( sum( dp.^2,2 )); 0083 % Zero outside points 0084 nodes( dp > mde+tol ) = 0; 0085 end 0086 nodes = nodes( nodes>0 ); 0087 0088 function do_unit_test 0089 elec_pts = {[1,0],[0,1;sin(0.2),cos(0.2)],[0.5,0.5]}; 0090 shapefn = inline('sqrt(sum(p.^2,2))-params.rad','p','params'); % Circle 0091 params.rad = 1; 0092 params.base_spacing = 0.06; 0093 params.refine_ratio = 10; 0094 params.gradient = 0.05; 0095 fmdl= dm_2d_pt_elecs( elec_pts, [], params, shapefn, [-1,-1;1,1] ); 0096 show_fem(fmdl);