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

Last change on this file since 24511 was 24511, checked in by Mathieu Morlighem, 5 years ago

CHG: added check before extrude, model needs to have geometry set

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