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

Last change on this file since 17940 was 17940, checked in by cborstad, 11 years ago

BUG: only depth-average damage if damgae is being used

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