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

Last change on this file since 18757 was 18757, checked in by srebuffi, 10 years ago

CHG: added calving class

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