source: issm/trunk/src/m/classes/public/extrude.m@ 510

Last change on this file since 510 was 510, checked in by Eric.Larour, 16 years ago

Extrude velocity observed and accumulation through thickness

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