crop_model

PURPOSE ^

CROP_MODEL: Crop away parts of a fem model

SYNOPSIS ^

function [fmdl,c2f_idx]= crop_model( axis_handle, fcn_handle );

DESCRIPTION ^

 CROP_MODEL: Crop away parts of a fem model

 USAGE #1: crop display to show model internals
   crop_model( axis_handle, fcn_handle );

   fcn_handle ==1 where model is *kept*
 
   if axis_handle==[], then use the current axis
   examples:
     crop_model([],  inline('z==3','x','y','z'))
     crop_model(gca, inline('x+y>0','x','y','z'))

 USAGE #2: crop fwd_model to create new fwd_model
   fmdl_new= crop_model( fwd_model, fcn_handle );
 
   example:
   fmdl2= crop_model(fmdl1, inline('x+y>0','x','y','z'))

  with two parameters output
 [fmdl,c2f_idx]= crop_model( axis_handle, fcn_handle );
     c2f_idx maps each elemen in fmdl_new to fwd_model

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [fmdl,c2f_idx]= crop_model( axis_handle, fcn_handle );
0002 % CROP_MODEL: Crop away parts of a fem model
0003 %
0004 % USAGE #1: crop display to show model internals
0005 %   crop_model( axis_handle, fcn_handle );
0006 %
0007 %   fcn_handle ==1 where model is *kept*
0008 %
0009 %   if axis_handle==[], then use the current axis
0010 %   examples:
0011 %     crop_model([],  inline('z==3','x','y','z'))
0012 %     crop_model(gca, inline('x+y>0','x','y','z'))
0013 %
0014 % USAGE #2: crop fwd_model to create new fwd_model
0015 %   fmdl_new= crop_model( fwd_model, fcn_handle );
0016 %
0017 %   example:
0018 %   fmdl2= crop_model(fmdl1, inline('x+y>0','x','y','z'))
0019 %
0020 %  with two parameters output
0021 % [fmdl,c2f_idx]= crop_model( axis_handle, fcn_handle );
0022 %     c2f_idx maps each elemen in fmdl_new to fwd_model
0023 
0024 % (C) 2006-2008 Andy Adler. License: GPL version 2 or version 3
0025 % $Id: crop_model.html 2819 2011-09-07 16:43:11Z aadler $
0026 
0027 usage_graphics= 1;
0028 try if axis_handle.type == 'fwd_model'
0029    usage_graphics= 0;
0030 end; end
0031 
0032 if usage_graphics
0033    if isempty(axis_handle)
0034       axis_handle= gca;
0035    end
0036    crop_graphics_model(axis_handle, fcn_handle);
0037 else
0038    [fmdl,c2f_idx]= crop_fwd_model(axis_handle, fcn_handle);
0039 end
0040 
0041 % CROP GRAPHICS
0042 function crop_graphics_model(axis_handle, fcn_handle);
0043    kk= get(axis_handle,'Children');
0044    % only the FEM frame
0045    %k=kk( find( kk== min(kk) ));
0046 
0047    for k= kk(:)'
0048       try
0049          x= get(k,'XData');
0050          y= get(k,'YData');
0051          z= get(k,'ZData');
0052          c= get(k,'CData');
0053          idx= ~all( feval(fcn_handle,x,y,z) );
0054          if any(size(c)>[1,1])
0055             set(k,'Xdata', x(:,idx), ...
0056                   'Ydata', y(:,idx), ...
0057                   'Zdata', z(:,idx), ...
0058                   'Cdata', c(:,idx));
0059          else
0060             set(k,'Xdata', x(:,idx), ...
0061                   'Ydata', y(:,idx), ...
0062                   'Zdata', z(:,idx));
0063          end
0064       end
0065    end
0066 
0067 % CROP fwd_model
0068 function [fmdl1,c2f_idx]= crop_fwd_model(fmdl0, fcn_handle);
0069    fmdl1= fmdl0;
0070 
0071 % Find nodes to remove
0072    nodes= fmdl0.nodes;
0073    [n,d]= size(nodes);
0074    n2xyz= eye(d,3); 
0075    xyz= nodes*n2xyz;
0076    idx0= ~all( feval(fcn_handle,xyz(:,1), ...
0077                                 xyz(:,2), ...
0078                                 xyz(:,3)),2);
0079 % remove these nodes
0080    fmdl1.nodes(idx0,:) = [];
0081 
0082 % renumber nodes, set unused ones to 0
0083    idx1= zeros(n,1);
0084    idx1(~idx0)= 1:sum(~idx0);
0085 
0086    fmdl1.elems(:) = idx1(fmdl0.elems);
0087    remove= any( fmdl1.elems == 0, 2);
0088    fmdl1.elems(remove,:)= [];
0089 % c2f_idx maps each new elem to its original position
0090    c2f_idx= find(~remove);
0091 
0092    fmdl1.boundary(:) = idx1(fmdl0.boundary);
0093    remove= any( fmdl1.boundary == 0, 2);
0094    fmdl1.boundary(remove,:)= [];
0095 
0096 % renumber nodes, set unused ones to 0
0097 if isfield(fmdl1,'electrode');
0098    for i=1:length(fmdl1.electrode)
0099       el_nodes= fmdl0.electrode(i).nodes;
0100       el_nodes(:)= idx1(el_nodes);
0101       if any(el_nodes==0);
0102          error('crop_model: nodes in electrode are removed');
0103       end
0104       fmdl1.electrode(i).nodes= el_nodes;
0105    end
0106 end
0107

Generated on Tue 09-Aug-2011 11:38:31 by m2html © 2005