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