source: issm/trunk-jpl/src/m/classes/model.m@ 21260

Last change on this file since 21260 was 21260, checked in by adhikari, 8 years ago

NEW: added new ESA capability to compute 3D elastostatic crustal deformation

File size: 63.7 KB
Line 
1%MODEL class definition
2%
3% Usage:
4% md = model(varargin)
5
6classdef model
7 properties (SetAccess=public) %Model fields
8 % {{{
9 %Careful here: no other class should be used as default value this is a bug of matlab
10 mesh = 0;
11 mask = 0;
12
13 geometry = 0;
14 constants = 0;
15 smb = 0;
16 basalforcings = 0;
17 materials = 0;
18 damage = 0;
19 friction = 0;
20 flowequation = 0;
21 timestepping = 0;
22 initialization = 0;
23 rifts = 0;
24 slr = 0;
25
26 debug = 0;
27 verbose = 0;
28 settings = 0;
29 toolkits = 0;
30 cluster = 0;
31
32 balancethickness = 0;
33 stressbalance = 0;
34 groundingline = 0;
35 hydrology = 0;
36 masstransport = 0;
37 thermal = 0;
38 steadystate = 0;
39 transient = 0;
40 levelset = 0;
41 calving = 0;
42 gia = 0;
43 esa = 0;
44
45 autodiff = 0;
46 inversion = 0;
47 qmu = 0;
48
49 results = 0;
50 outputdefinition = 0;
51 radaroverlay = 0;
52 miscellaneous = 0;
53 private = 0;
54
55 %}}}
56 end
57 methods (Static)
58 function md = loadobj(md) % {{{
59 % This function is directly called by matlab when a model object is
60 % loaded. If the input is a struct it is an old version of model and
61 % old fields must be recovered (make sure they are in the deprecated
62 % model properties)
63
64 if verLessThan('matlab','7.9'),
65 disp('Warning: your matlab version is old and there is a risk that load does not work correctly');
66 disp(' if the model is not loaded correctly, rename temporarily loadobj so that matlab does not use it');
67
68 % This is a Matlab bug: all the fields of md have their default value
69 % Example of error message:
70 % Warning: Error loading an object of class 'model':
71 % Undefined function or method 'exist' for input arguments of type 'cell'
72 %
73 % This has been fixed in MATLAB 7.9 (R2009b) and later versions
74 end
75
76 if isstruct(md)
77 disp('Recovering model object from a previous version');
78 md = structtomodel(model,md);
79 end
80
81 %2012 August 4th
82 if isa(md.materials,'materials'),
83 disp('Recovering old materials');
84 if numel(md.materials.rheology_Z)==1 & isnan(md.materials.rheology_Z),
85 md.materials=matice(md.materials);
86 else
87 md.materials=matdamageice(md.materials);
88 end
89 end
90 %2013 April 12
91 if numel(md.stressbalance.loadingforce==1)
92 md.stressbalance.loadingforce=0*ones(md.mesh.numberofvertices,3);
93 end
94 %2013 April 17
95 if isa(md.hydrology,'hydrology'),
96 disp('Recovering old hydrology class');
97 md.hydrology=hydrologyshreve(md.materials);
98 end
99 %2013 October 9
100 if ~isa(md.damage,'damage'),
101 md.damage=damage();
102 md.damage.D=zeros(md.mesh.numberofvertices,1);
103 md.damage.spcdamage=NaN*ones(md.mesh.numberofvertices,1);
104 end
105 %2013 November 18
106 if ~isa(md.outputdefinition,'outputdefinition'),
107 md.outputdefinition=outputdefinition();
108 end
109 %2014 March 26th
110 if isa(md.mesh,'mesh'),
111 disp('Recovering old mesh class');
112 if isprop(md.mesh,'dimension'),
113 if md.mesh.dimension==2,
114 md.mesh=mesh2d(md.mesh);
115 else
116 md.mesh=mesh3dprisms(md.mesh);
117 end
118 else
119 md.mesh=mesh2dvertical(md.mesh);
120 end
121 end
122 %2014 November 12
123 if isa(md.calving,'double');
124 md.calving=calving();
125 end
126 %2016 February 3
127 if isa(md.slr,'double');
128 md.slr=slr();
129 end
130 %2016 October 11
131 if isa(md.esa,'double');
132 md.esa=esa();
133 end
134
135 end% }}}
136 end
137 methods
138 function md = model(varargin) % {{{
139
140 switch nargin
141 case 0
142 md=setdefaultparameters(md);
143 case 1
144 error('model constructor not supported yet');
145
146 otherwise
147 error('model constructor error message: 0 of 1 argument only in input.');
148 end
149 end
150 %}}}
151 function md = checkmessage(md,string) % {{{
152 if(nargout~=1) error('wrong usage, model must be an output'); end
153 disp(['model not consistent: ' string]);
154 md.private.isconsistent=false;
155 end
156 %}}}
157 function md = collapse(md)% {{{
158 %COLLAPSE - collapses a 3d mesh into a 2d mesh
159 %
160 % This routine collapses a 3d model into a 2d model
161 % and collapses all the fileds of the 3d model by
162 % taking their depth-averaged values
163 %
164 % Usage:
165 % md=collapse(md)
166 %
167 % See also: EXTRUDE, MODELEXTRACT
168
169 %Check that the model is really a 3d model
170 if ~strcmp(md.mesh.elementtype(),'Penta'),
171 error('collapse error message: only 3d mesh can be collapsed')
172 end
173
174 %Start with changing all the fields from the 3d mesh
175
176 %dealing with the friciton law
177 %drag is limited to nodes that are on the bedrock.
178 if isa(md.friction,'friction'),
179 md.friction.coefficient=project2d(md,md.friction.coefficient,1);
180 md.friction.p=project2d(md,md.friction.p,1);
181 md.friction.q=project2d(md,md.friction.q,1);
182 elseif isa(md.friction,'frictionhydro'),
183 md.friction.q=project2d(md,md.friction.q,1);
184 md.friction.C=project2d(md,md.friction.C,1);
185 md.friction.As=project2d(md,md.friction.As,1);
186 md.friction.effective_pressure=project2d(md,md.friction.effective_pressure,1);
187 elseif isa(md.friction,'frictionwaterlayer'),
188 md.friction.coefficient=project2d(md,md.friction.coefficient,1);
189 md.friction.p=project2d(md,md.friction.p,1);
190 md.friction.q=project2d(md,md.friction.q,1);
191 md.friction.water_layer=project2d(md,md.friction.water_layer,1);
192 elseif isa(md.friction,'frictionweertman'),
193 md.friction.C=project2d(md,md.friction.C,1);
194 md.friction.m=project2d(md,md.friction.m,1);
195 elseif isa(md.friction,'frictionweertmantemp'),
196 md.friction.C=project2d(md,md.friction.C,1);
197 md.friction.m=project2d(md,md.friction.m,1);
198 else
199 disp('friction type not supported');
200 end
201
202 %observations
203 if ~isnan(md.inversion.vx_obs), md.inversion.vx_obs=project2d(md,md.inversion.vx_obs,md.mesh.numberoflayers); end;
204 if ~isnan(md.inversion.vy_obs), md.inversion.vy_obs=project2d(md,md.inversion.vy_obs,md.mesh.numberoflayers); end;
205 if ~isnan(md.inversion.vel_obs), md.inversion.vel_obs=project2d(md,md.inversion.vel_obs,md.mesh.numberoflayers); end;
206 if ~isnan(md.inversion.cost_functions_coefficients), md.inversion.cost_functions_coefficients=project2d(md,md.inversion.cost_functions_coefficients,md.mesh.numberoflayers); end;
207 if numel(md.inversion.min_parameters)>1, md.inversion.min_parameters=project2d(md,md.inversion.min_parameters,md.mesh.numberoflayers); end;
208 if numel(md.inversion.max_parameters)>1, md.inversion.max_parameters=project2d(md,md.inversion.max_parameters,md.mesh.numberoflayers); end;
209 if isa(md.smb,'SMBforcing') & ~isnan(md.smb.mass_balance),
210 md.smb.mass_balance=project2d(md,md.smb.mass_balance,md.mesh.numberoflayers);
211 elseif isa(md.smb,'SMBhenning') & ~isnan(md.smb.smbref),
212 md.smb.smbref=project2d(md,md.smb.smbref,md.mesh.numberoflayers);
213 end;
214
215 %results
216 if ~isnan(md.initialization.vx),md.initialization.vx=DepthAverage(md,md.initialization.vx);end;
217 if ~isnan(md.initialization.vy),md.initialization.vy=DepthAverage(md,md.initialization.vy);end;
218 if ~isnan(md.initialization.vz),md.initialization.vz=DepthAverage(md,md.initialization.vz);end;
219 if ~isnan(md.initialization.vel),md.initialization.vel=DepthAverage(md,md.initialization.vel);end;
220 if ~isnan(md.initialization.temperature),md.initialization.temperature=DepthAverage(md,md.initialization.temperature);end;
221 if ~isnan(md.initialization.pressure),md.initialization.pressure=project2d(md,md.initialization.pressure,1);end;
222 if ~isnan(md.initialization.sediment_head),md.initialization.sediment_head=project2d(md,md.initialization.sediment_head,1);end;
223 if ~isnan(md.initialization.epl_head),md.initialization.epl_head=project2d(md,md.initialization.epl_head,1);end;
224 if ~isnan(md.initialization.epl_thickness),md.initialization.epl_thickness=project2d(md,md.initialization.epl_thickness,1);end;
225 %gia
226 if ~isnan(md.gia.mantle_viscosity), md.gia.mantle_viscosity=project2d(md,md.gia.mantle_viscosity,1); end
227 if ~isnan(md.gia.lithosphere_thickness), md.gia.lithosphere_thickness=project2d(md,md.gia.lithosphere_thickness,1); end
228
229 %elementstype
230 if ~isnan(md.flowequation.element_equation)
231 md.flowequation.element_equation=project2d(md,md.flowequation.element_equation,1);
232 md.flowequation.vertex_equation=project2d(md,md.flowequation.vertex_equation,1);
233 md.flowequation.borderSSA=project2d(md,md.flowequation.borderSSA,1);
234 md.flowequation.borderHO=project2d(md,md.flowequation.borderHO,1);
235 md.flowequation.borderFS=project2d(md,md.flowequation.borderFS,1);
236 end
237
238 %boundary conditions
239 md.stressbalance.spcvx=project2d(md,md.stressbalance.spcvx,md.mesh.numberoflayers);
240 md.stressbalance.spcvy=project2d(md,md.stressbalance.spcvy,md.mesh.numberoflayers);
241 md.stressbalance.spcvz=project2d(md,md.stressbalance.spcvz,md.mesh.numberoflayers);
242 md.stressbalance.referential=project2d(md,md.stressbalance.referential,md.mesh.numberoflayers);
243 md.stressbalance.loadingforce=project2d(md,md.stressbalance.loadingforce,md.mesh.numberoflayers);
244 md.masstransport.spcthickness=project2d(md,md.masstransport.spcthickness,md.mesh.numberoflayers);
245 if ~isnan(md.damage.spcdamage), md.damage.spcdamage=project2d(md,md.damage.spcdamage,md.mesh.numberoflayers); end
246 md.thermal.spctemperature=project2d(md,md.thermal.spctemperature,md.mesh.numberoflayers);
247
248 % Hydrologydc variables
249 if isa(md.hydrology,'hydrologydc');
250 md.hydrology.spcsediment_head=project2d(md,md.hydrology.spcsediment_head,1);
251 md.hydrology.mask_eplactive_node=project2d(md,md.hydrology.mask_eplactive_node,1);
252 md.hydrology.sediment_transmitivity=project2d(md,md.hydrology.sediment_transmitivity,1);
253 md.hydrology.basal_moulin_input=project2d(md,md.hydrology.basal_moulin_input,1);
254 if(md.hydrology.isefficientlayer==1)
255 md.hydrology.spcepl_head=project2d(md,md.hydrology.spcepl_head,1);
256 end
257 end
258
259 %materials
260 md.materials.rheology_B=DepthAverage(md,md.materials.rheology_B);
261 md.materials.rheology_n=project2d(md,md.materials.rheology_n,1);
262
263 %damage:
264 if md.damage.isdamage,
265 md.damage.D=DepthAverage(md,md.damage.D);
266 end
267
268 %special for thermal modeling:
269 if ~isnan(md.basalforcings.groundedice_melting_rate),
270 md.basalforcings.groundedice_melting_rate=project2d(md,md.basalforcings.groundedice_melting_rate,1);
271 end
272 if ~isnan(md.basalforcings.floatingice_melting_rate),
273 md.basalforcings.floatingice_melting_rate=project2d(md,md.basalforcings.floatingice_melting_rate,1);
274 end
275 md.basalforcings.geothermalflux=project2d(md,md.basalforcings.geothermalflux,1); %bedrock only gets geothermal flux
276
277 %update of connectivity matrix
278 md.mesh.average_vertex_connectivity=25;
279
280 %Collapse the mesh
281 nodes2d=md.mesh.numberofvertices2d;
282 elements2d=md.mesh.numberofelements2d;
283
284 %parameters
285 md.geometry.surface=project2d(md,md.geometry.surface,1);
286 md.geometry.thickness=project2d(md,md.geometry.thickness,1);
287 md.geometry.base=project2d(md,md.geometry.base,1);
288 if ~isnan(md.geometry.bed),
289 md.geometry.bed=project2d(md,md.geometry.bed,1);
290 end
291
292 if ~isnan(md.mask.groundedice_levelset),
293 md.mask.groundedice_levelset=project2d(md,md.mask.groundedice_levelset,1);
294 end
295 if ~isnan(md.mask.ice_levelset),
296 md.mask.ice_levelset=project2d(md,md.mask.ice_levelset,1);
297 end
298
299 %lat long
300 if numel(md.mesh.lat) ==md.mesh.numberofvertices, md.mesh.lat=project2d(md,md.mesh.lat,1); end
301 if numel(md.mesh.long)==md.mesh.numberofvertices, md.mesh.long=project2d(md,md.mesh.long,1); end
302
303 %Initialize with the 2d mesh
304 mesh=mesh2d();
305 mesh.x=md.mesh.x2d;
306 mesh.y=md.mesh.y2d;
307 mesh.numberofvertices=md.mesh.numberofvertices2d;
308 mesh.numberofelements=md.mesh.numberofelements2d;
309 mesh.elements=md.mesh.elements2d;
310 if ~isnan(md.mesh.vertexonboundary), mesh.vertexonboundary=project2d(md,md.mesh.vertexonboundary,1); end
311 if ~isnan(md.mesh.elementconnectivity), mesh.elementconnectivity=project2d(md,md.mesh.elementconnectivity,1); end
312 md.mesh=mesh;
313 md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices);
314 md.mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity);
315 md.mesh.segments=contourenvelope(md.mesh);
316
317 end % }}}
318 function md2 = extract(md,area) % {{{
319 %extract - extract a model according to an Argus contour or flag list
320 %
321 % This routine extracts a submodel from a bigger model with respect to a given contour
322 % md must be followed by the corresponding exp file or flags list
323 % It can either be a domain file (argus type, .exp extension), or an array of element flags.
324 % If user wants every element outside the domain to be
325 % extract2d, add '~' to the name of the domain file (ex: '~HO.exp');
326 % an empty string '' will be considered as an empty domain
327 % a string 'all' will be considered as the entire domain
328 %
329 % Usage:
330 % md2=extract(md,area);
331 %
332 % Examples:
333 % md2=extract(md,'Domain.exp');
334 %
335 % See also: EXTRUDE, COLLAPSE
336
337 %copy model
338 md1=md;
339
340 %some checks
341 if ((nargin~=2) | (nargout~=1)),
342 help extract
343 error('extract error message: bad usage');
344 end
345
346 %get elements that are inside area
347 flag_elem=FlagElements(md1,area);
348 if ~any(flag_elem),
349 error('extracted model is empty');
350 end
351
352 %kick out all elements with 3 dirichlets
353 spc_elem=find(~flag_elem);
354 spc_node=sort(unique(md1.mesh.elements(spc_elem,:)));
355 flag=ones(md1.mesh.numberofvertices,1);
356 flag(spc_node)=0;
357 pos=find(sum(flag(md1.mesh.elements),2)==0);
358 flag_elem(pos)=0;
359
360 %extracted elements and nodes lists
361 pos_elem=find(flag_elem);
362 pos_node=sort(unique(md1.mesh.elements(pos_elem,:)));
363
364 %keep track of some fields
365 numberofvertices1=md1.mesh.numberofvertices;
366 numberofelements1=md1.mesh.numberofelements;
367 numberofvertices2=length(pos_node);
368 numberofelements2=length(pos_elem);
369 flag_node=zeros(numberofvertices1,1);
370 flag_node(pos_node)=1;
371
372 %Create Pelem and Pnode (transform old nodes in new nodes and same thing for the elements)
373 Pelem=zeros(numberofelements1,1);
374 Pelem(pos_elem)=[1:numberofelements2]';
375 Pnode=zeros(numberofvertices1,1);
376 Pnode(pos_node)=[1:numberofvertices2]';
377
378 %renumber the elements (some nodes won't exist anymore)
379 elements_1=md1.mesh.elements;
380 elements_2=elements_1(pos_elem,:);
381 elements_2(:,1)=Pnode(elements_2(:,1));
382 elements_2(:,2)=Pnode(elements_2(:,2));
383 elements_2(:,3)=Pnode(elements_2(:,3));
384 if isa(md1.mesh,'mesh3dprisms'),
385 elements_2(:,4)=Pnode(elements_2(:,4));
386 elements_2(:,5)=Pnode(elements_2(:,5));
387 elements_2(:,6)=Pnode(elements_2(:,6));
388 end
389
390 %OK, now create the new model!
391
392 %take every field from model
393 md2=md1;
394
395 %automatically modify fields
396
397 %loop over model fields
398 model_fields=fields(md1);
399 for i=1:length(model_fields),
400 %get field
401 field=md1.(model_fields{i});
402 fieldsize=size(field);
403 if isobject(field), %recursive call
404 object_fields=fields(md1.(model_fields{i}));
405 for j=1:length(object_fields),
406 %get field
407 field=md1.(model_fields{i}).(object_fields{j});
408 fieldsize=size(field);
409 %size = number of nodes * n
410 if fieldsize(1)==numberofvertices1
411 md2.(model_fields{i}).(object_fields{j})=field(pos_node,:);
412 elseif (fieldsize(1)==numberofvertices1+1)
413 md2.(model_fields{i}).(object_fields{j})=[field(pos_node,:); field(end,:)];
414 %size = number of elements * n
415 elseif fieldsize(1)==numberofelements1
416 md2.(model_fields{i}).(object_fields{j})=field(pos_elem,:);
417 end
418 end
419 else
420 %size = number of nodes * n
421 if fieldsize(1)==numberofvertices1
422 md2.(model_fields{i})=field(pos_node,:);
423 elseif (fieldsize(1)==numberofvertices1+1)
424 md2.(model_fields{i})=[field(pos_node,:); field(end,:)];
425 %size = number of elements * n
426 elseif fieldsize(1)==numberofelements1
427 md2.(model_fields{i})=field(pos_elem,:);
428 end
429 end
430 end
431
432 %modify some specific fields
433
434 %Mesh
435 md2.mesh.numberofelements=numberofelements2;
436 md2.mesh.numberofvertices=numberofvertices2;
437 md2.mesh.elements=elements_2;
438
439 %mesh.uppervertex mesh.lowervertex
440 if isa(md1.mesh,'mesh3dprisms'),
441 md2.mesh.uppervertex=md1.mesh.uppervertex(pos_node);
442 pos=find(~isnan(md2.mesh.uppervertex));
443 md2.mesh.uppervertex(pos)=Pnode(md2.mesh.uppervertex(pos));
444
445 md2.mesh.lowervertex=md1.mesh.lowervertex(pos_node);
446 pos=find(~isnan(md2.mesh.lowervertex));
447 md2.mesh.lowervertex(pos)=Pnode(md2.mesh.lowervertex(pos));
448
449 md2.mesh.upperelements=md1.mesh.upperelements(pos_elem);
450 pos=find(~isnan(md2.mesh.upperelements));
451 md2.mesh.upperelements(pos)=Pelem(md2.mesh.upperelements(pos));
452
453 md2.mesh.lowerelements=md1.mesh.lowerelements(pos_elem);
454 pos=find(~isnan(md2.mesh.lowerelements));
455 md2.mesh.lowerelements(pos)=Pelem(md2.mesh.lowerelements(pos));
456 end
457
458 %Initial 2d mesh
459 if isa(md1.mesh,'mesh3dprisms'),
460 flag_elem_2d=flag_elem(1:md1.mesh.numberofelements2d);
461 pos_elem_2d=find(flag_elem_2d);
462 flag_node_2d=flag_node(1:md1.mesh.numberofvertices2d);
463 pos_node_2d=find(flag_node_2d);
464
465 md2.mesh.numberofelements2d=length(pos_elem_2d);
466 md2.mesh.numberofvertices2d=length(pos_node_2d);
467 md2.mesh.elements2d=md1.mesh.elements2d(pos_elem_2d,:);
468 md2.mesh.elements2d(:,1)=Pnode(md2.mesh.elements2d(:,1));
469 md2.mesh.elements2d(:,2)=Pnode(md2.mesh.elements2d(:,2));
470 md2.mesh.elements2d(:,3)=Pnode(md2.mesh.elements2d(:,3));
471
472 md2.mesh.x2d=md1.mesh.x(pos_node_2d);
473 md2.mesh.y2d=md1.mesh.y(pos_node_2d);
474 end
475
476 %Edges
477 if(dimension(md.mesh)==2),
478 if size(md2.mesh.edges,2)>1, %do not use ~isnan because there are some NaNs...
479 %renumber first two columns
480 pos=find(md2.mesh.edges(:,4)~=-1);
481 md2.mesh.edges(: ,1)=Pnode(md2.mesh.edges(:,1));
482 md2.mesh.edges(: ,2)=Pnode(md2.mesh.edges(:,2));
483 md2.mesh.edges(: ,3)=Pelem(md2.mesh.edges(:,3));
484 md2.mesh.edges(pos,4)=Pelem(md2.mesh.edges(pos,4));
485 %remove edges when the 2 vertices are not in the domain.
486 md2.mesh.edges=md2.mesh.edges(find(md2.mesh.edges(:,1) & md2.mesh.edges(:,2)),:);
487 %Replace all zeros by -1 in the last two columns
488 pos=find(md2.mesh.edges(:,3)==0);
489 md2.mesh.edges(pos,3)=-1;
490 pos=find(md2.mesh.edges(:,4)==0);
491 md2.mesh.edges(pos,4)=-1;
492 %Invert -1 on the third column with last column (Also invert first two columns!!)
493 pos=find(md2.mesh.edges(:,3)==-1);
494 md2.mesh.edges(pos,3)=md2.mesh.edges(pos,4);
495 md2.mesh.edges(pos,4)=-1;
496 values=md2.mesh.edges(pos,2);
497 md2.mesh.edges(pos,2)=md2.mesh.edges(pos,1);
498 md2.mesh.edges(pos,1)=values;
499 %Finally remove edges that do not belong to any element
500 pos=find(md2.mesh.edges(:,3)==-1 & md2.mesh.edges(:,4)==-1);
501 md2.mesh.edges(pos,:)=[];
502 end
503 end
504
505 %Penalties
506 if ~isnan(md2.stressbalance.vertex_pairing),
507 for i=1:size(md1.stressbalance.vertex_pairing,1);
508 md2.stressbalance.vertex_pairing(i,:)=Pnode(md1.stressbalance.vertex_pairing(i,:));
509 end
510 md2.stressbalance.vertex_pairing=md2.stressbalance.vertex_pairing(find(md2.stressbalance.vertex_pairing(:,1)),:);
511 end
512 if ~isnan(md2.masstransport.vertex_pairing),
513 for i=1:size(md1.masstransport.vertex_pairing,1);
514 md2.masstransport.vertex_pairing(i,:)=Pnode(md1.masstransport.vertex_pairing(i,:));
515 end
516 md2.masstransport.vertex_pairing=md2.masstransport.vertex_pairing(find(md2.masstransport.vertex_pairing(:,1)),:);
517 end
518
519 %recreate segments
520 if isa(md1.mesh,'mesh2d') | isa(md1.mesh','mesh3dsurface'),
521 md2.mesh.vertexconnectivity=NodeConnectivity(md2.mesh.elements,md2.mesh.numberofvertices);
522 md2.mesh.elementconnectivity=ElementConnectivity(md2.mesh.elements,md2.mesh.vertexconnectivity);
523 md2.mesh.segments=contourenvelope(md2.mesh);
524 md2.mesh.vertexonboundary=zeros(numberofvertices2,1); md2.mesh.vertexonboundary(md2.mesh.segments(:,1:2))=1;
525 else
526 %First do the connectivity for the contourenvelope in 2d
527 md2.mesh.vertexconnectivity=NodeConnectivity(md2.mesh.elements2d,md2.mesh.numberofvertices2d);
528 md2.mesh.elementconnectivity=ElementConnectivity(md2.mesh.elements2d,md2.mesh.vertexconnectivity);
529 segments=contourenvelope(md2.mesh);
530 md2.mesh.vertexonboundary=zeros(numberofvertices2/md2.mesh.numberoflayers,1); md2.mesh.vertexonboundary(segments(:,1:2))=1;
531 md2.mesh.vertexonboundary=repmat(md2.mesh.vertexonboundary,md2.mesh.numberoflayers,1);
532 %Then do it for 3d as usual
533 md2.mesh.vertexconnectivity=NodeConnectivity(md2.mesh.elements,md2.mesh.numberofvertices);
534 md2.mesh.elementconnectivity=ElementConnectivity(md2.mesh.elements,md2.mesh.vertexconnectivity);
535 end
536
537 %Boundary conditions: Dirichlets on new boundary
538 %Catch the elements that have not been extracted
539 orphans_elem=find(~flag_elem);
540 orphans_node=unique(md1.mesh.elements(orphans_elem,:))';
541 %Figure out which node are on the boundary between md2 and md1
542 nodestoflag1=intersect(orphans_node,pos_node);
543 nodestoflag2=Pnode(nodestoflag1);
544 if numel(md1.stressbalance.spcvx)>1 & numel(md1.stressbalance.spcvy)>2 & numel(md1.stressbalance.spcvz)>2,
545 if numel(md1.inversion.vx_obs)>1 & numel(md1.inversion.vy_obs)>1
546 md2.stressbalance.spcvx(nodestoflag2)=md2.inversion.vx_obs(nodestoflag2);
547 md2.stressbalance.spcvy(nodestoflag2)=md2.inversion.vy_obs(nodestoflag2);
548 else
549 md2.stressbalance.spcvx(nodestoflag2)=NaN;
550 md2.stressbalance.spcvy(nodestoflag2)=NaN;
551 disp(' ')
552 disp('!! extract warning: spc values should be checked !!')
553 disp(' ')
554 end
555 %put 0 for vz
556 md2.stressbalance.spcvz(nodestoflag2)=0;
557 end
558 if ~isnan(md1.thermal.spctemperature),
559 md2.thermal.spctemperature(nodestoflag2,1)=1;
560 end
561
562 %Results fields
563 if isstruct(md1.results),
564 md2.results=struct();
565 solutionfields=fields(md1.results);
566 for i=1:length(solutionfields),
567 if isstruct(md1.results.(solutionfields{i}))
568 %get subfields
569 solutionsubfields=fields(md1.results.(solutionfields{i}));
570 for j=1:length(solutionsubfields),
571 field=md1.results.(solutionfields{i}).(solutionsubfields{j});
572 if length(field)==numberofvertices1,
573 md2.results.(solutionfields{i}).(solutionsubfields{j})=field(pos_node);
574 elseif length(field)==numberofelements1,
575 md2.results.(solutionfields{i}).(solutionsubfields{j})=field(pos_elem);
576 else
577 md2.results.(solutionfields{i}).(solutionsubfields{j})=field;
578 end
579 end
580 else
581 field=md1.results.(solutionfields{i});
582 if length(field)==numberofvertices1,
583 md2.results.(solutionfields{i})=field(pos_node);
584 elseif length(field)==numberofelements1,
585 md2.results.(solutionfields{i})=field(pos_elem);
586 else
587 md2.results.(solutionfields{i})=field;
588 end
589 end
590 end
591 end
592
593 %Keep track of pos_node and pos_elem
594 md2.mesh.extractedvertices=pos_node;
595 md2.mesh.extractedelements=pos_elem;
596 end % }}}
597 function md = extrude(md,varargin) % {{{
598 %EXTRUDE - vertically extrude a 2d mesh
599 %
600 % vertically extrude a 2d mesh and create corresponding 3d mesh.
601 % The vertical distribution can:
602 % - follow a polynomial law
603 % - follow two polynomial laws, one for the lower part and one for the upper part of the mesh
604 % - be discribed by a list of coefficients (between 0 and 1)
605 %
606 %
607 % Usage:
608 % md=extrude(md,numlayers,extrusionexponent);
609 % md=extrude(md,numlayers,lowerexponent,upperexponent);
610 % md=extrude(md,listofcoefficients);
611 %
612 % Example:
613 % md=extrude(md,15,1.3);
614 % md=extrude(md,15,1.3,1.2);
615 % md=extrude(md,[0 0.2 0.5 0.7 0.9 0.95 1]);
616 %
617 % See also: MODELEXTRACT, COLLAPSE
618
619 %some checks on list of arguments
620 if ((nargin>4) | (nargin<2) | (nargout~=1)),
621 help extrude;
622 error('extrude error message');
623 end
624
625 %Extrude the mesh
626 if nargin==2, %list of coefficients
627 clist=varargin{1};
628 if any(clist<0) | any(clist>1),
629 error('extrusioncoefficients must be between 0 and 1');
630 end
631 extrusionlist=sort(unique([clist(:);0;1]));
632 numlayers=length(extrusionlist);
633 elseif nargin==3, %one polynomial law
634 if varargin{2}<=0,
635 help extrude;
636 error('extrusionexponent must be >=0');
637 end
638 numlayers=varargin{1};
639 extrusionlist=((0:1:numlayers-1)/(numlayers-1)).^varargin{2};
640 elseif nargin==4, %two polynomial laws
641 numlayers=varargin{1};
642 lowerexp=varargin{2};
643 upperexp=varargin{3};
644
645 if varargin{2}<=0 | varargin{3}<=0,
646 help extrude;
647 error('lower and upper extrusionexponents must be >=0');
648 end
649
650 lowerextrusionlist=[(0:2/(numlayers-1):1).^lowerexp]/2;
651 upperextrusionlist=[(0:2/(numlayers-1):1).^upperexp]/2;
652 extrusionlist=sort(unique([lowerextrusionlist 1-upperextrusionlist]));
653
654 end
655
656 if numlayers<2,
657 error('number of layers should be at least 2');
658 end
659 if strcmp(md.mesh.domaintype(),'3D')
660 error('Cannot extrude a 3d mesh (extrude cannot be called more than once)');
661 end
662
663 %Initialize with the 2d mesh
664 mesh2d = md.mesh;
665 md.mesh=mesh3dprisms();
666 md.mesh.x = mesh2d.x;
667 md.mesh.y = mesh2d.y;
668 md.mesh.elements = mesh2d.elements;
669 md.mesh.numberofelements = mesh2d.numberofelements;
670 md.mesh.numberofvertices = mesh2d.numberofvertices;
671
672 md.mesh.lat = mesh2d.lat;
673 md.mesh.long = mesh2d.long;
674 md.mesh.epsg = mesh2d.epsg;
675
676 md.mesh.vertexonboundary = mesh2d.vertexonboundary;
677 md.mesh.vertexconnectivity = mesh2d.vertexconnectivity;
678 md.mesh.elementconnectivity = mesh2d.elementconnectivity;
679 md.mesh.average_vertex_connectivity = mesh2d.average_vertex_connectivity;
680
681 md.mesh.extractedvertices = mesh2d.extractedvertices;
682 md.mesh.extractedelements = mesh2d.extractedelements;
683
684 x3d=[];
685 y3d=[];
686 z3d=[]; %the lower node is on the bed
687 thickness3d=md.geometry.thickness; %thickness and bed for these nodes
688 bed3d=md.geometry.base;
689
690 %Create the new layers
691 for i=1:numlayers,
692 x3d=[x3d; md.mesh.x];
693 y3d=[y3d; md.mesh.y];
694 %nodes are distributed between bed and surface accordingly to the given exponent
695 z3d=[z3d; bed3d+thickness3d*extrusionlist(i)];
696 end
697 number_nodes3d=size(x3d,1); %number of 3d nodes for the non extruded part of the mesh
698
699 %Extrude elements
700 elements3d=[];
701 for i=1:numlayers-1,
702 elements3d=[elements3d;[md.mesh.elements+(i-1)*md.mesh.numberofvertices md.mesh.elements+i*md.mesh.numberofvertices]]; %Create the elements of the 3d mesh for the non extruded part
703 end
704 number_el3d=size(elements3d,1); %number of 3d nodes for the non extruded part of the mesh
705
706 %Keep a trace of lower and upper nodes
707 lowervertex=NaN*ones(number_nodes3d,1);
708 uppervertex=NaN*ones(number_nodes3d,1);
709 lowervertex(md.mesh.numberofvertices+1:end)=1:(numlayers-1)*md.mesh.numberofvertices;
710 uppervertex(1:(numlayers-1)*md.mesh.numberofvertices)=md.mesh.numberofvertices+1:number_nodes3d;
711 md.mesh.lowervertex=lowervertex;
712 md.mesh.uppervertex=uppervertex;
713
714 %same for lower and upper elements
715 lowerelements=NaN*ones(number_el3d,1);
716 upperelements=NaN*ones(number_el3d,1);
717 lowerelements(md.mesh.numberofelements+1:end)=1:(numlayers-2)*md.mesh.numberofelements;
718 upperelements(1:(numlayers-2)*md.mesh.numberofelements)=md.mesh.numberofelements+1:(numlayers-1)*md.mesh.numberofelements;
719 md.mesh.lowerelements=lowerelements;
720 md.mesh.upperelements=upperelements;
721
722 %Save old mesh
723 md.mesh.x2d=md.mesh.x;
724 md.mesh.y2d=md.mesh.y;
725 md.mesh.elements2d=md.mesh.elements;
726 md.mesh.numberofelements2d=md.mesh.numberofelements;
727 md.mesh.numberofvertices2d=md.mesh.numberofvertices;
728
729 %Build global 3d mesh
730 md.mesh.elements=elements3d;
731 md.mesh.x=x3d;
732 md.mesh.y=y3d;
733 md.mesh.z=z3d;
734 md.mesh.numberofelements=number_el3d;
735 md.mesh.numberofvertices=number_nodes3d;
736 md.mesh.numberoflayers=numlayers;
737
738 %Ok, now deal with the other fields from the 2d mesh:
739
740 %bedinfo and surface info
741 md.mesh.vertexonbase=project3d(md,'vector',ones(md.mesh.numberofvertices2d,1),'type','node','layer',1);
742 md.mesh.vertexonsurface=project3d(md,'vector',ones(md.mesh.numberofvertices2d,1),'type','node','layer',md.mesh.numberoflayers);
743 md.mesh.vertexonboundary=project3d(md,'vector',md.mesh.vertexonboundary,'type','node');
744
745 %lat long
746 md.mesh.lat=project3d(md,'vector',md.mesh.lat,'type','node');
747 md.mesh.long=project3d(md,'vector',md.mesh.long,'type','node');
748
749 md.geometry=extrude(md.geometry,md);
750 md.friction = extrude(md.friction,md);
751 md.inversion = extrude(md.inversion,md);
752 md.smb = extrude(md.smb,md);
753 md.initialization = extrude(md.initialization,md);
754
755 md.flowequation=md.flowequation.extrude(md);
756 md.stressbalance=extrude(md.stressbalance,md);
757 md.thermal=md.thermal.extrude(md);
758 md.masstransport=md.masstransport.extrude(md);
759 md.levelset=extrude(md.levelset,md);
760 md.calving=extrude(md.calving,md);
761 md.hydrology = extrude(md.hydrology,md);
762
763 %connectivity
764 if ~isnan(md.mesh.elementconnectivity)
765 md.mesh.elementconnectivity=repmat(md.mesh.elementconnectivity,numlayers-1,1);
766 md.mesh.elementconnectivity(find(md.mesh.elementconnectivity==0))=NaN;
767 for i=2:numlayers-1,
768 md.mesh.elementconnectivity((i-1)*md.mesh.numberofelements2d+1:(i)*md.mesh.numberofelements2d,:)...
769 =md.mesh.elementconnectivity((i-1)*md.mesh.numberofelements2d+1:(i)*md.mesh.numberofelements2d,:)+md.mesh.numberofelements2d;
770 end
771 md.mesh.elementconnectivity(find(isnan(md.mesh.elementconnectivity)))=0;
772 end
773
774 md.materials=extrude(md.materials,md);
775 md.damage=extrude(md.damage,md);
776 md.mask=extrude(md.mask,md);
777 md.qmu=extrude(md.qmu,md);
778 md.basalforcings=extrude(md.basalforcings,md);
779
780 %increase connectivity if less than 25:
781 if md.mesh.average_vertex_connectivity<=25,
782 md.mesh.average_vertex_connectivity=100;
783 end
784 end % }}}
785 function md = structtomodel(md,structmd) % {{{
786
787 if ~isstruct(structmd) error('input model is not a structure'); end
788
789 %loaded model is a struct, initialize output and recover all fields
790 md = structtoobj(model,structmd);
791
792 %Old field now classes
793 if (isfield(structmd,'timestepping') & isnumeric(md.timestepping)), md.timestepping=timestepping(); end
794 if (isfield(structmd,'mask') & isnumeric(md.mask)),md.mask=mask(); end
795
796 %Field name change
797 if isfield(structmd,'drag'), md.friction.coefficient=structmd.drag; end
798 if isfield(structmd,'p'), md.friction.p=structmd.p; end
799 if isfield(structmd,'q'), md.friction.q=structmd.p; end
800 if isfield(structmd,'melting'), md.basalforcings.floatingice_melting_rate=structmd.melting; end
801 if isfield(structmd,'melting_rate'), md.basalforcings.floatingice_melting_rate=structmd.melting_rate; end
802 if isfield(structmd,'melting_rate'), md.basalforcings.groundedice_melting_rate=structmd.melting_rate; end
803 if isfield(structmd,'accumulation'), md.smb.mass_balance=structmd.accumulation; end
804 if isfield(structmd,'numberofgrids'), md.mesh.numberofvertices=structmd.numberofgrids; end
805 if isfield(structmd,'numberofgrids2d'), md.mesh.numberofvertices2d=structmd.numberofgrids2d; end
806 if isfield(structmd,'uppergrids'), md.mesh.uppervertex=structmd.uppergrids; end
807 if isfield(structmd,'lowergrids'), md.mesh.lowervertex=structmd.lowergrids; end
808 if isfield(structmd,'gridonbase'), md.mesh.vertexonbase=structmd.gridonbase; end
809 if isfield(structmd,'gridonsurface'), md.mesh.vertexonsurface=structmd.gridonsurface; end
810 if isfield(structmd,'extractedgrids'), md.mesh.extractedvertices=structmd.extractedgrids; end
811 if isfield(structmd,'gridonboundary'), md.mesh.vertexonboundary=structmd.gridonboundary; end
812 if isfield(structmd,'petscoptions') & ~isempty(structmd.petscoptions), md.toolkits=structmd.petscoptions; end
813 if isfield(structmd,'g'), md.constants.g=structmd.g; end
814 if isfield(structmd,'yts'), md.constants.yts=structmd.yts; end
815 if isfield(structmd,'surface_mass_balance'), md.smb.mass_balance=structmd.surface_mass_balance; end
816 if isfield(structmd,'basal_melting_rate'), md.basalforcings.floatingice_melting_rate=structmd.basal_melting_rate; end
817 if isfield(structmd,'geothermalflux'), md.basalforcings.geothermalflux=structmd.geothermalflux; end
818 if isfield(structmd,'drag'), md.friction.coefficient=structmd.drag; end
819 if isfield(structmd,'drag_coefficient'), md.friction.coefficient=structmd.drag_coefficient; end
820 if isfield(structmd,'drag_p'), md.friction.p=structmd.drag_p; end
821 if isfield(structmd,'drag_q'), md.friction.q=structmd.drag_q; end
822 if isfield(structmd,'riftproperties'), %old implementation
823 md.rifts=rifts();
824 md.rifts.riftproperties=structmd.riftproperties;
825 md.rifts.riftstruct=structmd.rifts;
826 md.rifts.riftproperties=structmd.riftinfo;
827 end
828 if isfield(structmd,'bamg'), md.private.bamg=structmd.bamg; end
829 if isfield(structmd,'lowmem'), md.settings.lowmem=structmd.lowmem; end
830 if isfield(structmd,'io_gather'), md.settings.io_gather=structmd.io_gather; end
831 if isfield(structmd,'spcwatercolumn'), md.hydrology.spcwatercolumn=structmd.spcwatercolumn; end
832 if isfield(structmd,'hydro_n'), md.hydrology.n=structmd.hydro_n; end
833 if isfield(structmd,'hydro_p'), md.hydrology.p=structmd.hydro_p; end
834 if isfield(structmd,'hydro_q'), md.hydrology.q=structmd.hydro_q; end
835 if isfield(structmd,'hydro_CR'), md.hydrology.CR=structmd.hydro_CR; end
836 if isfield(structmd,'hydro_kn'), md.hydrology.kn=structmd.hydro_kn; end
837 if isfield(structmd,'spctemperature'), md.thermal.spctemperature=structmd.spctemperature; end
838 if isfield(structmd,'min_thermal_constraints'), md.thermal.penalty_threshold=structmd.min_thermal_constraints; end
839 if isfield(structmd,'artificial_diffusivity'), md.thermal.stabilization=structmd.artificial_diffusivity; end
840 if isfield(structmd,'max_nonlinear_iterations'), md.thermal.maxiter=structmd.max_nonlinear_iterations; end
841 if isfield(structmd,'stabilize_constraints'), md.thermal.penalty_lock=structmd.stabilize_constraints; end
842 if isfield(structmd,'penalty_offset'), md.thermal.penalty_factor=structmd.penalty_offset; end
843 if isfield(structmd,'name'), md.miscellaneous.name=structmd.name; end
844 if isfield(structmd,'notes'), md.miscellaneous.notes=structmd.notes; end
845 if isfield(structmd,'dummy'), md.miscellaneous.dummy=structmd.dummy; end
846 if isfield(structmd,'dt'), md.timestepping.time_step=structmd.dt; end
847 if isfield(structmd,'ndt'), md.timestepping.final_time=structmd.ndt; end
848 if isfield(structmd,'time_adapt'), md.timestepping.time_adapt=structmd.time_adapt; end
849 if isfield(structmd,'cfl_coefficient'), md.timestepping.cfl_coefficient=structmd.cfl_coefficient; end
850 if isfield(structmd,'spcthickness'), md.masstransport.spcthickness=structmd.spcthickness; end
851 if isfield(structmd,'artificial_diffusivity'), md.masstransport.stabilization=structmd.artificial_diffusivity; end
852 if isfield(structmd,'hydrostatic_adjustment'), md.masstransport.hydrostatic_adjustment=structmd.hydrostatic_adjustment; end
853 if isfield(structmd,'penalties'), md.masstransport.vertex_pairing=structmd.penalties; end
854 if isfield(structmd,'penalty_offset'), md.masstransport.penalty_factor=structmd.penalty_offset; end
855 if isfield(structmd,'B'), md.materials.rheology_B=structmd.B; end
856 if isfield(structmd,'n'), md.materials.rheology_n=structmd.n; end
857 if isfield(structmd,'rheology_B'), md.materials.rheology_B=structmd.rheology_B; end
858 if isfield(structmd,'rheology_n'), md.materials.rheology_n=structmd.rheology_n; end
859 if isfield(structmd,'rheology_Z'), md.damage.D=(1-structmd.rheology_Z); end
860 if isfield(structmd,'spcthickness'), md.balancethickness.spcthickness=structmd.spcthickness; end
861 if isfield(structmd,'artificial_diffusivity'), md.balancethickness.stabilization=structmd.artificial_diffusivity; end
862 if isfield(structmd,'dhdt'), md.balancethickness.thickening_rate=structmd.dhdt; end
863 if isfield(structmd,'isSIA'), md.flowequation.isSIA=structmd.isSIA; end
864 if isfield(structmd,'isFS'), md.flowequation.isFS=structmd.isFS; end
865 if isfield(structmd,'elements_type'), md.flowequation.element_equation=structmd.elements_type; end
866 if isfield(structmd,'vertices_type'), md.flowequation.vertex_equation=structmd.vertices_type; end
867 if isfield(structmd,'eps_rel'), md.steadystate.reltol=structmd.eps_rel; end
868 if isfield(structmd,'max_steadystate_iterations'), md.steadystate.maxiter=structmd.max_steadystate_iterations; end
869 if isfield(structmd,'isdiagnostic'), md.transient.isstressbalance=structmd.isdiagnostic; end
870 if isfield(structmd,'isprognostic'), md.transient.ismasstransport=structmd.isprognostic; end
871 if isfield(structmd,'isthermal'), md.transient.isthermal=structmd.isthermal; end
872 if isfield(structmd,'control_analysis'), md.inversion.iscontrol=structmd.control_analysis; end
873 if isfield(structmd,'weights'), md.inversion.cost_functions_coefficients=structmd.weights; end
874 if isfield(structmd,'nsteps'), md.inversion.nsteps=structmd.nsteps; end
875 if isfield(structmd,'maxiter_per_step'), md.inversion.maxiter_per_step=structmd.maxiter_per_step; end
876 if isfield(structmd,'cm_min'), md.inversion.min_parameters=structmd.cm_min; end
877 if isfield(structmd,'cm_max'), md.inversion.max_parameters=structmd.cm_max; end
878 if isfield(structmd,'vx_obs'), md.inversion.vx_obs=structmd.vx_obs; end
879 if isfield(structmd,'vy_obs'), md.inversion.vy_obs=structmd.vy_obs; end
880 if isfield(structmd,'vel_obs'), md.inversion.vel_obs=structmd.vel_obs; end
881 if isfield(structmd,'thickness_obs'), md.inversion.thickness_obs=structmd.thickness_obs; end
882 if isfield(structmd,'vx'), md.initialization.vx=structmd.vx; end
883 if isfield(structmd,'vy'), md.initialization.vy=structmd.vy; end
884 if isfield(structmd,'vz'), md.initialization.vz=structmd.vz; end
885 if isfield(structmd,'vel'), md.initialization.vel=structmd.vel; end
886 if isfield(structmd,'pressure'), md.initialization.pressure=structmd.pressure; end
887 if isfield(structmd,'temperature'), md.initialization.temperature=structmd.temperature; end
888 if isfield(structmd,'waterfraction'), md.initialization.waterfraction=structmd.waterfraction; end
889 if isfield(structmd,'watercolumn'), md.initialization.watercolumn=structmd.watercolumn; end
890 if isfield(structmd,'surface'), md.geometry.surface=structmd.surface; end
891 if isfield(structmd,'bed'), md.geometry.base=structmd.bed; end
892 if isfield(structmd,'thickness'), md.geometry.thickness=structmd.thickness; end
893 if isfield(structmd,'bathymetry'), md.geometry.bed=structmd.bathymetry; end
894 if isfield(structmd,'thickness_coeff'), md.geometry.hydrostatic_ratio=structmd.thickness_coeff; end
895 if isfield(structmd,'connectivity'), md.mesh.average_vertex_connectivity=structmd.connectivity; end
896 if isfield(structmd,'extractednodes'), md.mesh.extractedvertices=structmd.extractednodes; end
897 if isfield(structmd,'extractedelements'), md.mesh.extractedelements=structmd.extractedelements; end
898 if isfield(structmd,'nodeonboundary'), md.mesh.vertexonboundary=structmd.nodeonboundary; end
899 if isfield(structmd,'lat'), md.mesh.lat=structmd.lat; end
900 if isfield(structmd,'long'), md.mesh.long=structmd.long; end
901 if isfield(structmd,'segments'), md.mesh.segments=structmd.segments; end
902 if isfield(structmd,'segmentmarkers'), md.mesh.segmentmarkers=structmd.segmentmarkers; end
903 if isfield(structmd,'numlayers'), md.mesh.numberoflayers=structmd.numlayers; end
904 if isfield(structmd,'numberofelements'), md.mesh.numberofelements=structmd.numberofelements; end
905 if isfield(structmd,'numberofvertices'), md.mesh.numberofvertices=structmd.numberofvertices; end
906 if isfield(structmd,'numberofnodes'), md.mesh.numberofvertices=structmd.numberofnodes; end
907 if isfield(structmd,'numberofedges'), md.mesh.numberofedges=structmd.numberofedges; end
908 if isfield(structmd,'numberofelements2d'), md.mesh.numberofelements2d=structmd.numberofelements2d; end
909 if isfield(structmd,'numberofnodes2d'), md.mesh.numberofvertices2d=structmd.numberofnodes2d; end
910 if isfield(structmd,'nodeconnectivity'), md.mesh.vertexconnectivity=structmd.nodeconnectivity; end
911 if isfield(structmd,'elementconnectivity'), md.mesh.elementconnectivity=structmd.elementconnectivity; end
912 if isfield(structmd,'uppernodes'), md.mesh.uppervertex=structmd.uppernodes; end
913 if isfield(structmd,'lowernodes'), md.mesh.lowervertex=structmd.lowernodes; end
914 if isfield(structmd,'upperelements'), md.mesh.upperelements=structmd.upperelements; end
915 if isfield(structmd,'lowerelements'), md.mesh.lowerelements=structmd.lowerelements; end
916 if isfield(structmd,'nodeonsurface'), md.mesh.vertexonsurface=structmd.nodeonsurface; end
917 if isfield(structmd,'nodeonbase'), md.mesh.vertexonbase=structmd.nodeonbase; end
918 if isfield(structmd,'elements2d'), md.mesh.elements2d=structmd.elements2d; end
919 if isfield(structmd,'y2d'), md.mesh.y2d=structmd.y2d; end
920 if isfield(structmd,'x2d'), md.mesh.x2d=structmd.x2d; end
921 if isfield(structmd,'elements'), md.mesh.elements=structmd.elements; end
922 if isfield(structmd,'edges'),
923 md.mesh.edges=structmd.edges;
924 md.mesh.edges(isnan(md.mesh.edges))=-1;
925 end
926 if isfield(structmd,'y'), md.mesh.y=structmd.y; end
927 if isfield(structmd,'x'), md.mesh.x=structmd.x; end
928 if isfield(structmd,'z'), md.mesh.z=structmd.z; end
929 if isfield(structmd,'diagnostic_ref'), md.stressbalance.referential=structmd.diagnostic_ref; end
930 if isfield(structmd,'npart'); md.qmu.numberofpartitions=structmd.npart; end
931 if isfield(structmd,'part'); md.qmu.partition=structmd.part; end
932
933 if isnumeric(md.verbose),
934 md.verbose=verbose;
935 end
936
937 if isfield(structmd,'spcvelocity'),
938 md.stressbalance.spcvx=NaN*ones(md.mesh.numberofvertices,1);
939 md.stressbalance.spcvy=NaN*ones(md.mesh.numberofvertices,1);
940 md.stressbalance.spcvz=NaN*ones(md.mesh.numberofvertices,1);
941 pos=find(structmd.spcvelocity(:,1)); md.stressbalance.spcvx(pos)=structmd.spcvelocity(pos,4);
942 pos=find(structmd.spcvelocity(:,2)); md.stressbalance.spcvy(pos)=structmd.spcvelocity(pos,5);
943 pos=find(structmd.spcvelocity(:,3)); md.stressbalance.spcvz(pos)=structmd.spcvelocity(pos,6);
944 end
945 if isfield(structmd,'spcvx'),
946 md.stressbalance.spcvx=NaN*ones(md.mesh.numberofvertices,1);
947 pos=find(~isnan(structmd.spcvx)); md.stressbalance.spcvx(pos)=structmd.spcvx(pos);
948 end
949 if isfield(structmd,'spcvy'),
950 md.stressbalance.spcvy=NaN*ones(md.mesh.numberofvertices,1);
951 pos=find(~isnan(structmd.spcvy)); md.stressbalance.spcvy(pos)=structmd.spcvy(pos);
952 end
953 if isfield(structmd,'spcvz'),
954 md.stressbalance.spcvz=NaN*ones(md.mesh.numberofvertices,1);
955 pos=find(~isnan(structmd.spcvz)); md.stressbalance.spcvz(pos)=structmd.spcvz(pos);
956 end
957 if isfield(structmd,'pressureload'),
958 if ~isempty(structmd.pressureload) & ismember(structmd.pressureload(end,end),[118 119 120]),
959 pos=find(structmd.pressureload(:,end)==120); md.stressbalance.icefront(pos,end)=0;
960 pos=find(structmd.pressureload(:,end)==118); md.stressbalance.icefront(pos,end)=1;
961 pos=find(structmd.pressureload(:,end)==119); md.stressbalance.icefront(pos,end)=2;
962 end
963 end
964 if isfield(structmd,'elements_type') & structmd.elements_type(end,end)>50,
965 pos=find(structmd.elements_type==59); md.flowequation.element_equation(pos,end)=0;
966 pos=find(structmd.elements_type==55); md.flowequation.element_equation(pos,end)=1;
967 pos=find(structmd.elements_type==56); md.flowequation.element_equation(pos,end)=2;
968 pos=find(structmd.elements_type==60); md.flowequation.element_equation(pos,end)=3;
969 pos=find(structmd.elements_type==62); md.flowequation.element_equation(pos,end)=4;
970 pos=find(structmd.elements_type==57); md.flowequation.element_equation(pos,end)=5;
971 pos=find(structmd.elements_type==58); md.flowequation.element_equation(pos,end)=6;
972 pos=find(structmd.elements_type==61); md.flowequation.element_equation(pos,end)=7;
973 end
974 if isfield(structmd,'vertices_type') & structmd.vertices_type(end,end)>50,
975 pos=find(structmd.vertices_type==59); md.flowequation.vertex_equation(pos,end)=0;
976 pos=find(structmd.vertices_type==55); md.flowequation.vertex_equation(pos,end)=1;
977 pos=find(structmd.vertices_type==56); md.flowequation.vertex_equation(pos,end)=2;
978 pos=find(structmd.vertices_type==60); md.flowequation.vertex_equation(pos,end)=3;
979 pos=find(structmd.vertices_type==62); md.flowequation.vertex_equation(pos,end)=4;
980 pos=find(structmd.vertices_type==57); md.flowequation.vertex_equation(pos,end)=5;
981 pos=find(structmd.vertices_type==58); md.flowequation.vertex_equation(pos,end)=6;
982 pos=find(structmd.vertices_type==61); md.flowequation.vertex_equation(pos,end)=7;
983 end
984 if isfield(structmd,'rheology_law') & isnumeric(structmd.rheology_law),
985 if (structmd.rheology_law==272), md.materials.rheology_law='None'; end
986 if (structmd.rheology_law==368), md.materials.rheology_law='Paterson'; end
987 if (structmd.rheology_law==369), md.materials.rheology_law='Arrhenius'; end
988 end
989 if isfield(structmd,'groundingline_migration') & isnumeric(structmd.groundingline_migration),
990 if (structmd.groundingline_migration==272), md.groundingline.migration='None'; end
991 if (structmd.groundingline_migration==273), md.groundingline.migration='AggressiveMigration'; end
992 if (structmd.groundingline_migration==274), md.groundingline.migration='SoftMigration'; end
993 end
994 if isfield(structmd,'control_type') & isnumeric(structmd.control_type),
995 if (structmd.control_type==143), md.inversion.control_parameters={'FrictionCoefficient'}; end
996 if (structmd.control_type==190), md.inversion.control_parameters={'RheologyBbar'}; end
997 if (structmd.control_type==147), md.inversion.control_parameters={'Thickeningrate'}; end
998 end
999 if isfield(structmd,'cm_responses') & ismember(structmd.cm_responses(end,end),[165:170 383 388 389]),
1000 pos=find(structmd.cm_responses==166); md.inversion.cost_functions(pos)=101;
1001 pos=find(structmd.cm_responses==167); md.inversion.cost_functions(pos)=102;
1002 pos=find(structmd.cm_responses==168); md.inversion.cost_functions(pos)=103;
1003 pos=find(structmd.cm_responses==169); md.inversion.cost_functions(pos)=104;
1004 pos=find(structmd.cm_responses==170); md.inversion.cost_functions(pos)=105;
1005 pos=find(structmd.cm_responses==165); md.inversion.cost_functions(pos)=201;
1006 pos=find(structmd.cm_responses==389); md.inversion.cost_functions(pos)=501;
1007 pos=find(structmd.cm_responses==388); md.inversion.cost_functions(pos)=502;
1008 pos=find(structmd.cm_responses==382); md.inversion.cost_functions(pos)=503;
1009 end
1010
1011 if isfield(structmd,'artificial_diffusivity') & structmd.artificial_diffusivity==2,
1012 md.thermal.stabilization=2;
1013 md.masstransport.stabilization=1;
1014 md.balancethickness.stabilization=1;
1015 end
1016 if isnumeric(md.masstransport.hydrostatic_adjustment)
1017 if md.masstransport.hydrostatic_adjustment==269,
1018 md.masstransport.hydrostatic_adjustment='Incremental';
1019 else
1020 md.masstransport.hydrostatic_adjustment='Absolute';
1021 end
1022 end
1023
1024 %New fields
1025 if ~isfield(structmd,'upperelements') & isa(md.mesh,'mesh3dprisms')
1026 md.mesh.upperelements=transpose(1:md.mesh.numberofelements)+md.mesh.numberofelements2d;
1027 md.mesh.upperelements(end-md.mesh.numberofelements2d+1:end)=NaN;
1028 end
1029 if ~isfield(structmd,'lowerelements') & isa(md.mesh,'mesh3dprisms')
1030 md.mesh.lowerelements=transpose(1:md.mesh.numberofelements)-md.mesh.numberofelements2d;
1031 md.mesh.lowerelements(1:md.mesh.numberofelements2d)=NaN;
1032 end
1033 if ~isfield(structmd,'diagnostic_ref');
1034 md.stressbalance.referential=NaN*ones(md.mesh.numberofvertices,6);
1035 end
1036 if ~isfield(structmd,'loadingforce');
1037 md.stressbalance.loadingforce=0*ones(md.mesh.numberofvertices,3);
1038 end
1039
1040 %2013 August 9
1041 if isfield(structmd,'prognostic') & isa(structmd.prognostic,'prognostic'),
1042 disp('Recovering old prognostic class');
1043 md.masstransport=masstransport(structmd.prognostic);
1044 end
1045 %2013 August 9
1046 if isfield(structmd,'diagnostic') & (isa(structmd.diagnostic,'diagnostic') || isa(structmd.diagnostic,'stressbalance')),
1047 disp('Recovering old diagnostic class');
1048 md.stressbalance=stressbalance(structmd.diagnostic);
1049 end
1050 %2014 January 9th
1051 if isfield(structmd,'surfaceforcings') & isa(md.smb,'surfaceforcings'),
1052 disp('Recovering old surfaceforcings class');
1053 mass_balance=structmd.surfaceforcings.mass_balance;
1054 md.smb=SMB();
1055 md.smb.mass_balance=mass_balance;
1056 end
1057 %2015 September 10
1058 if isfield(structmd,'surfaceforcings') & isa(structmd.surfaceforcings,'SMB'),
1059 disp('Recovering old SMB class');
1060 md.smb=SMBforcing(structmd.surfaceforcings);
1061 end
1062 if isfield(structmd,'surfaceforcings') & isa(structmd.surfaceforcings,'SMBhenning'),
1063 disp('Recovering old SMBhenning class');
1064 md.smb=SMBhenning(structmd.surfaceforcings);
1065 end
1066
1067 end% }}}
1068 function md = setdefaultparameters(md) % {{{
1069
1070 %initialize subclasses
1071 md.mesh = mesh2d();
1072 md.mask = mask();
1073 md.constants = constants();
1074 md.geometry = geometry();
1075 md.initialization = initialization();
1076 md.smb = SMBforcing();
1077 md.basalforcings = basalforcings();
1078 md.friction = friction();
1079 md.rifts = rifts();
1080 md.slr = slr();
1081 md.timestepping = timestepping();
1082 md.groundingline = groundingline();
1083 md.materials = matice();
1084 md.damage = damage();
1085 md.flowequation = flowequation();
1086 md.debug = debug();
1087 md.verbose = verbose();
1088 md.settings = settings();
1089 md.toolkits = toolkits();
1090 md.cluster = generic();
1091 md.balancethickness = balancethickness();
1092 md.stressbalance = stressbalance();
1093 md.hydrology = hydrologyshreve();
1094 md.masstransport = masstransport();
1095 md.thermal = thermal();
1096 md.steadystate = steadystate();
1097 md.transient = transient();
1098 md.levelset = levelset();
1099 md.calving = calving();
1100 md.gia = gia();
1101 md.esa = esa();
1102 md.autodiff = autodiff();
1103 md.inversion = inversion();
1104 md.qmu = qmu();
1105 md.radaroverlay = radaroverlay();
1106 md.results = struct();
1107 md.outputdefinition = outputdefinition();
1108 md.miscellaneous = miscellaneous();
1109 md.private = private();
1110 end
1111 %}}}
1112 function md = tetras(md,varargin) % {{{
1113 %TETRAS - split 3d prismatic mesh into 3 tetrahedrons
1114 %
1115 % Usage:
1116 % md=tetra(md)
1117
1118 if ~isa(md.mesh,'mesh3dprisms')
1119 error('mesh is not a 3d prismatic mesh');
1120 end
1121
1122 %Initialize tetra mesh
1123 md.mesh=mesh3dtetras(md.mesh);
1124
1125 %Subdivision from Philipp Furnstahl (http://studierstube.icg.tugraz.at/thesis/fuernstahl_thesis.pdf)
1126 steiner = 0;
1127 nbv = md.mesh.numberofvertices;
1128 nbt = 3*md.mesh.numberofelements;
1129 elements = zeros(nbt,4);
1130 for i=1:md.mesh.numberofelements
1131 v1=md.mesh.elements(i,1); v2=md.mesh.elements(i,2); v3=md.mesh.elements(i,3);
1132 v4=md.mesh.elements(i,4); v5=md.mesh.elements(i,5); v6=md.mesh.elements(i,6);
1133 if(min(v2,v4)<min(v1,v5) & min(v1,v6)<min(v3,v4) & min(v3,v5)<min(v2,v6)),
1134 steiner = steiner+1; nbv = nbv+1; nbt = nbt+5; v7 = nbv;
1135 md.mesh.x=[md.mesh.x; mean(md.mesh.x(md.mesh.elements(i,:)))];
1136 md.mesh.y=[md.mesh.y; mean(md.mesh.y(md.mesh.elements(i,:)))];
1137 md.mesh.z=[md.mesh.z; mean(md.mesh.z(md.mesh.elements(i,:)))];
1138 elements(3*(i-1)+1,:) = [v1 v2 v3 v7];
1139 elements(3*(i-1)+2,:) = [v1 v2 v4 v7];
1140 elements(3*(i-1)+3,:) = [v2 v4 v5 v7];
1141 elements(end+1,:) = [v2 v3 v5 v7];
1142 elements(end+1,:) = [v3 v5 v6 v7];
1143 elements(end+1,:) = [v1 v3 v6 v7];
1144 elements(end+1,:) = [v1 v4 v6 v7];
1145 elements(end+1,:) = [v4 v5 v6 v7];
1146 elseif(min(v2,v4)<min(v1,v5) & min(v1,v6)<min(v3,v4) & min(v3,v5)>min(v2,v6)),
1147 elements(3*(i-1)+1,:) = [v1 v2 v4 v6];
1148 elements(3*(i-1)+2,:) = [v2 v4 v5 v6];
1149 elements(3*(i-1)+3,:) = [v1 v2 v3 v6];
1150 elseif(min(v2,v4)<min(v1,v5) & min(v1,v6)>min(v3,v4) & min(v3,v5)<min(v2,v6)),
1151 elements(3*(i-1)+1,:) = [v1 v2 v3 v4];
1152 elements(3*(i-1)+2,:) = [v2 v3 v4 v5];
1153 elements(3*(i-1)+3,:) = [v3 v4 v5 v6];
1154 elseif(min(v2,v4)<min(v1,v5) & min(v1,v6)>min(v3,v4) & min(v3,v5)>min(v2,v6)),
1155 elements(3*(i-1)+1,:) = [v1 v2 v3 v4];
1156 elements(3*(i-1)+2,:) = [v2 v4 v5 v6];
1157 elements(3*(i-1)+3,:) = [v2 v3 v4 v6];
1158 elseif(min(v2,v4)>min(v1,v5) & min(v1,v6)<min(v3,v4) & min(v3,v5)<min(v2,v6)),
1159 elements(3*(i-1)+1,:) = [v1 v4 v5 v6];
1160 elements(3*(i-1)+2,:) = [v1 v2 v3 v5];
1161 elements(3*(i-1)+3,:) = [v1 v3 v5 v6];
1162 elseif(min(v2,v4)>min(v1,v5) & min(v1,v6)<min(v3,v4) & min(v3,v5)>min(v2,v6)),
1163 elements(3*(i-1)+1,:) = [v1 v4 v5 v6];
1164 elements(3*(i-1)+2,:) = [v1 v2 v5 v6];
1165 elements(3*(i-1)+3,:) = [v1 v2 v3 v6];
1166 elseif(min(v2,v4)>min(v1,v5) & min(v1,v6)>min(v3,v4) & min(v3,v5)<min(v2,v6)),
1167 elements(3*(i-1)+1,:) = [v1 v3 v4 v5];
1168 elements(3*(i-1)+2,:) = [v1 v2 v3 v5];
1169 elements(3*(i-1)+3,:) = [v3 v4 v5 v6];
1170 elseif(min(v2,v4)>min(v1,v5) & min(v1,v6)<min(v3,v4) & min(v3,v5)<min(v2,v6)),
1171 elements(3*(i-1)+1,:) = [v1 v5 v6 v4];
1172 elements(3*(i-1)+2,:) = [v1 v2 v3 v5];
1173 elements(3*(i-1)+3,:) = [v5 v6 v3 v1];
1174 elseif(min(v2,v4)>min(v1,v5) & min(v1,v6)>min(v3,v4) & min(v3,v5)>min(v2,v6)),
1175 steiner = steiner+1; nbv = nbv+1; nbt = nbt+5; v7 = nbv;
1176 md.mesh.x=[md.mesh.x; mean(md.mesh.x(md.mesh.elements(i,:)))];
1177 md.mesh.y=[md.mesh.y; mean(md.mesh.y(md.mesh.elements(i,:)))];
1178 md.mesh.z=[md.mesh.z; mean(md.mesh.z(md.mesh.elements(i,:)))];
1179 elements(3*(i-1)+1,:) = [v1 v2 v3 v7];
1180 elements(3*(i-1)+2,:) = [v1 v4 v5 v7];
1181 elements(3*(i-1)+3,:) = [v1 v2 v5 v7];
1182 elements(end+1,:) = [v2 v5 v6 v7];
1183 elements(end+1,:) = [v2 v3 v6 v7];
1184 elements(end+1,:) = [v3 v4 v6 v7];
1185 elements(end+1,:) = [v1 v3 v4 v7];
1186 elements(end+1,:) = [v4 v5 v6 v7];
1187 else
1188 error('Case not supported'); %not supposed to happen!
1189 end
1190 %Reorder elements to make sure they are direct
1191 for j=1:3
1192 element = elements(3*(i-1)+j,:);
1193 matrix = [md.mesh.x(element), md.mesh.y(element), md.mesh.z(element), ones(4,1)];
1194 if det(matrix)>0,
1195 elements(3*(i-1)+j,1)=element(2);
1196 elements(3*(i-1)+j,2)=element(1);
1197 end
1198 end
1199 end
1200 %%Split in 3 tetras
1201 %subelement1 = [1 2 3 5];
1202 %subelement2 = [4 6 5 1];
1203 %subelement3 = [5 6 3 1];
1204 %elements=[md.mesh.elements(:,subelement1);md.mesh.elements(:,subelement2);md.mesh.elements(:,subelement3)];
1205 if steiner==0,
1206 disp('No Steiner point required to split prismatic mesh into tets');
1207 else
1208 disp([num2str(steiner) ' Steiner points had to be included'])
1209 error('Steiner point not supported yet');
1210 end
1211
1212 pos_elements = repmat([1:md.mesh.numberofelements]',3,1);
1213
1214 md.mesh.elements=elements;
1215 md.mesh.numberofelements=size(elements,1);
1216
1217 %p and q (same deal, except for element that are on the bedrock: )
1218 if ~isnan(md.friction.p),
1219 md.friction.p=md.friction.p(pos_elements);
1220 md.friction.q=md.friction.q(pos_elements);
1221 end
1222
1223 %elementstype
1224 if ~isnan(md.flowequation.element_equation)
1225 oldelements_type=md.flowequation.element_equation;
1226 md.flowequation.element_equation=md.flowequation.element_equation(pos_elements);
1227 end
1228
1229 %connectivity
1230 md.mesh.elementconnectivity=NaN;
1231
1232 %materials
1233 if ~isnan(md.materials.rheology_n),
1234 md.materials.rheology_n=md.materials.rheology_n(pos_elements);
1235 end
1236
1237 %increase connectivity if less than 25:
1238 if md.mesh.average_vertex_connectivity<=25,
1239 md.mesh.average_vertex_connectivity=100;
1240 end
1241 end % }}}
1242 function disp(self) % {{{
1243 disp(sprintf('%19s: %-22s -- %s','mesh' ,['[1x1 ' class(self.mesh) ']'],'mesh properties'));
1244 disp(sprintf('%19s: %-22s -- %s','mask' ,['[1x1 ' class(self.mask) ']'],'defines grounded and floating elements'));
1245 disp(sprintf('%19s: %-22s -- %s','geometry' ,['[1x1 ' class(self.geometry) ']'],'surface elevation, bedrock topography, ice thickness,...'));
1246 disp(sprintf('%19s: %-22s -- %s','constants' ,['[1x1 ' class(self.constants) ']'],'physical constants'));
1247 disp(sprintf('%19s: %-22s -- %s','smb' ,['[1x1 ' class(self.smb) ']'],'surface mass balance'));
1248 disp(sprintf('%19s: %-22s -- %s','basalforcings' ,['[1x1 ' class(self.basalforcings) ']'],'bed forcings'));
1249 disp(sprintf('%19s: %-22s -- %s','materials' ,['[1x1 ' class(self.materials) ']'],'material properties'));
1250 disp(sprintf('%19s: %-22s -- %s','damage' ,['[1x1 ' class(self.damage) ']'],'parameters for damage evolution solution'));
1251 disp(sprintf('%19s: %-22s -- %s','friction' ,['[1x1 ' class(self.friction) ']'],'basal friction/drag properties'));
1252 disp(sprintf('%19s: %-22s -- %s','flowequation' ,['[1x1 ' class(self.flowequation) ']'],'flow equations'));
1253 disp(sprintf('%19s: %-22s -- %s','timestepping' ,['[1x1 ' class(self.timestepping) ']'],'time stepping for transient models'));
1254 disp(sprintf('%19s: %-22s -- %s','initialization' ,['[1x1 ' class(self.initialization) ']'],'initial guess/state'));
1255 disp(sprintf('%19s: %-22s -- %s','rifts' ,['[1x1 ' class(self.rifts) ']'],'rifts properties'));
1256 disp(sprintf('%19s: %-22s -- %s','slr' ,['[1x1 ' class(self.slr) ']'],'slr forcings'));
1257 disp(sprintf('%19s: %-22s -- %s','debug' ,['[1x1 ' class(self.debug) ']'],'debugging tools (valgrind, gprof)'));
1258 disp(sprintf('%19s: %-22s -- %s','verbose' ,['[1x1 ' class(self.verbose) ']'],'verbosity level in solve'));
1259 disp(sprintf('%19s: %-22s -- %s','settings' ,['[1x1 ' class(self.settings) ']'],'settings properties'));
1260 disp(sprintf('%19s: %-22s -- %s','toolkits' ,['[1x1 ' class(self.toolkits) ']'],'PETSc options for each solution'));
1261 disp(sprintf('%19s: %-22s -- %s','cluster' ,['[1x1 ' class(self.cluster) ']'],'cluster parameters (number of cpus...)'));
1262 disp(sprintf('%19s: %-22s -- %s','balancethickness',['[1x1 ' class(self.balancethickness) ']'],'parameters for balancethickness solution'));
1263 disp(sprintf('%19s: %-22s -- %s','stressbalance' ,['[1x1 ' class(self.stressbalance) ']'],'parameters for stressbalance solution'));
1264 disp(sprintf('%19s: %-22s -- %s','groundingline' ,['[1x1 ' class(self.groundingline) ']'],'parameters for groundingline solution'));
1265 disp(sprintf('%19s: %-22s -- %s','hydrology' ,['[1x1 ' class(self.hydrology) ']'],'parameters for hydrology solution'));
1266 disp(sprintf('%19s: %-22s -- %s','masstransport' ,['[1x1 ' class(self.masstransport) ']'],'parameters for masstransport solution'));
1267 disp(sprintf('%19s: %-22s -- %s','thermal' ,['[1x1 ' class(self.thermal) ']'],'parameters for thermal solution'));
1268 disp(sprintf('%19s: %-22s -- %s','steadystate' ,['[1x1 ' class(self.steadystate) ']'],'parameters for steadystate solution'));
1269 disp(sprintf('%19s: %-22s -- %s','transient' ,['[1x1 ' class(self.transient) ']'],'parameters for transient solution'));
1270 disp(sprintf('%19s: %-22s -- %s','levelset' ,['[1x1 ' class(self.levelset) ']'],'parameters for moving boundaries (level-set method)'));
1271 disp(sprintf('%19s: %-22s -- %s','calving' ,['[1x1 ' class(self.calving) ']'],'parameters for calving'));
1272 disp(sprintf('%19s: %-22s -- %s','gia' ,['[1x1 ' class(self.gia) ']'],'parameters for gia solution'));
1273 disp(sprintf('%19s: %-22s -- %s','esa' ,['[1x1 ' class(self.esa) ']'],'parameters for elastic adjustment solution'));
1274 disp(sprintf('%19s: %-22s -- %s','autodiff' ,['[1x1 ' class(self.autodiff) ']'],'automatic differentiation parameters'));
1275 disp(sprintf('%19s: %-22s -- %s','inversion' ,['[1x1 ' class(self.inversion) ']'],'parameters for inverse methods'));
1276 disp(sprintf('%19s: %-22s -- %s','qmu' ,['[1x1 ' class(self.qmu) ']'],'dakota properties'));
1277 disp(sprintf('%19s: %-22s -- %s','outputdefinition',['[1x1 ' class(self.outputdefinition) ']'],'output definition'));
1278 disp(sprintf('%19s: %-22s -- %s','results' ,['[1x1 ' class(self.results) ']'],'model results'));
1279 disp(sprintf('%19s: %-22s -- %s','radaroverlay' ,['[1x1 ' class(self.radaroverlay) ']'],'radar image for plot overlay'));
1280 disp(sprintf('%19s: %-22s -- %s','miscellaneous' ,['[1x1 ' class(self.miscellaneous) ']'],'miscellaneous fields'));
1281 end % }}}
1282 function memory(self) % {{{
1283
1284 disp(sprintf('\nMemory imprint:\n'));
1285
1286 fields=properties('model');
1287 mem=0;
1288
1289 for i=1:length(fields),
1290 field=self.(fields{i});
1291 s=whos('field');
1292 mem=mem+s.bytes/1e6;
1293 disp(sprintf('%19s: %6.2f Mb',fields{i},s.bytes/1e6));
1294 end
1295 disp(sprintf('%19s--%10s','--------------','--------------'));
1296 disp(sprintf('%19s: %g Mb','Total',mem));
1297 end % }}}
1298 function netcdf(self,filename) % {{{
1299 %NETCDF - save model as netcdf
1300 %
1301 % Usage:
1302 % netcdf(md,filename)
1303 %
1304 % Example:
1305 % netcdf(md,'model.nc');
1306
1307 disp('Saving model as NetCDF');
1308 %1. Create NetCDF file
1309 ncid=netcdf.create(filename,'CLOBBER');
1310 netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Conventions','CF-1.4');
1311 netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Title',['ISSM model (' self.miscellaneous.name ')']);
1312 netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Author',getenv('USER'));
1313 netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Date',datestr(now));
1314
1315 %Preallocate variable id, needed to write variables in netcdf file
1316 var_id=zeros(1000,1);%preallocate
1317
1318 for step=1:2,
1319 counter=0;
1320 [var_id,counter]=structtonc(ncid,'md',self,0,var_id,counter,step);
1321 if step==1, netcdf.endDef(ncid); end
1322 end
1323
1324 if counter>1000,
1325 warning(['preallocation of var_id need to be updated from ' num2str(1000) ' to ' num2str(counter)]);
1326 end
1327
1328 netcdf.close(ncid)
1329 end % }}}
1330 function xylim(self) % {{{
1331
1332 xlim([min(self.mesh.x) max(self.mesh.x)]);
1333 ylim([min(self.mesh.y) max(self.mesh.y)])
1334 end % }}}
1335 function md=upload(md) % {{{
1336 %the goal of this routine is to upload the model onto a server, and to empty it.
1337 %So first, save the model with a unique name and upload the file to the server:
1338 random_part=fix(rand(1)*10000);
1339 id=[md.miscellaneous.name '-' regexprep(datestr(now),'[^\w'']','') '-' num2str(random_part) '-' getenv('USER') '-' oshostname() '.upload'];
1340 eval(['save ' id ' md']);
1341
1342 %Now, upload the file:
1343 issmscpout(md.settings.upload_server,md.settings.upload_path,md.settings.upload_login,md.settings.upload_port,{id},1);
1344
1345 %Now, empty this model of everything except settings, and record name of file we just uploaded!
1346 settings_back=md.settings;
1347 md=model();
1348 md.settings=settings_back;
1349 md.settings.upload_filename=id;
1350
1351 %get locally rid of file that was uploaded
1352 eval(['delete ' id]);
1353
1354 end % }}}
1355 function md=download(md) % {{{
1356
1357 %the goal of this routine is to download the internals of the current model from a server, because
1358 %this model is empty, except for the settings which tell us where to go and find this model!
1359
1360 %Download the file:
1361 issmscpin(md.settings.upload_server, md.settings.upload_login, md.settings.upload_port, md.settings.upload_path, {md.settings.upload_filename});
1362
1363 name=md.settings.upload_filename;
1364
1365 %Now, load this model:
1366 md=loadmodel(md.settings.upload_filename);
1367
1368 %get locally rid of file that was downloaded
1369 eval(['delete ' name]);
1370
1371 end % }}}
1372 function savemodeljs(md,modelname,websiteroot) % {{{
1373
1374 %the goal of this routine is to save the model as a javascript array that can be included in any html
1375 %file:
1376
1377 %disp:
1378 disp(['saving model ''' modelname ''' in file ' websiteroot '/js/' modelname '.js']);
1379
1380 %open file for writing and declare the model:
1381 fid=fopen([websiteroot '/js/' modelname '.js'],'w');
1382 fprintf(fid,'var %s=new model();\n',modelname);
1383
1384 %now go through all the classes and fwrite all the corresponding fields:
1385
1386 fields=properties('model');
1387 for i=1:length(fields),
1388 field=fields{i};
1389
1390 %Some properties do not need to be saved
1391 if ismember(field,{'results','cluster' }),
1392 continue;
1393 end
1394
1395 %Check that current field is an object
1396 if ~isobject(md.(field))
1397 error(['field ''' char(field) ''' is not an object']);
1398 end
1399
1400 %savemodeljs for current object
1401 %disp(['javascript saving ' field '...']);
1402 savemodeljs(md.(field),fid,modelname);
1403 end
1404
1405 %done, close file:
1406 fclose(fid);
1407 end
1408 end
1409 end
Note: See TracBrowser for help on using the repository browser.