0001 function mdl2 = mdl2d_from3d(mdl3);
0002
0003
0004
0005
0006
0007 mdl2 = eidors_obj('fwd_model',sprintf('%s 2D',mdl3.name));
0008
0009
0010 [bdy,idx] = find_boundary(mdl3.elems);
0011 vtx = mdl3.nodes;
0012 z_vtx = reshape(vtx(bdy,3), size(bdy) );
0013 lay0 = find( all(z_vtx==0,2) );
0014 bdy0 = bdy( lay0, :);
0015
0016 vtx0 = unique(bdy0(:));
0017 mdl2.nodes = vtx(vtx0,1:2);
0018 if isempty(mdl2.nodes)
0019 error('mdl2d_from3d: Something went wrong; mdl2 has no nodes');
0020 end
0021
0022
0023 nmap = zeros(size(vtx,1),1); nmap(vtx0) = 1:length(vtx0);
0024 bdy0 = reshape(nmap(bdy0), size(bdy0) );
0025 mdl2.elems = bdy0;
0026
0027
0028 mdl2.boundary = find_boundary( mdl2.elems);
0029
0030
0031 mdl2.gnd_node = nmap(mdl3.gnd_node);
0032 if mdl2.gnd_node == 0
0033 ctr = mean(mdl2.nodes);
0034 d = bsxfun(@minus, mdl2.nodes, ctr).^2;
0035 [jnk, mdl2.gnd_node] = min(d);
0036 mdl2.gnd_node = mdl2.gnd_node(1);
0037 end
0038
0039
0040
0041
0042
0043
0044 if isfield(mdl3,'mat_idx');
0045 mdl2.mat_idx = {};
0046 idx0 = idx( lay0, :);
0047 for i=1:size(mdl3.mat_idx,2)
0048 mdl2.mat_idx{i} = [];
0049 ii = 1;
0050 for j=1:size(mdl3.mat_idx{i},1)
0051 idx_tmp = find( idx0==mdl3.mat_idx{i}(j) );
0052 if not(isempty(idx_tmp))
0053 mdl2.mat_idx{i}(ii,1) = idx_tmp(1,1);
0054 ii = ii + 1;
0055 end
0056 end
0057 end
0058 end
0059
0060
0061 if isfield(mdl3,'mat_idx_reordered');
0062 mdl2.mat_idx_reordered = {};
0063 idx0 = idx( lay0, :);
0064 for i=1:size(mdl3.mat_idx_reordered,2)
0065 mdl2.mat_idx_reordered{i} = [];
0066 ii = 1;
0067 for j=1:size(mdl3.mat_idx_reordered{i},1)
0068 idx_tmp = find( idx0==mdl3.mat_idx_reordered{i}(j) );
0069 if not(isempty(idx_tmp))
0070 mdl2.mat_idx_reordered{i}(ii,1) = idx_tmp(1,1);
0071 ii = ii + 1;
0072 end
0073 end
0074 end
0075 end
0076
0077
0078 if isfield(mdl3,'electrode')
0079 mdl2.electrode = mdl3.electrode;
0080 for i=1:length(mdl2.electrode);
0081 enodes = nmap( mdl2.electrode(i).nodes );
0082 enodes(enodes==0) = [];
0083 mdl2.electrode(i).nodes = enodes(:)';
0084 end
0085 end
0086
0087
0088 if isfield(mdl3,'stimulation'); mdl2.stimulation= mdl3.stimulation; end
0089 try
0090 mdl2.solve = mdl3.solve;
0091 catch
0092 mdl2.solve = 'eidors_default';end
0093 try
0094 mdl2.jacobian = mdl3.jacobian;
0095 catch
0096 mdl2.jacobian = 'eidors_default';end
0097 try
0098 mdl2.system_mat = mdl3.system_mat;
0099 catch
0100 mdl2.system_mat = 'eidors_default'; end;
0101 try
0102 mdl2.normalize_measurements = mdl3.normalize_measurements;
0103 catch
0104 mdl2.normalize_measurements = 0; end;
0105
0106
0107 mdl2 = eidors_obj('fwd_model',mdl2);
0108