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

Last change on this file since 19642 was 19642, checked in by schlegel, 9 years ago

CHG: update lonestar time plus SMBforcing conversions

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