| 1 | function md=extrude(md,numlayers,extrusionexponent)
|
|---|
| 2 | %EXTRUDE - vertically extrude a 2d mesh
|
|---|
| 3 | %
|
|---|
| 4 | % vertically extrude a 2d mesh and create corresponding 3d mesh following the extrusionexponent,
|
|---|
| 5 | % the vertical distribution follows a polynomial law:');
|
|---|
| 6 | % extrusionexponent>1 refinement at the base');
|
|---|
| 7 | % 0<extrusionexponent<1 refinement at the surface');
|
|---|
| 8 | % extrusionexponent=1 linear extrusion');
|
|---|
| 9 | %
|
|---|
| 10 | % Usage:
|
|---|
| 11 | % md=extrude(md,numlayers,extrusionexponent);
|
|---|
| 12 | %
|
|---|
| 13 | % Example:
|
|---|
| 14 | % md=extrude(md,8,3);
|
|---|
| 15 | %
|
|---|
| 16 | % See also: MODELEXTRACT, COLLAPSE
|
|---|
| 17 |
|
|---|
| 18 | %some checks on list of arguments
|
|---|
| 19 | if ((nargin~=3) | (nargout~=1)),
|
|---|
| 20 | extrudeusage();
|
|---|
| 21 | error('extrude error message');
|
|---|
| 22 | end
|
|---|
| 23 |
|
|---|
| 24 | if md.counter<3,
|
|---|
| 25 | extrudeusage();
|
|---|
| 26 | error('only fully parameterized 2d models can be extruded');
|
|---|
| 27 | end
|
|---|
| 28 |
|
|---|
| 29 | if md.counter>=4,
|
|---|
| 30 | error('This model has already been extruded!','s');
|
|---|
| 31 | end
|
|---|
| 32 |
|
|---|
| 33 | if numlayers<2,
|
|---|
| 34 | extrudeusage();
|
|---|
| 35 | error('number of layers should be at least 2');
|
|---|
| 36 | end
|
|---|
| 37 |
|
|---|
| 38 | if extrusionexponent<0,
|
|---|
| 39 | extrudeusage();
|
|---|
| 40 | error('extrusionexponent must be >0');
|
|---|
| 41 | end
|
|---|
| 42 |
|
|---|
| 43 | %Extrude the mesh
|
|---|
| 44 | %Initialize with the 2d mesh
|
|---|
| 45 | x3d=md.x;
|
|---|
| 46 | y3d=md.y;
|
|---|
| 47 | z3d=md.bed; %the lower grid is on the bed
|
|---|
| 48 | thickness3d=md.thickness; %thickness and bed for these grids
|
|---|
| 49 | bed3d=md.bed;
|
|---|
| 50 | %Create the new layers
|
|---|
| 51 | for i=2:numlayers,
|
|---|
| 52 | x3d=[x3d; md.x]; %build the grids of the other layers
|
|---|
| 53 | y3d=[y3d; md.y];
|
|---|
| 54 | z3d=[z3d; bed3d+thickness3d*(i/numlayers)^extrusionexponent]; %grids are distributed between bed and surface accordingly to the given exponent
|
|---|
| 55 | end
|
|---|
| 56 | number_grids3d=size(x3d,1); %number of 3d grids for the non extruded part of the mesh
|
|---|
| 57 |
|
|---|
| 58 | %Extrude elements
|
|---|
| 59 | elements3d=[];
|
|---|
| 60 | for i=1:numlayers-1,
|
|---|
| 61 | elements3d=[elements3d;[md.elements+(i-1)*md.numberofgrids md.elements+i*md.numberofgrids]]; %Create the elements of the 3d mesh for the non extruded part
|
|---|
| 62 | end
|
|---|
| 63 | number_el3d=size(elements3d,1); %number of 3d grids for the non extruded part of the mesh
|
|---|
| 64 |
|
|---|
| 65 | %Keep a trace of lower and upper grids
|
|---|
| 66 | lowergrids=NaN*ones(number_grids3d,1);
|
|---|
| 67 | uppergrids=NaN*ones(number_grids3d,1);
|
|---|
| 68 | lowergrids(md.numberofgrids+1:end)=1:(numlayers-1)*md.numberofgrids;
|
|---|
| 69 | uppergrids(1:(numlayers-1)*md.numberofgrids)=md.numberofgrids+1:number_grids3d;
|
|---|
| 70 | md.lowergrids=lowergrids;
|
|---|
| 71 | md.uppergrids=uppergrids;
|
|---|
| 72 |
|
|---|
| 73 | %Save old mesh
|
|---|
| 74 | md.x2d=md.x;
|
|---|
| 75 | md.y2d=md.y;
|
|---|
| 76 | md.z2d=md.z;
|
|---|
| 77 | md.elements2d=md.elements;
|
|---|
| 78 | md.elements_type2d=md.elements_type;
|
|---|
| 79 | md.numberofelements2d=md.numberofelements;
|
|---|
| 80 | md.numberofgrids2d=md.numberofgrids;
|
|---|
| 81 |
|
|---|
| 82 | %Update mesh type
|
|---|
| 83 | md.type='3d';
|
|---|
| 84 |
|
|---|
| 85 | %Build global 3d mesh
|
|---|
| 86 | md.elements=elements3d;
|
|---|
| 87 | md.x=x3d;
|
|---|
| 88 | md.y=y3d;
|
|---|
| 89 | md.z=z3d;
|
|---|
| 90 | md.numberofelements=number_el3d;
|
|---|
| 91 | md.numberofgrids=number_grids3d;
|
|---|
| 92 | md.numlayers=numlayers;
|
|---|
| 93 |
|
|---|
| 94 | %Ok, now deal with the other fields from the 2d mesh:
|
|---|
| 95 |
|
|---|
| 96 | %drag is limited to grids that are on the bedrock.
|
|---|
| 97 | md.drag=project3d(md,md.drag,'node',1);
|
|---|
| 98 |
|
|---|
| 99 | %p and q (same deal, except for element that are on the bedrock: )
|
|---|
| 100 | md.p=project3d(md,md.p,'element');
|
|---|
| 101 | md.q=project3d(md,md.q,'element');
|
|---|
| 102 |
|
|---|
| 103 | %observations
|
|---|
| 104 | md.vx_obs=project3d(md,md.vx_obs,'node',md.numlayers);
|
|---|
| 105 | md.vy_obs=project3d(md,md.vy_obs,'node',md.numlayers);
|
|---|
| 106 | md.vel_obs=project3d(md,md.vel_obs,'node',md.numlayers);
|
|---|
| 107 | md.accumulation=project3d(md,md.accumulation,'node',md.numlayers);
|
|---|
| 108 | md.firn_layer=project3d(md,md.firn_layer,'node',md.numlayers);
|
|---|
| 109 |
|
|---|
| 110 | %results
|
|---|
| 111 | if ~isnan(md.vx),md.vx=project3d(md,md.vx,'node');end;
|
|---|
| 112 | if ~isnan(md.vy),md.vy=project3d(md,md.vy,'node');end;
|
|---|
| 113 | if ~isnan(md.vz),md.vz=project3d(md,md.vz,'node');end;
|
|---|
| 114 | if ~isnan(md.vel),md.vel=project3d(md,md.vel,'node');end;
|
|---|
| 115 | if ~isnan(md.surface_slopex),md.surface_slopex=project3d(md,md.surface_slopex,'node');end;
|
|---|
| 116 | if ~isnan(md.surface_slopey),md.surface_slopey=project3d(md,md.surface_slopey,'node');end;
|
|---|
| 117 | if ~isnan(md.bed_slopex),md.bed_slopex=project3d(md,md.bed_slopex,'node');end;
|
|---|
| 118 | if ~isnan(md.bed_slopey),md.bed_slopey=project3d(md,md.bed_slopey,'node');end;
|
|---|
| 119 |
|
|---|
| 120 | %bedinfo and surface info
|
|---|
| 121 | md.elementonbed=project3d(md,ones(md.numberofelements2d,1),'element',1);
|
|---|
| 122 | md.elementonsurface=project3d(md,ones(md.numberofelements2d,1),'element',md.numlayers-1);
|
|---|
| 123 | md.gridonbed=project3d(md,ones(md.numberofgrids2d,1),'node',1);
|
|---|
| 124 | md.gridonsurface=project3d(md,ones(md.numberofgrids2d,1),'node',md.numlayers);
|
|---|
| 125 |
|
|---|
| 126 | %elementstype
|
|---|
| 127 | if ~isnan(md.elements_type)
|
|---|
| 128 | oldelements_type=md.elements_type2d;
|
|---|
| 129 | md.elements_type=zeros(number_el3d,2);
|
|---|
| 130 | md.elements_type(:,1)=project3d(md,oldelements_type(:,1),'element');
|
|---|
| 131 | md.elements_type(:,2)=project3d(md,oldelements_type(:,2),'element');
|
|---|
| 132 | md.gridonhutter=project3d(md,md.gridonhutter,'node');
|
|---|
| 133 | md.gridonmacayeal=project3d(md,md.gridonmacayeal,'node');
|
|---|
| 134 | md.gridonpattyn=project3d(md,md.gridonpattyn,'node');
|
|---|
| 135 | md.gridonstokes=project3d(md,md.gridonstokes,'node');
|
|---|
| 136 | end
|
|---|
| 137 |
|
|---|
| 138 | %boundary conditions
|
|---|
| 139 | md.gridondirichlet_diag=project3d(md,md.gridondirichlet_diag,'node');
|
|---|
| 140 | md.dirichletvalues_diag=project3d(md,md.dirichletvalues_diag,'node');
|
|---|
| 141 |
|
|---|
| 142 | %Extrusion of Neumann BC
|
|---|
| 143 | %in 3d, segmentonnumann is: [grid1 grid2 grid3 grid4 element]
|
|---|
| 144 | oldsegmentonneumann_diag=md.segmentonneumann_diag;
|
|---|
| 145 | segmentonneumann_diag_layer1=[oldsegmentonneumann_diag(:,1:2) oldsegmentonneumann_diag(:,2)+md.numberofgrids2d oldsegmentonneumann_diag(:,1)+md.numberofgrids2d oldsegmentonneumann_diag(:,3)]; %Add two columns on the first layer
|
|---|
| 146 | segmentonneumann_diag=[];
|
|---|
| 147 | for i=1:numlayers-1,
|
|---|
| 148 | segmentonneumann_diag=[segmentonneumann_diag ;segmentonneumann_diag_layer1(:,1:4)+(i-1)*md.numberofgrids2d segmentonneumann_diag_layer1(:,5)+(i-1)*md.numberofelements2d ];
|
|---|
| 149 | end
|
|---|
| 150 |
|
|---|
| 151 | %plug into md
|
|---|
| 152 | md.segmentonneumann_diag=segmentonneumann_diag;
|
|---|
| 153 | md.gridondirichlet_prog=project3d(md,md.gridondirichlet_prog,'node');
|
|---|
| 154 | md.dirichletvalues_prog=project3d(md,md.dirichletvalues_prog,'node');
|
|---|
| 155 | %md.segmentonneumann_prog=[tproj(md.segmentonneumann_prog(:,1)) tproj(md.segmentonneumann_prog(:,2)) tproj2d_el(md.segmentonneumann_prog(:,3))];
|
|---|
| 156 | %md.segmentonneumann_prog2=[tproj(md.segmentonneumann_prog2(:,1)) tproj(md.segmentonneumann_prog2(:,2)) tproj2d_el(md.segmentonneumann_prog2(:,3))];
|
|---|
| 157 |
|
|---|
| 158 | %materials
|
|---|
| 159 | md.B=project3d(md,md.B,'node');
|
|---|
| 160 | md.n=project3d(md,md.n,'element');
|
|---|
| 161 |
|
|---|
| 162 | %parameters
|
|---|
| 163 | md.surface=project3d(md,md.surface,'node');
|
|---|
| 164 | md.thickness=project3d(md,md.thickness,'node');
|
|---|
| 165 | md.bed=project3d(md,md.bed,'node');
|
|---|
| 166 | md.gridonboundary=project3d(md,md.gridonboundary,'node');
|
|---|
| 167 | md.elementoniceshelf=project3d(md,md.elementoniceshelf,'element');
|
|---|
| 168 | md.gridoniceshelf=project3d(md,md.gridoniceshelf,'node');
|
|---|
| 169 | md.elementonicesheet=project3d(md,md.elementonicesheet,'element');
|
|---|
| 170 | md.gridonicesheet=project3d(md,md.gridonicesheet,'node');
|
|---|
| 171 |
|
|---|
| 172 | %special for thermal modeling:
|
|---|
| 173 | md.melting=project3d(md,md.melting,'node',1);
|
|---|
| 174 | md.observed_temperature=project3d(md,md.observed_temperature,'node');
|
|---|
| 175 | md.geothermalflux=project3d(md,md.geothermalflux,'node',1); %bedrock only gets geothermal flux
|
|---|
| 176 | md.gridondirichlet_thermal=project3d(md,md.gridondirichlet_thermal,'node',md.numlayers); %surface temperature
|
|---|
| 177 | md.dirichletvalues_thermal=project3d(md,md.dirichletvalues_thermal,'node',md.numlayers); %surface temperature
|
|---|
| 178 |
|
|---|
| 179 | %NaN the values that are not on an spc'd temperature.
|
|---|
| 180 | pos=find(~md.gridondirichlet_thermal);
|
|---|
| 181 | md.dirichletvalues_thermal(pos)=NaN;
|
|---|
| 182 |
|
|---|
| 183 | %update of connectivity matrix
|
|---|
| 184 | md.connectivity=25;
|
|---|
| 185 |
|
|---|
| 186 | %augment counter keeping track of what has been done to this model
|
|---|
| 187 | md.counter=4;
|
|---|
| 188 |
|
|---|
| 189 | end
|
|---|
| 190 |
|
|---|
| 191 | function extrudeusage(),
|
|---|
| 192 | disp('INPUT function md=extrude(md,numlayers,extrusionexponent) ');
|
|---|
| 193 | disp(' vertically extrude a 2d mesh and create corresponding 3d mesh, ');
|
|---|
| 194 | disp(' the vertical distribution follows a polynomial law:');
|
|---|
| 195 | disp(' extrusionexponent>1 refinement at the base');
|
|---|
| 196 | disp(' 0<extrusionexponent<1 refinement at the surface');
|
|---|
| 197 | disp(' extrusionexponent=1 linear extrusion');
|
|---|
| 198 | end
|
|---|