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

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

CHG: new reorganization of the slr capabilities.

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