modelzoom

PURPOSE ^

MODELZOOM - exctract a smaller model out of a large one.

SYNOPSIS ^

function md2=modelzoom(md,areaname)

DESCRIPTION ^

MODELZOOM - exctract a smaller model out of a large one. 

   It is used to be able to plot large models, one area at a time. 
   Be careful: usage is: md2=modelzoom(md,areaname) where md2 is the returned 
   model, md the large input model, and areaname the name of the area wherefrom 
   the smaller model should be extracted. 
   Because this is intended for mainly plotting purposes, the private member segments will 
   not be extracted. Ie: this model cannot be used for solving.

   Usage:
      md2=modelzoom(md,areaname)

   Example:
      md2=modelzoom(md,'pineislandglacier');

   See also: MODELEXTRACT

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function md2=modelzoom(md,areaname)
0002 %MODELZOOM - exctract a smaller model out of a large one.
0003 %
0004 %   It is used to be able to plot large models, one area at a time.
0005 %   Be careful: usage is: md2=modelzoom(md,areaname) where md2 is the returned
0006 %   model, md the large input model, and areaname the name of the area wherefrom
0007 %   the smaller model should be extracted.
0008 %   Because this is intended for mainly plotting purposes, the private member segments will
0009 %   not be extracted. Ie: this model cannot be used for solving.
0010 %
0011 %   Usage:
0012 %      md2=modelzoom(md,areaname)
0013 %
0014 %   Example:
0015 %      md2=modelzoom(md,'pineislandglacier');
0016 %
0017 %   See also: MODELEXTRACT
0018 
0019 %some checks on list of arguments
0020 if ((nargin~=2) | (nargout~=1)),
0021     modelzoomusage();
0022     error('modelzoom error message');
0023 end
0024 
0025 [xlim0 ylim0]=antmodelzoom(areaname);
0026 
0027 %Create a list of elements locations from the input model
0028 xel=(md.x(md.elements(:,1))+md.x(md.elements(:,2))+md.x(md.elements(:,3)))/3;
0029 yel=(md.y(md.elements(:,1))+md.y(md.elements(:,2))+md.y(md.elements(:,3)))/3;
0030 
0031 %Figure out which elements are within the area:
0032 elementlist=find( (xel>xlim0(1)) & (xel<xlim0(2)) & (yel>ylim0(1)) & (yel<ylim0(2)) );
0033 
0034 %Create a list of elements locations from the input model, which are on the segmentonneumann_diag:
0035 if(~isempty(md.segmentonneumann_diag)),
0036     xelneumann=(md.x(md.elements(md.segmentonneumann_diag(:,3),1))+md.x(md.elements(md.segmentonneumann_diag(:,3),2))+md.x(md.elements(md.segmentonneumann_diag(:,3),3)))/3;
0037     yelneumann=(md.y(md.elements(md.segmentonneumann_diag(:,3),1))+md.y(md.elements(md.segmentonneumann_diag(:,3),2))+md.y(md.elements(md.segmentonneumann_diag(:,3),3)))/3;
0038     %Figure out which elements are within the area, and on segmentonneumann_diag:
0039     elementlistneumann=find( (xelneumann>xlim0(1)) & (xelneumann<xlim0(2)) & (yelneumann>ylim0(1)) & (yelneumann<ylim0(2)) );
0040 end
0041 
0042 
0043 %Figure out the corresponding grids in the area:
0044 flags=zeros(md.numberofgrids,1);
0045 flags(md.elements(elementlist,1))=1;
0046 flags(md.elements(elementlist,2))=1;
0047 flags(md.elements(elementlist,3))=1;
0048 gridlist=find(flags);
0049 
0050 %Reverse indexing
0051 gridpos=zeros(md.numberofgrids,1);
0052 gridpos(gridlist)=1:1:length(gridlist);
0053 elempos=zeros(md.numberofelements,1);
0054 elempos(elementlist)=1:1:length(elementlist);
0055 
0056 %Create output model:
0057 md2=model;
0058 md2.numberofgrids=length(gridlist);
0059 md2.numberofelements=length(elementlist);
0060 
0061 structfields=fields(md);
0062 for i=1:length(structfields),
0063     field=structfields(i);field=field{1};
0064     fieldval=getfield(md,field);
0065 
0066     if isnumeric(fieldval),
0067         if isempty(fieldval),
0068             md2=setfield(md2,field,fieldval);
0069         end
0070         if length(fieldval)==md.numberofgrids,
0071             fieldval=fieldval(gridlist);
0072             md2=setfield(md2,field,fieldval);
0073         end
0074         if length(fieldval)==md.numberofelements,
0075             if strcmp(field,'elements'),
0076                 fieldval=fieldval(elementlist,:);
0077                 md2=setfield(md2,field,fieldval);
0078                 %Now, we need to reset the element grid ids to the
0079                 %new mesh grid ids.
0080                 md2.elements(:)=gridpos(md2.elements(:));
0081             else
0082                 fieldval=fieldval(elementlist,:);
0083                 md2=setfield(md2,field,fieldval);
0084             end
0085         end
0086         if isscalar(fieldval),
0087             if (~(strcmp(field,'numberofelements') | strcmp(field,'numberofgrids')))
0088                 md2=setfield(md2,field,fieldval);
0089             end
0090         end
0091     end
0092     if ischar(fieldval),
0093         md2=setfield(md2,field,fieldval);
0094     end
0095 end
0096 
0097 %Deal with segmentonneumann_diag:
0098 if(~isempty(md.segmentonneumann_diag)),
0099     md2.segmentonneumann_diag=md.segmentonneumann_diag(elementlistneumann,:);
0100     md2.segmentonneumann_diag(:,1)=gridpos(md2.segmentonneumann_diag(:,1));
0101     md2.segmentonneumann_diag(:,2)=gridpos(md2.segmentonneumann_diag(:,2));
0102     md2.segmentonneumann_diag(:,3)=elempos(md2.segmentonneumann_diag(:,3));
0103 end
0104 
0105 %Add a note:
0106 md2=addnote(md2,['This model is a modelzoom on area: ' areaname]);
0107 end %end of function
0108 
0109 
0110 function modelzoomusage(),
0111 disp('md2=modelzoom(md,areaname');
0112 end %end of function
0113

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003