dm_2d_circ_pt_elecs

PURPOSE ^

DM_2D_CIRC_PT_ELECS: Create circle mesh (or radius 1) refined with electrodes

SYNOPSIS ^

function fmdl = dm_2d_circ_pt_elecs( elec_pts, pfix, spacing);

DESCRIPTION ^

 DM_2D_CIRC_PT_ELECS: Create circle mesh (or radius 1) refined with electrodes
 fmdl = dm_2d_circ_pt_elecs( elec_pts, pfix, spacing);
     at points on the electrodes
 fmdl = dm_2d_circ_pt_elecs( elec_pts, pfix, ...
               [base_spacing, refine_ratio, gradient]);
 elec_pts = cell fcn of N x [x,y,{z}] for each electrode
    normally only 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 = [])
 param(1) = base_spacing - edge length away from refined nodes (eg 0.1)
 param(2) = refine_ratio - relative refinement near points (eg. 10)
 param(3) = gradient     - transition slope of refinement (eg 0.1)

 Example: Three electrodes 2 on boundary and one internal
  elec_pts = {[1,0],[0,1;sin(0.2),cos(0.2)],[0.5,0.5]};
  fmdl= dm_2d_circ_pt_elecs( elec_pts, [], [0.15,10,0.05] );

 Example:
  n_elecs= 14; elec_width= 0.1; hw= elec_width/2;
  th = linspace(0,2*pi,n_elecs+1); th(end)=[];
  for i=1:n_elecs;
     ti = th(i) + [hw;-hw];
     elec_pts{i} = [sin(ti),cos(ti)];
  end
  fmdl= dm_2d_circ_pt_elecs( elec_pts, [], [0.10,10,0.02] );

 See also: dm_2d_pt_elecs

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function fmdl = dm_2d_circ_pt_elecs( elec_pts, pfix, spacing);
0002 % DM_2D_CIRC_PT_ELECS: Create circle mesh (or radius 1) refined with electrodes
0003 % fmdl = dm_2d_circ_pt_elecs( elec_pts, pfix, spacing);
0004 %     at points on the electrodes
0005 % fmdl = dm_2d_circ_pt_elecs( elec_pts, pfix, ...
0006 %               [base_spacing, refine_ratio, gradient]);
0007 % elec_pts = cell fcn of N x [x,y,{z}] for each electrode
0008 %    normally only 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 % param(1) = base_spacing - edge length away from refined nodes (eg 0.1)
0012 % param(2) = refine_ratio - relative refinement near points (eg. 10)
0013 % param(3) = gradient     - transition slope of refinement (eg 0.1)
0014 %
0015 % Example: Three electrodes 2 on boundary and one internal
0016 %  elec_pts = {[1,0],[0,1;sin(0.2),cos(0.2)],[0.5,0.5]};
0017 %  fmdl= dm_2d_circ_pt_elecs( elec_pts, [], [0.15,10,0.05] );
0018 %
0019 % Example:
0020 %  n_elecs= 14; elec_width= 0.1; hw= elec_width/2;
0021 %  th = linspace(0,2*pi,n_elecs+1); th(end)=[];
0022 %  for i=1:n_elecs;
0023 %     ti = th(i) + [hw;-hw];
0024 %     elec_pts{i} = [sin(ti),cos(ti)];
0025 %  end
0026 %  fmdl= dm_2d_circ_pt_elecs( elec_pts, [], [0.10,10,0.02] );
0027 %
0028 % See also: dm_2d_pt_elecs
0029 
0030 % (C) 2009 Andy Adler. License: GPL version 2 or version 3
0031 % $Id: dm_2d_circ_pt_elecs.m 5763 2018-05-20 11:26:26Z aadler $
0032 
0033 
0034 if ischar(elec_pts) && strcmp(elec_pts,'UNIT_TEST'); do_unit_test; return; end
0035 if ischar(elec_pts) && strcmp(elec_pts,'CALIBRATE'); do_calibrate; return; end
0036 
0037 copt.cache_obj = {elec_pts, spacing};
0038 copt.fstr = 'dm_2d_circ_pt_elecs';
0039 fmdl = eidors_cache(@do_circ_pt_elecs,{elec_pts, pfix, spacing}, copt);
0040 
0041 function fmdl = do_circ_pt_elecs( elec_pts, pfix, spacing )
0042 params.base_spacing = spacing(1);
0043 params.refine_ratio = spacing(2);
0044 params.gradient     = spacing(3);
0045 
0046 bbox= [-1,-1;1,1];
0047 
0048 eidors_cache('boost_priority',-4);
0049 fmdl= dm_2d_pt_elecs( elec_pts, [], params, @circle, [-1,-1;1,1] );
0050 eidors_cache('boost_priority',+4);
0051 
0052 fmdl.name = sprintf('dm_2d_circ_pt_elec');
0053 fmdl.normalize_measurements = 0; %default
0054 
0055 function d= circle(p,params);
0056   d = sqrt(sum(p.^2,2)) - 1; 
0057 
0058 %%%%%%%%%%%%%%%%%%%%%%%%%%%% TESTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0059 
0060 function do_unit_test
0061    elec_pts = {[1,0],[0,1;sin(0.2),cos(0.2)],[0.5,0.5]};
0062    fmdl= dm_2d_circ_pt_elecs( elec_pts, [], [0.15,10,0.05] );
0063    subplot(221); show_fem(fmdl);
0064    for i=1:length(elec_pts)
0065       unit_test_cmp(sprintf('Elec%d(%d)',1,i), ...
0066          mean(fmdl.nodes(fmdl.electrode(i).nodes,:),1), mean(elec_pts{i},1), .01);
0067    end
0068 
0069 
0070 % Example:
0071    n_elecs= 14; elec_width= 0.1; hw= elec_width/2;
0072    th = linspace(0,2*pi,n_elecs+1); th(end)=[];
0073    for i=1:n_elecs;
0074       ti = th(i) + [hw;-hw];
0075       elec_pts{i} = [sin(ti),cos(ti)];
0076    end
0077    fmdl= dm_2d_circ_pt_elecs( elec_pts, [], [0.10,10,0.02] );
0078    subplot(222); show_fem(fmdl)
0079    for i=1:length(elec_pts)
0080       unit_test_cmp(sprintf('Elec%d(%d)',2,i), ...
0081          mean(fmdl.nodes(fmdl.electrode(i).nodes,:),1), mean(elec_pts{i},1), .01);
0082    end
0083    eidors_msg('CHECK FIGURE - should have 3 and 16 electrodes',0);
0084 
0085 % find example models that work well with the values defined in mk_common_model
0086 function do_calibrate
0087 
0088 % meas = calc_range(0.05*([1,1.1,1.2,1.4,1.6,2.0,2.5,3,4,5,7,10,15,20]),0,1)
0089   meas = calc_range(0.02,3,0.10),%- level 1
0090 % meas = calc_range(0.03,10,0.05),%- level 3
0091 
0092 % meas = calc_range(0.02,10,0.05),%- level 3
0093 % meas = calc_range(0.02,20,0.05),%- level 3
0094  % As a start, set p2 = 1. This is uniform, and we can choose the
0095  % target refinement levels, and calculate the centre mesh density
0096  % OR setting p3=1 also gives uniform
0097 
0098 function meas = calc_range(p1range,p2,p3)
0099   n_elecs= 8; elec_width= 0.1; hw= elec_width/2;
0100   th = linspace(0,2*pi,n_elecs+1); th(end)=[];
0101   for i=1:n_elecs;
0102      ti = th(i) + [hw;-hw];
0103      elec_pts{i} = [sin(ti),cos(ti)];
0104   end
0105 
0106   for i = 1:length(p1range)
0107      p1 = p1range(i);
0108      fmdl= dm_2d_circ_pt_elecs( elec_pts, [], [p1,p2,p3]);
0109      nd= fmdl.nodes; nn= size(nd,1);
0110      ne= size(fmdl.elems,1);
0111      nc= sum( nd(:,1).^2 + nd(:,2).^2 < 0.5^2);
0112      nl= sum( (nd(:,1)-1).^2 + nd(:,2).^2 < 0.2^2);
0113      meas(i,:) = [p1,p2,p3,[nn,ne,nc,nl]/1000];
0114 
0115   end;
0116 show_fem(fmdl)
0117

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