Home > eidors > meshing > netgen > mdl2d_from3d.m

mdl2d_from3d

PURPOSE ^

mdl2d_from3d: Create 2D mdl from z=0 plane of 3d model

SYNOPSIS ^

function mdl2 = mdl2d_from3d(mdl3);

DESCRIPTION ^

 mdl2d_from3d: Create 2D mdl from z=0 plane of 3d model

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mdl2 = mdl2d_from3d(mdl3);
0002 % mdl2d_from3d: Create 2D mdl from z=0 plane of 3d model
0003 
0004 % (C) Andy Adler, Alistair Boyle 2013. Licenced under GPL v2 or v3
0005 % $Id: mdl2d_from3d.m 5356 2017-03-11 15:02:39Z aadler $
0006    % set name
0007    mdl2 = eidors_obj('fwd_model',sprintf('%s 2D',mdl3.name));
0008 
0009    % set nodes
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    % set elems
0023    nmap  = zeros(size(vtx,1),1); nmap(vtx0) = 1:length(vtx0);
0024    bdy0  = reshape(nmap(bdy0), size(bdy0) ); % renumber to new scheme
0025    mdl2.elems = bdy0;
0026 
0027    % set boundary
0028    mdl2.boundary = find_boundary( mdl2.elems);
0029 
0030    % set gnd_node
0031    mdl2.gnd_node = nmap(mdl3.gnd_node);
0032    if mdl2.gnd_node == 0 % we've just killed it
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    % set material indices
0040    % NOTE this must be done for both mat_idx and
0041    % mat_idx_reordered (which is DEPRECIATED but
0042    % still required for backwards compatibilty)
0043    % TODO: vectorize code
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 %isfield
0059 
0060    % TODO: vectorize code
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 %isfield
0076    
0077    % set electrode
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) = []; % Remove 3D layers
0083         mdl2.electrode(i).nodes = enodes(:)';
0084      end
0085    end
0086 
0087    % copy other fields
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    % update cache
0107    mdl2 = eidors_obj('fwd_model',mdl2);
0108

Generated on Fri 01-Jun-2018 15:59:55 by m2html © 2005