source: issm/trunk-jpl/examples/Pig/runme.m@ 18198

Last change on this file since 18198 was 18198, checked in by Mathieu Morlighem, 11 years ago

Done with tutorials

  • Property svn:executable set to *
File size: 6.8 KB
Line 
1%Which steps to be performed
2steps=[2] ;
3
4name_prefix='PIG.';
5%Run Steps
6org=organizer('repository','./Models','prefix',name_prefix,'steps',steps);
7
8% {{{ Mesh Generation #1
9if perform(org,'Mesh_generation'),
10
11 md.miscellaneous.name=strcat(name_prefix,'Mesh_generation');
12
13 %Mesh parameters
14 domain =['./DomainOutline.exp'];
15 hmax=40000; % maximum element size of the final mesh
16 hmin=5000; % minimum element size of the final mesh
17 hinit=10000; % element size for the initial mesh
18 gradation=1.7; % maximum size ratio between two neighboring elements
19 err=8; % maximum error between interpolated and control field
20
21 % Generate an initial uniform mesh (resolution = hinit m)
22 md=bamg(model,'domain',domain,'hmax',hinit,'MaxCornerAngle',1);
23
24 %ploting
25 plotmodel(md,'data','mesh')
26
27 % Load Velocities
28 % http://nsidc.org/data/nsidc-0484.html
29 nsidc_vel='../Data/Antarctica_ice_velocity.nc';
30
31 % Get necessary data to build up the velocity grid
32 xmin = ncreadatt(nsidc_vel,'/','xmin');
33 xmin = strtrim(xmin); % this is a string, and we need to recover the double value
34 xmin = xmin(1:end-2); % get rid of the unit
35 xmin = str2num(xmin); % convert to double
36
37 ymax = ncreadatt(nsidc_vel,'/','ymax');
38 ymax = strtrim(ymax);
39 ymax = ymax(1:end-2);
40 ymax = str2num(ymax);
41
42 nx = ncreadatt(nsidc_vel,'/','nx');
43 ny = ncreadatt(nsidc_vel,'/','ny');
44
45 spacing = ncreadatt(nsidc_vel,'/','spacing');
46 spacing = strtrim(spacing);
47 spacing = spacing(1:end-2);
48 spacing = str2num(spacing);
49
50 % Get velocities (Note: You can use ncdisp('file') to see an ncdump)
51 vx = double(ncread(nsidc_vel,'vx'));
52 vy = double(ncread(nsidc_vel,'vy'));
53
54 x=xmin+(0:1:nx)'*spacing;
55 x=double(x);
56 y=(ymax-ny*spacing)+(0:1:ny)'*spacing;
57 y=double(y);
58
59 % Interpolate velocities onto coarse mesh
60 vx_obs=InterpFromGridToMesh(x,y,flipud(vx'),md.mesh.x,md.mesh.y,0);
61 vy_obs=InterpFromGridToMesh(x,y,flipud(vy'),md.mesh.x,md.mesh.y,0);
62 vel_obs=sqrt(vx_obs.^2+vy_obs.^2);
63 clear vx vy x y;
64
65 % Adapt the mesh to minimize error in velocity interpolation
66 md=bamg(md,'hmax',hmax,'hmin',hmin,'gradation',gradation,'field',vel_obs,'err',err);
67
68 %ploting
69 plotmodel(md,'data','mesh')
70
71 % Convert x,y coordinates (Polar stereo) to lat/lon
72 [md.mesh.lat,md.mesh.long]=xy2ll(md.mesh.x,md.mesh.y,-1,39,71);
73
74 % Save model
75 savemodel(org,md);
76end
77% }}}
78
79% {{{ Masks #2
80if perform(org,'SetMask'),
81
82 md = loadmodel(org,'Mesh_generation');
83
84 % Load SeaRISe dataset for Antarctica
85 % http://websrv.cs.umt.edu/isis/index.php/Present_Day_Antarctica
86 searise='../Data/Antarctica_5km_withshelves_v0.75.nc';
87
88 %read thickness mask from SeaRISE
89 x1=double(ncread(searise,'x1'));
90 y1=double(ncread(searise,'y1'));
91 thkmask=double(ncread(searise,'thkmask'));
92
93 %interpolate onto our mesh vertices
94 groundedice=double(InterpFromGridToMesh(x1,y1,thkmask',md.mesh.x,md.mesh.y,0));
95 groundedice(groundedice<=0)=-1;
96 clear thkmask;
97
98 %fill in the md.mask structure
99 md.mask.groundedice_levelset=groundedice; %ice is grounded for mask equal one
100 md.mask.ice_levelset=-1*ones(md.mesh.numberofvertices,1);%ice is present when negatvie
101
102 %ploting
103 plotmodel(md,'data',md.mask.groundedice_levelset,'title','grounded/floating','data',md.mask.ice_levelset,'title','ice/no-ice')
104
105 % Save model
106 savemodel(org,md);
107end
108% }}}
109
110% {{{ Parameterization #3
111if perform(org,'Parameterization')
112
113 md = loadmodel(org,'SetMask');
114 md = parameterize(md,'./Pig.par');
115
116 % Use a MacAyeal flow model
117 md = setflowequation(md,'SSA','all');
118
119 % Save model
120 savemodel(org,md);
121end
122% }}}
123
124% {{{ Control Method #4
125if perform(org,'Control_drag')
126
127 md = loadmodel(org,'Parameterization');
128
129 % Control general
130 md.inversion.iscontrol=1;
131 md.inversion.maxsteps=20;
132 md.inversion.maxiter=40;
133 md.inversion.dxmin=0.1;
134 md.inversion.gttol=1.0e-4;
135 md.verbose=verbose('solution',true,'control',true);
136
137 % Cost functions
138 md.inversion.cost_functions=[101 103 501];
139 md.inversion.cost_functions_coefficients=ones(md.mesh.numberofvertices,3);
140 md.inversion.cost_functions_coefficients(:,1)=1;
141 md.inversion.cost_functions_coefficients(:,2)=1;
142 md.inversion.cost_functions_coefficients(:,3)=8e-15;
143
144 % Controls
145 md.inversion.control_parameters={'FrictionCoefficient'};
146 md.inversion.min_parameters=1*ones(md.mesh.numberofvertices,1);
147 md.inversion.max_parameters=200*ones(md.mesh.numberofvertices,1);
148
149 % Additional parameters
150 md.stressbalance.restol=0.01;
151 md.stressbalance.reltol=0.1;
152 md.stressbalance.abstol=NaN;
153
154 % Solve
155 md.toolkits=toolkits;
156 md.cluster=generic('name',oshostname,'np',2);
157 md=solve(md,StressbalanceSolutionEnum);
158
159 % Update model friction fields accordingly
160 md.friction.coefficient=md.results.StressbalanceSolution.FrictionCoefficient;
161
162 plotmodel(md,'data',md.friction.coefficient)
163
164 % Save model
165 savemodel(org,md);
166end
167% }}}
168
169% {{{ Plot #5
170if perform(org,'PlotSSA')
171
172 md = loadmodel(org,'Control_drag');
173
174 plotmodel(md,'nlines',2,'ncols',2,'unit#all','km','axis#all','equal',...
175 'xlim#all',[min(md.mesh.x) max(md.mesh.x)]/10^3,...
176 'ylim#all',[min(md.mesh.y) max(md.mesh.y)]/10^3,...
177 'FontSize#all',12,...
178 'data',md.initialization.vel,'title','Observed velocity',...
179 'data',md.results.StressbalanceSolution.Vel,'title','Modeled Velocity',...
180 'data',md.geometry.base,'title','Bed elevation',...
181 'data',md.results.StressbalanceSolution.FrictionCoefficient,'title','Friction Coefficient',...
182 'colorbar#all','on','colorbartitle#1-2','[m/yr]',...
183 'caxis#1-2',([1.5,4000]),...
184 'colorbartitle#3','[m]', 'log#1-2',10);
185end
186% }}}
187
188% {{{ HO #6
189if perform(org,'ModelHO')
190
191 % Load Model
192
193 % Disable inversion
194
195 %Extrude Mesh
196
197 % Set Flowequation
198
199 % Solve
200
201 % Save Model
202
203end
204% }}}
205
206% {{{ Plot #7
207if perform(org,'PlotHO')
208
209 mdHO = loadmodel(org,'ModelHO');
210 mdSSA = loadmodel(org,'Control_drag');
211
212 basal=find(mdHO.mesh.vertexonbase);
213 surf=find(mdHO.mesh.vertexonsurface);
214
215 plotmodel(md,'nlines',3,'ncols',2,'unit#all','km','axis#all','equal',...
216 'xlim#all',[min(md.mesh.x) max(md.mesh.x)]/10^3,...
217 'ylim#all',[min(md.mesh.y) max(md.mesh.y)]/10^3,...
218 'FontSize#all',12,...
219 'data',mdHO.initialization.vel,'title','Observed velocity',...
220 'data',(mdHO.results.StressbalanceSolution.Vel(surf)-mdHO.initialization.vel(surf)),'title','(HO-observed) velocities',...
221 'data',mdSSA.results.StressbalanceSolution.Vel,'title','Modeled SSA Velocity',...
222 'data',(mdHO.results.StressbalanceSolution.Vel(surf)-mdSSA.results.StressbalanceSolution.Vel),'title','(HO-SSA) velocities',...
223 'data',mdHO.results.StressbalanceSolution.Vel,'title','Modeled HO surface Velocities',...
224 'data',(mdHO.results.StressbalanceSolution.Vel(surf)-mdHO.results.StressbalanceSolution.Vel(basal)),'title','(HOsurf-HO base) velocities',...
225 'caxis#1',([1.5,4000]),'caxis#3',([1.5,4000]),'caxis#5',([1.5,4000]),...
226 'colorbar#all','on','view#all',2,...
227 'colorbartitle#all','[m/yr]',...
228 'layer#5',1, 'log#1', 10,'log#3', 10,'log#5', 10);
229end
230% }}}
Note: See TracBrowser for help on using the repository browser.