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