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

Last change on this file since 18961 was 18961, checked in by jbondzio, 10 years ago

ADD: extrude calving.meltingrate

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