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

Last change on this file since 21702 was 21702, checked in by Mathieu Morlighem, 8 years ago

CHG: fixed amr for old models

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