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

Last change on this file since 27323 was 27323, checked in by rueckamp, 2 years ago

CHG: some minor fixes for debris stuff

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