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

Last change on this file since 18519 was 18519, checked in by Mathieu Morlighem, 11 years ago

CHG: fixing error message while loading models

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