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