collapse

PURPOSE ^

COLLAPSE - collapses a 3d mesh into a 2d mesh

SYNOPSIS ^

function md=collapse(md)

DESCRIPTION ^

COLLAPSE - collapses a 3d mesh into a 2d mesh

   This routine collapses a 3d model into a 2d model
   and collapses all the fileds of the 3d model by
   taking their depth-averaged values

   Usage:
      md=collapse(md)

   See also: EXTRUDE, MODELEXTRACT

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function md=collapse(md)
0002 %COLLAPSE - collapses a 3d mesh into a 2d mesh
0003 %
0004 %   This routine collapses a 3d model into a 2d model
0005 %   and collapses all the fileds of the 3d model by
0006 %   taking their depth-averaged values
0007 %
0008 %   Usage:
0009 %      md=collapse(md)
0010 %
0011 %   See also: EXTRUDE, MODELEXTRACT
0012 
0013 %Check that the model is really a 3d model
0014 if ~strcmpi(md.type,'3d'),
0015     error('collapse error message: only 3d mesh can be collapsed')
0016 end
0017 
0018 %Start with changing alle the fields from the 3d mesh
0019 
0020 %drag is limited to grids that are on the bedrock.
0021 md.drag=project2d(md,md.drag,1);
0022 
0023 %p and q (same deal, except for element that are on the bedrock: )
0024 md.p=project2d(md,md.p,1);
0025 md.q=project2d(md,md.q,1);
0026 
0027 %observations
0028 md.vx_obs=project2d(md,md.vx_obs,md.numlayers);
0029 md.vy_obs=project2d(md,md.vy_obs,md.numlayers);
0030 md.vel_obs=project2d(md,md.vel_obs,md.numlayers);
0031 md.accumulation=project2d(md,md.accumulation,md.numlayers);
0032 md.firn_layer=project2d(md,md.firn_layer,md.numlayers);
0033 
0034 %results
0035 if ~isnan(md.vx),md.vx=DepthAverage(md,md.vx);end;
0036 if ~isnan(md.vy),md.vy=DepthAverage(md,md.vy);end;
0037 if ~isnan(md.vz),md.vz=DepthAverage(md,md.vz);end;
0038 if ~isnan(md.vel),md.vel=DepthAverage(md,md.vel);end;
0039 if ~isnan(md.surface_slopex),md.surface_slopex=project2d(md,md.surface_slopex,md.numlayers);end;
0040 if ~isnan(md.surface_slopey),md.surface_slopey=project2d(md,md.surface_slopey,md.numlayers);end;
0041 if ~isnan(md.bed_slopex),md.bed_slopex=project2d(md,md.bed_slopex,1);end;
0042 if ~isnan(md.bed_slopey),md.bed_slopey=project2d(md,md.bed_slopey,1);end;
0043 
0044 %bedinfo and surface info
0045 md.elementonbed=ones(md.numberofelements2d,1);
0046 md.elementonsurface=ones(md.numberofelements2d,1);
0047 md.gridonbed=ones(md.numberofgrids2d,1);
0048 md.gridonsurface=ones(md.numberofgrids2d,1);
0049 
0050 %elementstype
0051 if ~isnan(md.elements_type2d)
0052     md.elements_type=md.elements_type2d; 
0053 else
0054     md.elements_type2d(:,1)=project2d(md,md.elements_type(:,1),1);
0055     md.elements_type2d(:,2)=project2d(md,md.elements_type(:,2),1);
0056 end    
0057 md.gridonhutter=project2d(md,md.gridonhutter,1);
0058 md.gridonmacayeal=project2d(md,md.gridonmacayeal,1);
0059 md.gridonpattyn=project2d(md,md.gridonpattyn,1);
0060 md.gridonstokes=project2d(md,md.gridonstokes,1);
0061 
0062 %boundary conditions
0063 md.gridondirichlet_diag=project2d(md,md.gridondirichlet_diag,md.numlayers);
0064 dirichletvalues_diag2d(:,1)=project2d(md,md.dirichletvalues_diag(:,1),md.numlayers); 
0065 dirichletvalues_diag2d(:,2)=project2d(md,md.dirichletvalues_diag(:,2),md.numlayers); 
0066 md.dirichletvalues_diag=dirichletvalues_diag2d;
0067 
0068 %Extrusion of Neumann BC
0069 %in 2d, segmentonnumann is: [grid1 grid2 element]
0070 numberofneumann2d=size(md.segmentonneumann_diag,1)/md.numlayers;
0071 md.segmentonneumann_diag=[md.segmentonneumann_diag(1:numberofneumann2d,1:2) md.segmentonneumann_diag(1:numberofneumann2d,5)]; %Add two columns on the first layer
0072 
0073 %Prognostic
0074 md.gridondirichlet_prog=project2d(md,md.gridondirichlet_prog,md.numlayers);
0075 md.dirichletvalues_prog=project2d(md,md.dirichletvalues_prog,md.numlayers);
0076 %md.segmentonneumann_prog=[tproj(md.segmentonneumann_prog(:,1)) tproj(md.segmentonneumann_prog(:,2)) tproj2d_el(md.segmentonneumann_prog(:,5))];
0077 %md.segmentonneumann_prog2=[tproj(md.segmentonneumann_prog2(:,1)) tproj(md.segmentonneumann_prog2(:,2)) tproj2d_el(md.segmentonneumann_prog2(:,5))];
0078 
0079 %materials
0080 md.B=DepthAverage(md,md.B);
0081 md.n=project2d(md,md.n,1);
0082 
0083 %special for thermal modeling:
0084 md.melting=project2d(md,md.melting,1); 
0085 md.observed_temperature=DepthAverage(md,md.observed_temperature); 
0086 md.geothermalflux=project2d(md,md.geothermalflux,1); %bedrock only gets geothermal flux
0087 md.gridondirichlet_thermal=project2d(md,md.gridondirichlet_thermal,md.numlayers); %surface temperature
0088 md.dirichletvalues_thermal=project2d(md,md.dirichletvalues_thermal,md.numlayers); %surface temperature
0089 
0090 %NaN the values that are not on an spc'd temperature.
0091 pos=find(~md.gridondirichlet_thermal);
0092 md.dirichletvalues_thermal(pos)=NaN;
0093 
0094 %update of connectivity matrix
0095 md.connectivity=25;
0096 
0097 %Collapse the mesh
0098 grids2d=md.numberofgrids2d;
0099 elements2d=md.numberofelements2d;
0100 
0101 %parameters
0102 md.surface=project2d(md,md.surface,1);
0103 md.thickness=project2d(md,md.thickness,1);
0104 md.bed=project2d(md,md.bed,1);
0105 md.gridonboundary=project2d(md,md.gridonboundary,1);
0106 md.elementoniceshelf=project2d(md,md.elementoniceshelf,1);
0107 md.gridoniceshelf=project2d(md,md.gridoniceshelf,1);
0108 md.elementonicesheet=project2d(md,md.elementonicesheet,1);
0109 md.gridonicesheet=project2d(md,md.gridonicesheet,1);
0110 
0111 %Initialize with the 2d mesh
0112 md.x=md.x2d;
0113 md.y=md.y2d;
0114 md.z=md.z2d;
0115 md.numberofgrids=md.numberofgrids2d;
0116 md.numberofelements=md.numberofelements2d;
0117 md.elements=md.elements2d;
0118 
0119 %Keep a trace of lower and upper grids
0120 md.lowergrids=NaN;
0121 md.uppergrids=NaN;
0122 
0123 %Remove old mesh
0124 md.x2d=NaN;
0125 md.y2d=NaN;
0126 md.z2d=NaN;
0127 md.elements2d=NaN;
0128 md.elements_type2d=md.elements_type;
0129 md.numberofelements2d=md.numberofelements;
0130 md.numberofgrids2d=md.numberofgrids;
0131 md.numlayers=0;
0132 
0133 %Update mesh type
0134 md.type='2d';
0135 
0136 %Tie in with Cielo if requested
0137 cieloend;
0138 end

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