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