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

Last change on this file since 25996 was 25996, checked in by bulthuis, 4 years ago

NEW: add new class sampling to model for stochastic sampling capability

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