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

Last change on this file since 22194 was 22194, checked in by Mathieu Morlighem, 7 years ago

CHG: added backward compatibility check

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