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