0001 function param= mk_circ_tank(rings, levels, elec_spec );
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 if ischar(rings) && strcmp(rings,'UNIT_TEST'); do_unit_test; return; end
0046
0047
0048
0049 n_elec= [];
0050 if size(elec_spec) == [1,1] if isnumeric(elec_spec)
0051 n_elec= elec_spec;
0052 end; end
0053
0054 [elem, node, bdy, point_elec_nodes, node_order] = mk_2D_model( rings );
0055
0056 if isempty( levels )
0057
0058 if n_elec==0
0059 elec_nodes= [];
0060 elseif ~isempty( n_elec )
0061 idx= (0:n_elec-1)*length(point_elec_nodes)/n_elec + 1;
0062 if any(rem(idx,1) ~= 0);
0063 error('The requested number of electrodes (%d) is not compatible with this FEM mesh', n_elec)
0064 end
0065 elec_nodes= point_elec_nodes( idx );
0066 else
0067 error('2D models only support scalar electrode patterns');
0068 end
0069 else
0070 [elem, node, bdy, point_elec_nodes] = mk_3D_model( elem, node, ...
0071 levels, bdy, point_elec_nodes, node_order );
0072
0073 if n_elec==0
0074 elec_nodes= [];
0075 elseif ~isempty( n_elec )
0076 idx= (0:n_elec-1)*length(point_elec_nodes)/n_elec + 1;
0077 half_lev = ceil( length(levels)/2 );
0078 elec_nodes= point_elec_nodes( half_lev, idx );
0079 else
0080 elec_nodes= electrode_pattern( point_elec_nodes, elec_spec );
0081 end
0082
0083 end
0084
0085 param.name= sprintf('EIT FEM by mk_circ_tank with N=%d levs=%d', ...
0086 rings, length(levels) );
0087 param.nodes = node';
0088 param.elems = elem';
0089 param.boundary = bdy';
0090 param.gnd_node = 1;
0091 if ~isempty( elec_nodes)
0092 param.electrode = mk_electrodes( elec_nodes );
0093 end
0094 param.type = 'fwd_model';
0095
0096 param.normalize_measurements = 0;
0097
0098 return;
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 function elec_nodes= electrode_pattern( point_elec_nodes, elec_spec )
0110 elec_nodes= [];
0111 lpe = size(point_elec_nodes,2);
0112 nlev= size(point_elec_nodes,1);
0113 for i=1:3:length(elec_spec)-2
0114 spec = elec_spec{i};
0115 if strcmp( spec,'planes' )
0116 n_elec= elec_spec{i+1};
0117 levs = elec_spec{i+2};
0118
0119 eidx= (0:n_elec-1);
0120 idx= round(eidx*lpe/n_elec) + 1;
0121 nodes= point_elec_nodes( levs, idx )';
0122 elec_nodes= [ elec_nodes; nodes(:) ];
0123 elseif strcmp( spec,'zigzag' )
0124 n_elec= elec_spec{i+1};
0125 levs = elec_spec{i+2};
0126 if any(levs > size(point_elec_nodes,1))
0127 error('requested electrode plane larger than FEModel');
0128 end
0129
0130 eidx= (0:n_elec-1);
0131 idx= round(eidx*lpe/n_elec)*nlev + ...
0132 levs( rem( eidx, length(levs))+1);
0133 nodes= point_elec_nodes( idx );
0134 elec_nodes= [ elec_nodes; nodes(:) ];
0135 else
0136 error('elec_spec parameter not understood');
0137 end
0138 end
0139
0140
0141
0142 function [ELEM, NODE, bdy_nodes, point_elec_nodes, NODE_order] = ...
0143 mk_2D_model( N );
0144 ELEM=[];
0145 NODE= [0;0];
0146 NODE_order= [1];
0147 int=1;
0148 for k=1:N
0149 phi= (0:4*k-1)*pi/2/k;
0150 NODE= [NODE k/N*[sin(phi);cos(phi)]];
0151
0152
0153
0154 NOq= rem(k+(0:k),3)+1;
0155 NODE_order= [NODE_order, NOq([1:k, k+1:-1:2, 1:k, k+1:-1:2])];
0156
0157 ext= 2*(k*k-k+1);
0158 idxe=[0:k-1; 1:k];
0159 idxi=[0:k-1];
0160 elem= [ ext+idxe, ext+2*k+[-idxe idxe], ...
0161 ext+rem(4*k-idxe,4*k), ...
0162 ext+idxe, ext+2*k+[-idxe idxe], ...
0163 ext+rem(4*k-idxe,4*k);
0164 int+idxi, int+2*(k-1)+[-idxi, idxi], ...
0165 int+rem(4*(k-1)-idxi, 4*(k-1)+(k==1) ) ...
0166 ext+4*k+1+idxi, ...
0167 ext+6*k+ [1-idxi 3+idxi], ...
0168 ext+8*k+3-idxi ];
0169 for j=1:k
0170 r1= rem(j+k-1,3)+1;
0171 r2= rem(j+k,3)+1;
0172 r3= 6-r1-r2;
0173 elem([r1 r2 r3],j+k*(0:7) )= elem(:,j+k*(0:7));
0174 end
0175
0176 ELEM=[ ELEM elem(:,1:(8-4*(k==N))*k) ];
0177 int=ext;
0178 end
0179
0180 bdy_nodes= [ (ext :ext+N*4-1) ; ...
0181 (ext+1:ext+N*4-1), ext ];
0182 point_elec_nodes= (ext):(ext+N*4-1) ;
0183
0184
0185
0186
0187
0188
0189
0190
0191 function [ELEM, NODE, BDY, elec_nodes] = mk_3D_model( ...
0192 elem0, node0, niveaux, bdy, elec_nodes0, node_order );
0193
0194 elem0= node_reorder( elem0, node_order);
0195
0196 d= size(elem0,1);
0197 n= size(node0,2);
0198 e= size(elem0,2);
0199
0200
0201 elem_odd= [elem0([3,2,1,1],:), ...
0202 elem0([3,2,2,1],:), ...
0203 elem0([3,3,2,1],:)];
0204 elem_even=[elem0([1,2,3,3],:), ...
0205 elem0([1,2,2,3],:), ...
0206 elem0([1,1,2,3],:)];
0207
0208 NODE= [node0; niveaux(1)*ones(1,n) ];
0209 ELEM= [];
0210 bl= size(bdy,2);
0211
0212
0213 bdy_order =node_order(bdy);
0214 bdy_up= find(bdy_order>[1;1]*min(bdy_order));
0215 bdy_dn= find(bdy_order<[1;1]*max(bdy_order));
0216
0217 bdy_odd = [bdy; bdy(bdy_up')];
0218 bdy_even= [bdy; bdy(bdy_dn')];
0219 BDY = [];
0220
0221 ln= length(niveaux);
0222 for k=2:ln
0223 NODE=[NODE [node0; niveaux(k)*ones(1,n)] ];
0224 if rem(k,2)==1
0225 elem= elem_odd;
0226 bdy_e0= bdy_even;
0227 bdy_e1= bdy_odd;
0228 else
0229 elem= elem_even;
0230 bdy_e1= bdy_even;
0231 bdy_e0= bdy_odd;
0232 end
0233 el_add = (k-2)*n+[[zeros(3,e);n*ones(1,e)], ...
0234 [zeros(2,e);n*ones(2,e)], ...
0235 [zeros(1,e);n*ones(3,e)]];
0236 ELEM= [ELEM,elem + el_add];
0237 BDY= [BDY, bdy_e0+(k-2)*n+[zeros(2,bl);n*ones(1,bl)], ...
0238 bdy_e1+(k-2)*n+[n*ones(2,bl);zeros(1,bl)] ];
0239 end
0240
0241
0242 BDY= [elem0, BDY, elem0+n*(ln-1) ];
0243
0244
0245 elec_nodes= ones(ln,1) * elec_nodes0 + ...
0246 (0:ln-1)' * n*ones(1, length(elec_nodes0) );
0247
0248
0249
0250
0251
0252
0253 function elec_struct = mk_electrodes( elec_nodes)
0254 for i= 1:length( elec_nodes )
0255 elec_struct(i).nodes = elec_nodes(i);
0256 elec_struct(i).z_contact = 0.001;
0257 end
0258
0259 if ~exist('elec_struct');
0260 elec_struct= [];
0261 end
0262
0263 function elem= node_reorder( elem0, node_order);
0264 e= size(elem0,2);
0265
0266 no_test= node_order(elem0);
0267 no_test= (0:e-1)'*[3,3,3]+no_test';
0268 elem= elem0(no_test');
0269
0270 no_test = node_order(elem);
0271 ok= ~norm(no_test - [1;2;3]*ones(1,e));
0272
0273 if ~ok; error('test_node_order fails - cant do 3D meshes'); end
0274
0275 function do_unit_test
0276 subplot(3,3,1)
0277 mdl= mk_circ_tank(2, [], 2 );
0278 show_fem(mdl, [0,1,1]);
0279 unit_test_cmp('2D mdl', length(mdl.elems), 16);
0280
0281 subplot(3,3,2)
0282 mdl= mk_circ_tank(4, [], 16 );
0283 show_fem(mdl);
0284 unit_test_cmp('2D mdl', length(mdl.nodes), 41);
0285
0286 subplot(3,3,3)
0287 mdl= mk_circ_tank(4, linspace(-1,1,3), {'planes', 8, 2} );
0288 show_fem(mdl);
0289 unit_test_cmp('2D mdl', length(mdl.elems), 384);
0290
0291 subplot(3,3,4)
0292 mdl= mk_circ_tank(4, linspace(-1,1,5), {'zigzag', 4, [2,4]} );
0293 show_fem(mdl);
0294 unit_test_cmp('2D mdl', length(mdl.elems), 768);
0295
0296 try
0297 mdl= mk_circ_tank(2, [], 18 ); error
0298 unit_test_cmp('test for error', 1,0);
0299 catch
0300 unit_test_cmp('test for error', 1,1);
0301 end
0302
0303 subplot(3,3,5)
0304 mdl= mk_circ_tank(4, [], 0);
0305 show_fem(mdl);
0306 title 'no electodes'
0307
0308 subplot(3,3,6)
0309 mdl= mk_circ_tank(4, linspace(-1,1,5), 0);
0310 show_fem(mdl);
0311 title 'no electodes'