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

Last change on this file since 23652 was 23652, checked in by youngmc3, 6 years ago

NEW: add new class md.frontalforcings

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