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