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

Last change on this file since 23758 was 23758, checked in by schlegel, 6 years ago

CHG: change results on nodes to be a list of strings instead of a bool

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