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