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

Last change on this file since 26161 was 26161, checked in by Mathieu Morlighem, 4 years ago

CHG: added super cool function to refine 4x a mesh automatically

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