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 | help extrude;
|
---|
21 | error('extrude error message');
|
---|
22 | end
|
---|
23 |
|
---|
24 | if md.counter<3,
|
---|
25 | help extrude;
|
---|
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 | disp('number of layers should be at least 2. returning initial model...');
|
---|
35 | return
|
---|
36 | end
|
---|
37 |
|
---|
38 | if extrusionexponent<=0,
|
---|
39 | help extrude;
|
---|
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 |
|
---|
51 | %Create the new layers
|
---|
52 | for i=1:numlayers-1,
|
---|
53 | x3d=[x3d; md.x];
|
---|
54 | y3d=[y3d; md.y];
|
---|
55 | %grids are distributed between bed and surface accordingly to the given exponent
|
---|
56 | z3d=[z3d; bed3d+thickness3d*(i/(numlayers-1))^extrusionexponent];
|
---|
57 | end
|
---|
58 | number_grids3d=size(x3d,1); %number of 3d grids for the non extruded part of the mesh
|
---|
59 |
|
---|
60 | %Extrude elements
|
---|
61 | elements3d=[];
|
---|
62 | for i=1:numlayers-1,
|
---|
63 | 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
|
---|
64 | end
|
---|
65 | number_el3d=size(elements3d,1); %number of 3d grids for the non extruded part of the mesh
|
---|
66 |
|
---|
67 | %Keep a trace of lower and upper grids
|
---|
68 | lowergrids=NaN*ones(number_grids3d,1);
|
---|
69 | uppergrids=NaN*ones(number_grids3d,1);
|
---|
70 | lowergrids(md.numberofgrids+1:end)=1:(numlayers-1)*md.numberofgrids;
|
---|
71 | uppergrids(1:(numlayers-1)*md.numberofgrids)=md.numberofgrids+1:number_grids3d;
|
---|
72 | md.lowergrids=lowergrids;
|
---|
73 | md.uppergrids=uppergrids;
|
---|
74 |
|
---|
75 | %Save old mesh
|
---|
76 | md.x2d=md.x;
|
---|
77 | md.y2d=md.y;
|
---|
78 | md.z2d=md.z;
|
---|
79 | md.elements2d=md.elements;
|
---|
80 | md.elements_type2d=md.elements_type;
|
---|
81 | md.numberofelements2d=md.numberofelements;
|
---|
82 | md.numberofgrids2d=md.numberofgrids;
|
---|
83 |
|
---|
84 | %Update mesh type
|
---|
85 | md.type='3d';
|
---|
86 |
|
---|
87 | %Build global 3d mesh
|
---|
88 | md.elements=elements3d;
|
---|
89 | md.x=x3d;
|
---|
90 | md.y=y3d;
|
---|
91 | md.z=z3d;
|
---|
92 | md.numberofelements=number_el3d;
|
---|
93 | md.numberofgrids=number_grids3d;
|
---|
94 | md.numlayers=numlayers;
|
---|
95 |
|
---|
96 | %Ok, now deal with the other fields from the 2d mesh:
|
---|
97 |
|
---|
98 | %drag is limited to grids that are on the bedrock.
|
---|
99 | md.drag=project3d(md,md.drag,'node',1);
|
---|
100 |
|
---|
101 | %p and q (same deal, except for element that are on the bedrock: )
|
---|
102 | md.p=project3d(md,md.p,'element');
|
---|
103 | md.q=project3d(md,md.q,'element');
|
---|
104 |
|
---|
105 | %observations
|
---|
106 | md.vx_obs=project3d(md,md.vx_obs,'node');
|
---|
107 | md.vy_obs=project3d(md,md.vy_obs,'node');
|
---|
108 | md.vel_obs=project3d(md,md.vel_obs,'node');
|
---|
109 | md.vel_obs_raw=project3d(md,md.vel_obs_raw,'node');
|
---|
110 | md.accumulation=project3d(md,md.accumulation,'node');
|
---|
111 | md.firn_layer=project3d(md,md.firn_layer,'node',md.numlayers);
|
---|
112 |
|
---|
113 | %results
|
---|
114 | if ~isnan(md.vx),md.vx=project3d(md,md.vx,'node');end;
|
---|
115 | if ~isnan(md.vy),md.vy=project3d(md,md.vy,'node');end;
|
---|
116 | if ~isnan(md.vz),md.vz=project3d(md,md.vz,'node');end;
|
---|
117 | if ~isnan(md.vel),md.vel=project3d(md,md.vel,'node');end;
|
---|
118 | if ~isnan(md.temperature),md.temperature=project3d(md,md.temperature,'node');end;
|
---|
119 | if ~isnan(md.surface_slopex),md.surface_slopex=project3d(md,md.surface_slopex,'node');end;
|
---|
120 | if ~isnan(md.surface_slopey),md.surface_slopey=project3d(md,md.surface_slopey,'node');end;
|
---|
121 | if ~isnan(md.bed_slopex),md.bed_slopex=project3d(md,md.bed_slopex,'node');end;
|
---|
122 | if ~isnan(md.bed_slopey),md.bed_slopey=project3d(md,md.bed_slopey,'node');end;
|
---|
123 |
|
---|
124 | %bedinfo and surface info
|
---|
125 | md.elementonbed=project3d(md,ones(md.numberofelements2d,1),'element',1);
|
---|
126 | md.elementonsurface=project3d(md,ones(md.numberofelements2d,1),'element',md.numlayers-1);
|
---|
127 | md.gridonbed=project3d(md,ones(md.numberofgrids2d,1),'node',1);
|
---|
128 | md.gridonsurface=project3d(md,ones(md.numberofgrids2d,1),'node',md.numlayers);
|
---|
129 |
|
---|
130 | %elementstype
|
---|
131 | if ~isnan(md.elements_type)
|
---|
132 | oldelements_type=md.elements_type2d;
|
---|
133 | md.elements_type=zeros(number_el3d,2);
|
---|
134 | md.elements_type(:,1)=project3d(md,oldelements_type(:,1),'element');
|
---|
135 | md.elements_type(:,2)=project3d(md,oldelements_type(:,2),'element');
|
---|
136 | md.gridonhutter=project3d(md,md.gridonhutter,'node');
|
---|
137 | md.gridonmacayeal=project3d(md,md.gridonmacayeal,'node');
|
---|
138 | md.gridonpattyn=project3d(md,md.gridonpattyn,'node');
|
---|
139 | md.gridonstokes=project3d(md,md.gridonstokes,'node');
|
---|
140 |
|
---|
141 | %dead grids
|
---|
142 | md.deadgrids=ones(md.numberofgrids,1);
|
---|
143 | md.deadgrids(md.elements(md.elements_type(:,1)~=MacAyealFormulationEnum,:))=0;%non macayeal grids are not dead
|
---|
144 | md.deadgrids(find(md.gridonbed))=0;%grids from elements on bed are not dead
|
---|
145 | end
|
---|
146 |
|
---|
147 | %boundary conditions
|
---|
148 | md.spcvelocity=project3d(md,md.spcvelocity,'node');
|
---|
149 | md.spctemperature=project3d(md,md.spctemperature,'node',md.numlayers);
|
---|
150 | md.spcthickness=project3d(md,md.spcthickness,'node');
|
---|
151 |
|
---|
152 | %Extrusion of Neumann BC
|
---|
153 | %in 3d, segmentonnumann is: [grid1 grid2 grid3 grid4 element]
|
---|
154 | oldpressureload=md.pressureload;
|
---|
155 | pressureload_layer1=[oldpressureload(:,1:2) oldpressureload(:,2)+md.numberofgrids2d oldpressureload(:,1)+md.numberofgrids2d oldpressureload(:,3)]; %Add two columns on the first layer
|
---|
156 | pressureload=[];
|
---|
157 | for i=1:numlayers-1,
|
---|
158 | pressureload=[pressureload ;pressureload_layer1(:,1:4)+(i-1)*md.numberofgrids2d pressureload_layer1(:,5)+(i-1)*md.numberofelements2d ];
|
---|
159 | end
|
---|
160 |
|
---|
161 | %plug into md
|
---|
162 | md.pressureload=pressureload;
|
---|
163 |
|
---|
164 | %materials
|
---|
165 | md.B=project3d(md,md.B,'node');
|
---|
166 | md.n=project3d(md,md.n,'element');
|
---|
167 |
|
---|
168 | %parameters
|
---|
169 | md.surface=project3d(md,md.surface,'node');
|
---|
170 | md.thickness=project3d(md,md.thickness,'node');
|
---|
171 | md.bed=project3d(md,md.bed,'node');
|
---|
172 | md.gridonboundary=project3d(md,md.gridonboundary,'node');
|
---|
173 | md.elementoniceshelf=project3d(md,md.elementoniceshelf,'element');
|
---|
174 | md.gridoniceshelf=project3d(md,md.gridoniceshelf,'node');
|
---|
175 | md.elementonicesheet=project3d(md,md.elementonicesheet,'element');
|
---|
176 | md.gridonicesheet=project3d(md,md.gridonicesheet,'node');
|
---|
177 | md.elementonwater=project3d(md,md.elementonwater,'element');
|
---|
178 | md.gridonwater=project3d(md,md.gridonwater,'node');
|
---|
179 |
|
---|
180 | %special for thermal modeling:
|
---|
181 | md.melting=project3d(md,md.melting,'node',1);
|
---|
182 | md.observed_temperature=project3d(md,md.observed_temperature,'node');
|
---|
183 | md.geothermalflux=project3d(md,md.geothermalflux,'node',1); %bedrock only gets geothermal flux
|
---|
184 |
|
---|
185 | %increase connectivity if less than 25:
|
---|
186 | if md.connectivity<=25,
|
---|
187 | md.connectivity=100;
|
---|
188 | end
|
---|
189 |
|
---|
190 | %augment counter keeping track of what has been done to this model
|
---|
191 | md.counter=4;
|
---|