Changeset 25499
- Timestamp:
- 08/31/20 14:54:17 (5 years ago)
- Location:
- issm/trunk-jpl
- Files:
-
- 3 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/friction.m
r25403 r25499 79 79 end % }}} 80 80 function marshall(self,prefix,md,fid) % {{{ 81 yts=md.constants.yts;82 83 81 WriteData(fid,prefix,'name','md.friction.law','data',1,'format','Integer'); 84 82 if(size(self.coefficient,1)==md.mesh.numberofvertices | size(self.coefficient,1)==md.mesh.numberofvertices+1), 85 mattype=1; tsl = md.mesh.numberofvertices; 83 mattype=1; 84 tsl = md.mesh.numberofvertices; 86 85 else 87 mattype=2; tsl = md.mesh.numberofelements; 86 mattype=2; 87 tsl = md.mesh.numberofelements; 88 88 end 89 89 WriteData(fid,prefix,'object',self,'fieldname','coefficient','format','DoubleMat','mattype',mattype,'timeserieslength',tsl+1,'yts',md.constants.yts); -
issm/trunk-jpl/src/m/classes/friction.py
r25161 r25499 1 import numpy as np 2 1 3 from checkfield import checkfield 2 4 from fielddisplay import fielddisplay … … 6 8 7 9 class friction(object): 8 ''' 9 FRICTION class definition 10 """FRICTION class definition 10 11 11 12 13 '''12 Usage: 13 friction = friction() 14 """ 14 15 15 16 def __init__(self): # {{{ 16 self.coefficient = float('NaN')17 self.p = float('NaN')18 self.q = float('NaN')17 self.coefficient = np.nan 18 self.p = np.nan 19 self.q = np.nan 19 20 self.coupling = 0 20 self.effective_pressure = float('NaN')21 self.effective_pressure = np.nan 21 22 self.effective_pressure_limit = 0 23 22 24 #set defaults 23 25 self.setdefaultparameters() 24 #self.requested_outputs = []25 26 #}}} 26 27 27 28 def __repr__(self): # {{{ 28 string = "Basal shear stress parameters: Sigma_b = coefficient^2 * Neff ^r * |u_b|^(s - 1) * u_b, \n(effective stress Neff = rho_ice * g * thickness + rho_water * g * base, r = q / p and s = 1 / p)" 29 s = "Basal shear stress parameters: Sigma_b = coefficient^2 * Neff ^r * |u_b|^(s - 1) * u_b, \n(effective stress Neff = rho_ice * g * thickness + rho_water * g * base, r = q / p and s = 1 / p)\n" 30 s = "{}\n".format(fielddisplay(self, "coefficient", "friction coefficient [SI]")) 31 s = "{}\n".format(fielddisplay(self, "p", "p exponent")) 32 s = "{}\n".format(fielddisplay(self, "q", "q exponent")) 33 s = "{}\n".format(fielddisplay(self, 'coupling', 'Coupling flag 0: uniform sheet (negative pressure ok, default), 1: ice pressure only, 2: water pressure assuming uniform sheet (no negative pressure), 3: use provided effective_pressure, 4: used coupled model (not implemented yet)')) 34 s = "{}\n".format(fielddisplay(self, 'effective_pressure', 'Effective Pressure for the forcing if not coupled [Pa]')) 35 s = "{}\n".format(fielddisplay(self, 'effective_pressure_limit', 'Neff do not allow to fall below a certain limit: effective_pressure_limit * rho_ice * g * thickness (default 0)')) 36 37 return s 38 #}}} 29 39 30 string = "%s\n%s" % (string, fielddisplay(self, "coefficient", "friction coefficient [SI]")) 31 string = "%s\n%s" % (string, fielddisplay(self, "p", "p exponent")) 32 string = "%s\n%s" % (string, fielddisplay(self, "q", "q exponent")) 33 string = "%s\n%s" % (string, fielddisplay(self, 'coupling', 'Coupling flag 0: uniform sheet (negative pressure ok, default), 1: ice pressure only, 2: water pressure assuming uniform sheet (no negative pressure), 3: use provided effective_pressure, 4: used coupled model (not implemented yet)')) 34 string = "%s\n%s" % (string, fielddisplay(self, 'effective_pressure', 'Effective Pressure for the forcing if not coupled [Pa]')) 35 string = "%s\n%s" % (string, fielddisplay(self, 'effective_pressure_limit', 'Neff do not allow to fall below a certain limit: effective_pressure_limit * rho_ice * g * thickness (default 0)')) 36 #string = "%s\n%s" % (string, fielddisplay(self, 'requested_outputs', 'additional outputs requested')) 37 return string 40 def setdefaultparameters(self): # {{{ 41 self.effective_pressure_limit = 0 42 43 return self 38 44 #}}} 39 45 … … 50 56 #}}} 51 57 52 def setdefaultparameters(self): # {{{53 #self.requested_outputs = ['default']54 self.effective_pressure_limit = 055 return self56 #}}}57 58 58 def defaultoutputs(self, md): # {{{ 59 59 list = [] … … 64 64 #Early return 65 65 if 'StressbalanceAnalysis' not in analyses and 'ThermalAnalysis' not in analyses: 66 return md 67 if solution == 'TransientSoluition' and not md.transient.isstressbalance and not md.transient.isthermal: 66 68 return md 67 69 … … 74 76 md = checkfield(md, 'fieldname', 'friction.effective_pressure', 'NaN', 1, 'Inf', 1, 'timeseries', 1) 75 77 elif self.coupling > 4: 76 raise ValueError(' md.friction.coupling larger than 4,not supported yet')77 #md = checkfield(md, 'fieldname', 'friction.requested_outputs', 'stringrow', 1) 78 raise ValueError('not supported yet') 79 78 80 return md 79 81 # }}} … … 81 83 def marshall(self, prefix, md, fid): # {{{ 82 84 WriteData(fid, prefix, 'name', 'md.friction.law', 'data', 1, 'format', 'Integer') 83 WriteData(fid, prefix, 'object', self, 'fieldname', 'coefficient', 'format', 'DoubleMat', 'mattype', 1) 85 86 if type(self.coefficient) in [np.ndarray] and (self.coefficient.shape[0] == md.mesh.numberofvertices or self.coefficient.shape[0] == (md.mesh.numberofvertices + 1)): 87 mattype = 1 88 tsl = md.mesh.numberofvertices 89 else: 90 mattype = 2 91 tsl = md.mesh.numberofelements 92 93 WriteData(fid, prefix, 'object', self, 'fieldname', 'coefficient', 'format', 'DoubleMat', 'mattype', mattype, 'timeserieslength', tsl + 1, 'yts', md.constants.yts) 84 94 WriteData(fid, prefix, 'object', self, 'fieldname', 'p', 'format', 'DoubleMat', 'mattype', 2) 85 95 WriteData(fid, prefix, 'object', self, 'fieldname', 'q', 'format', 'DoubleMat', 'mattype', 2) … … 88 98 if self.coupling == 3: 89 99 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'effective_pressure', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', md.constants.yts) 90 if self.coupling == 4:91 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'effective_pressure', 'format', 'DoubleMat', 'mattype', 1 )100 elif self.coupling == 4: 101 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'effective_pressure', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', md.constants.yts) 92 102 elif self.coupling > 4: 93 raise ValueError('md.friction.coupling larger than 4, not supported yet') 94 95 # #process requested outputs 96 # outputs = self.requested_outputs 97 # indices = [i for i, x in enumerate(outputs) if x == 'default'] 98 # if len(indices) > 0: 99 # outputscopy = outputs[0:max(0, indices[0] - 1)] + self.defaultoutputs(md) + outputs[indices[0] + 1:] 100 # outputs = outputscopy 101 # WriteData(fid, prefix, 'data', outputs, 'name', 'md.friction.requested_outputs', 'format', 'StringArray') 103 raise ValueError('not supported yet') 102 104 # }}} -
issm/trunk-jpl/src/m/classes/frictioncoulomb.py
r24670 r25499 1 import numpy as np 2 3 from checkfield import checkfield 1 4 from fielddisplay import fielddisplay 2 5 from project3d import project3d 3 from checkfield import checkfield4 6 from WriteData import WriteData 5 7 6 8 7 9 class frictioncoulomb(object): 8 """ 9 FRICTIONCOULOMB class definition 10 """FRICTIONCOULOMB class definition 10 11 11 12 Usage: 12 frictioncoulomb = frictioncoulomb()13 frictioncoulomb = frictioncoulomb() 13 14 """ 14 15 15 16 def __init__(self): # {{{ 16 self.coefficient = float('NaN')17 self.coefficientcoulomb = float('NaN')18 self.p = float('NaN')19 self.q = float('NaN')17 self.coefficient = np.nan 18 self.coefficientcoulomb = np.nan 19 self.p = np.nan 20 self.q = np.nan 20 21 self.coupling = 0 21 self.effective_pressure = float('NaN')22 self.effective_pressure = np.nan 22 23 self.effective_pressure_limit = 0 23 #set defaults 24 25 #set defaults 24 26 self.setdefaultparameters() 25 27 #}}} 26 28 27 29 def __repr__(self): # {{{ 28 string = "Basal shear stress parameters: Sigma_b = min(coefficient^2 * Neff ^r * |u_b|^(s - 1) * u_b, \n coefficientcoulomb^2 * rho_i * g * (h - h_f)), (effective stress Neff = rho_ice * g * thickness + rho_water * g * bed, r = q / p and s = 1 / p)." 29 string = "%s\n%s" % (string, fielddisplay(self, "coefficient", "power law (Weertman) friction coefficient [SI]")) 30 string = "%s\n%s" % (string, fielddisplay(self, "coefficientcoulomb", "Coulomb friction coefficient [SI]")) 31 string = "%s\n%s" % (string, fielddisplay(self, "p", "p exponent")) 32 string = "%s\n%s" % (string, fielddisplay(self, "q", "q exponent")) 33 string = "%s\n%s" % (string, fielddisplay(self, 'coupling', 'Coupling flag: 0 for default, 1 for forcing(provide md.friction.effective_pressure) and 2 for coupled(not implemented yet)')) 34 string = "%s\n%s" % (string, fielddisplay(self, 'effective_pressure', 'Effective Pressure for the forcing if not coupled [Pa]')) 35 string = "%s\n%s" % (string, fielddisplay(self, 'effective_pressure_limit', 'Neff do not allow to fall below a certain limit: effective_pressure_limit * rho_ice * g * thickness (default 0)')) 36 return string 30 s = "Basal shear stress parameters: Sigma_b = min(coefficient^2 * Neff ^r * |u_b|^(s - 1) * u_b, \n coefficientcoulomb^2 * rho_i * g * (h - h_f)), (effective stress Neff = rho_ice * g * thickness + rho_water * g * bed, r = q / p and s = 1 / p).\n" 31 s = "{}\n".format(fielddisplay(self, "coefficient", "power law (Weertman) friction coefficient [SI]")) 32 s = "{}\n".format(fielddisplay(self, "coefficientcoulomb", "Coulomb friction coefficient [SI]")) 33 s = "{}\n".format(fielddisplay(self, "p", "p exponent")) 34 s = "{}\n".format(fielddisplay(self, "q", "q exponent")) 35 s = "{}\n".format(fielddisplay(self, 'coupling', 'Coupling flag: 0 for default, 1 for forcing(provide md.friction.effective_pressure) and 2 for coupled(not implemented yet)')) 36 s = "{}\n".format(fielddisplay(self, 'effective_pressure', 'Effective Pressure for the forcing if not coupled [Pa]')) 37 s = "{}\n".format(fielddisplay(self, 'effective_pressure_limit', 'Neff do not allow to fall below a certain limit: effective_pressure_limit * rho_ice * g * thickness (default 0)')) 38 39 return s 40 #}}} 41 42 def setdefaultparameters(self): # {{{ 43 self.effective_pressure_limit = 0 44 45 return self 37 46 #}}} 38 47 … … 45 54 self.effective_pressure = project3d(md, 'vector', self.effective_pressure, 'type', 'node', 'layer', 1) 46 55 elif self.coupling == 2: 47 raise ValueError(' coupling not supported yet')56 raise ValueError('not implemented yet') 48 57 elif self.coupling > 2: 49 raise ValueError('md.friction.coupling larger than 2, not supported yet') 58 raise ValueError('not supported yet') 59 50 60 return self 51 61 #}}} 52 53 def setdefaultparameters(self): # {{{54 self.effective_pressure_limit = 055 return self56 #}}}57 58 62 def checkconsistency(self, md, solution, analyses): # {{{ 59 63 #Early return … … 65 69 md = checkfield(md, 'fieldname', 'friction.q', 'NaN', 1, 'Inf', 1, 'size', [md.mesh.numberofelements]) 66 70 md = checkfield(md, 'fieldname', 'friction.p', 'NaN', 1, 'Inf', 1, 'size', [md.mesh.numberofelements]) 71 md = checkfield(md, 'fieldname', 'friction.coupling', 'numel', [1], 'values', [0, 1, 2]) 67 72 md = checkfield(md, 'fieldname', 'friction.effective_pressure_limit', 'numel', [1], '>=', 0) 68 73 if self.coupling == 1: 69 74 md = checkfield(md, 'fieldname', 'friction.effective_pressure', 'NaN', 1, 'Inf', 1, 'timeseries', 1) 70 75 elif self.coupling == 2: 71 raise ValueError(' coupling not supported yet')76 raise ValueError('not implemented yet') 72 77 elif self.coupling > 2: 73 raise ValueError('md.friction.coupling larger than 2, not supported yet') 78 raise ValueError('not supported yet') 79 74 80 return md 75 81 # }}} … … 86 92 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'effective_pressure', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', md.constants.yts) 87 93 elif self.coupling == 2: 88 raise ValueError(' coupling not supported yet')94 raise ValueError('not implemented yet') 89 95 elif self.coupling > 2: 90 raise ValueError(' md.friction.coupling larger than 2,not supported yet')96 raise ValueError('not supported yet') 91 97 # }}} -
issm/trunk-jpl/src/m/classes/frictionshakti.m
r23020 r25499 36 36 end % }}} 37 37 function marshall(self,prefix,md,fid) % {{{ 38 yts=md.constants.yts;39 40 38 WriteData(fid,prefix,'name','md.friction.law','data',8,'format','Integer'); 41 39 WriteData(fid,prefix,'class','friction','object',self,'fieldname','coefficient','format','DoubleMat','mattype',1,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts); -
issm/trunk-jpl/src/m/classes/frictionshakti.py
r24213 r25499 1 import numpy as np 2 3 from checkfield import checkfield 1 4 from fielddisplay import fielddisplay 2 5 from project3d import project3d 3 from checkfield import checkfield4 6 from WriteData import WriteData 5 7 6 8 7 9 class frictionshakti(object): 8 """ 9 FRICTIONSHAKTI class definition 10 """FRICTIONSHAKTI class definition 10 11 11 12 Usage: 12 friction = frictionshakti()13 friction = frictionshakti() 13 14 """ 14 15 15 16 def __init__(self, md): # {{{ 16 self.coefficient = md.friction.coefficient17 #set defaults17 self.coefficient = np.nan 18 #set defaults 18 19 self.setdefaultparameters() 19 20 #}}} 20 21 21 22 def __repr__(self): # {{{ 22 string = "Basal shear stress parameters: Sigma_b = coefficient^2 * Neff * u_b\n(effective stress Neff = rho_ice * g * thickness + rho_water * g * (head - b))" 23 string = "%s\n%s" % (string, fielddisplay(self, "coefficient", "friction coefficient [SI]")) 24 return string 23 s = "Basal shear stress parameters: Sigma_b = coefficient^2 * Neff * u_b\n(effective stress Neff = rho_ice * g * thickness + rho_water * g * (head - b))\n" 24 s += "{}\n".format(fielddisplay(self, "coefficient", "friction coefficient [SI]")) 25 26 return s 27 #}}} 28 29 def setdefaultparameters(self): # {{{ 30 return self 25 31 #}}} 26 32 … … 30 36 #}}} 31 37 32 def setdefaultparameters(self): # {{{33 return self34 #}}}35 36 38 def checkconsistency(self, md, solution, analyses): # {{{ 37 # Early return39 # Early return 38 40 if 'StressbalanceAnalysis' not in analyses and 'ThermalAnalysis' not in analyses: 39 41 return md -
issm/trunk-jpl/src/m/classes/frictionwaterlayer.py
r24213 r25499 1 import numpy as np 2 3 from checkfield import checkfield 4 from fielddisplay import fielddisplay 1 5 from project3d import project3d 2 from fielddisplay import fielddisplay3 from checkfield import checkfield4 6 from WriteData import WriteData 5 7 6 8 7 9 class frictionwaterlayer(object): 8 """ 9 frictionwaterlayer class definition 10 """FRICTIONWATERLAYER class definition 10 11 11 12 Usage: 12 13 friction = frictionwaterlayer(md) 13 14 """ 15 14 16 def __init__(self, md): # {{{ 15 self.coefficient = md.friction.coefficient 16 self.f = float('NaN') 17 self.p = md.friction.p 18 self.q = md.friction.q 19 self.water_layer = float('NaN') 17 self.coefficient = np.nan 18 self.f = np.nan 19 self.p = np.nan 20 self.q = np.nan 21 self.water_layer = np.nan 22 #}}} 23 24 def __repr__(self): # {{{ 25 s = 'Basal shear stress parameters: tau_b = coefficient^2 * Neff ^r * |u_b|^(s - 1) * u_b * 1 / f(T)\n(effective stress Neff = rho_ice * g * thickness + rho_water * g * (bed + water_layer), r = q / p and s = 1 / p)\n' 26 s = "{}\n".format(fielddisplay(self, 'coefficient', 'frictiontemp coefficient [SI]')) 27 s = "{}\n".format(fielddisplay(self, 'f', 'f variable for effective pressure')) 28 s = "{}\n".format(fielddisplay(self, 'p', 'p exponent')) 29 s = "{}\n".format(fielddisplay(self, 'q', 'q exponent')) 30 s = "{}\n".format(fielddisplay(self, 'water_layer', 'water thickness at the base of the ice (m)')) 31 32 return s 33 #}}} 34 35 def setdefaultparameters(self): # {{{ 36 return self 20 37 #}}} 21 38 … … 37 54 self.q = project3d(md, 'vector', self.q, 'type', 'element') 38 55 self.water_layer = project3d(md, 'vector', self.water_layer, 'type', 'node', 'layer', 1) 56 39 57 return self 40 58 # }}} 41 59 42 def __repr__(self): # {{{43 string = 'Basal shear stress parameters: tau_b = coefficient^2 * Neff ^r * |u_b|^(s - 1) * u_b * 1 / f(T)\n(effective stress Neff = rho_ice * g * thickness + rho_water * g * (bed + water_layer), r = q / p and s = 1 / p)'44 string = "%s\n%s" % (string, fielddisplay(self, 'coefficient', 'frictiontemp coefficient [SI]'))45 string = "%s\n%s" % (string, fielddisplay(self, 'f', 'f variable for effective pressure'))46 string = "%s\n%s" % (string, fielddisplay(self, 'p', 'p exponent'))47 string = "%s\n%s" % (string, fielddisplay(self, 'q', 'q exponent'))48 string = "%s\n%s" % (string, fielddisplay(self, 'water_layer', 'water thickness at the base of the ice (m)'))49 50 return string51 #}}}52 53 60 def marshall(self, prefix, md, fid): #{{{ 54 yts = md.constants.yts55 61 WriteData(fid, prefix, 'name', 'md.friction.law', 'data', 5, 'format', 'Integer') 56 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'coefficient', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)62 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'coefficient', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', md.constants.yts) 57 63 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'f', 'format', 'Double') 58 64 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'p', 'format', 'DoubleMat', 'mattype', 2) 59 65 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'q', 'format', 'DoubleMat', 'mattype', 2) 60 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'water_layer', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)66 WriteData(fid, prefix, 'class', 'friction', 'object', self, 'fieldname', 'water_layer', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', md.constants.yts) 61 67 #}}} -
issm/trunk-jpl/src/m/classes/mesh3dsurface.py
r25455 r25499 207 207 208 208 #first line: 209 contour 210 contour.x 211 contour.y 212 contour.Geometry 213 contours[count] 209 contour = OrderedStruct() 210 contour.x = [self.long[el[0]], self.long[el[1]]] 211 contour.y = [self.lat[el[0]], self.lat[el[1]]] 212 contour.Geometry = 'Line' 213 contours[count] = contour 214 214 215 215 #second line: 216 contour 217 contour.x 218 contour.y 219 contour.Geometry 220 contours[count + 1] 216 contour = OrderedStruct() 217 contour.x = [self.long[el[1]], self.long[el[2]]] 218 contour.y = [self.lat[el[1]], self.lat[el[2]]] 219 contour.Geometry = 'Line' 220 contours[count + 1] = contour 221 221 222 222 #second line: 223 contour 224 contour.x 225 contour.y 226 contour.Geometry 227 contours[count + 2] 223 contour = OrderedStruct() 224 contour.x = [self.long[el[2]], self.long[el[0]]] 225 contour.y = [self.lat[el[2]], self.lat[el[0]]] 226 contour.Geometry = 'Line' 227 contours[count + 2] = contour 228 228 229 229 #increase count: -
issm/trunk-jpl/src/m/classes/model.m
r25172 r25499 214 214 % 215 215 % This routine collapses a 3d model into a 2d model 216 % and collapses all the fi leds of the 3d model by216 % and collapses all the fields of the 3d model by 217 217 % taking their depth-averaged values 218 218 % … … 261 261 262 262 %observations 263 if ~isnan(md.inversion.vx_obs), md.inversion.vx_obs=project2d(md,md.inversion.vx_obs,md.mesh.numberoflayers); end; 264 if ~isnan(md.inversion.vy_obs), md.inversion.vy_obs=project2d(md,md.inversion.vy_obs,md.mesh.numberoflayers); end; 265 if ~isnan(md.inversion.vel_obs), md.inversion.vel_obs=project2d(md,md.inversion.vel_obs,md.mesh.numberoflayers); end; 266 if ~isnan(md.inversion.thickness_obs), md.inversion.thickness_obs=project2d(md,md.inversion.thickness_obs,md.mesh.numberoflayers); end; 267 if ~isnan(md.inversion.cost_functions_coefficients), md.inversion.cost_functions_coefficients=project2d(md,md.inversion.cost_functions_coefficients,md.mesh.numberoflayers); end; 268 if numel(md.inversion.min_parameters)>1, md.inversion.min_parameters=project2d(md,md.inversion.min_parameters,md.mesh.numberoflayers); end; 269 if numel(md.inversion.max_parameters)>1, md.inversion.max_parameters=project2d(md,md.inversion.max_parameters,md.mesh.numberoflayers); end; 263 if ~isnan(md.inversion.vx_obs), 264 md.inversion.vx_obs=project2d(md,md.inversion.vx_obs,md.mesh.numberoflayers); 265 end 266 if ~isnan(md.inversion.vy_obs), 267 md.inversion.vy_obs=project2d(md,md.inversion.vy_obs,md.mesh.numberoflayers); 268 end 269 if ~isnan(md.inversion.vel_obs), 270 md.inversion.vel_obs=project2d(md,md.inversion.vel_obs,md.mesh.numberoflayers); 271 end 272 if ~isnan(md.inversion.thickness_obs), 273 md.inversion.thickness_obs=project2d(md,md.inversion.thickness_obs,md.mesh.numberoflayers); 274 end 275 if ~isnan(md.inversion.cost_functions_coefficients), 276 md.inversion.cost_functions_coefficients=project2d(md,md.inversion.cost_functions_coefficients,md.mesh.numberoflayers); 277 end 278 if numel(md.inversion.min_parameters)>1, 279 md.inversion.min_parameters=project2d(md,md.inversion.min_parameters,md.mesh.numberoflayers); 280 end 281 if numel(md.inversion.max_parameters)>1, 282 md.inversion.max_parameters=project2d(md,md.inversion.max_parameters,md.mesh.numberoflayers); 283 end 270 284 if isa(md.smb,'SMBforcing') & ~isnan(md.smb.mass_balance), 271 285 md.smb.mass_balance=project2d(md,md.smb.mass_balance,md.mesh.numberoflayers); 272 286 elseif isa(md.smb,'SMBhenning') & ~isnan(md.smb.smbref), 273 287 md.smb.smbref=project2d(md,md.smb.smbref,md.mesh.numberoflayers); 274 end ;288 end 275 289 276 290 %results 277 if ~isnan(md.initialization.vx),md.initialization.vx=DepthAverage(md,md.initialization.vx);end; 278 if ~isnan(md.initialization.vy),md.initialization.vy=DepthAverage(md,md.initialization.vy);end; 279 if ~isnan(md.initialization.vz),md.initialization.vz=DepthAverage(md,md.initialization.vz);end; 280 if ~isnan(md.initialization.vel),md.initialization.vel=DepthAverage(md,md.initialization.vel);end; 281 if ~isnan(md.initialization.temperature),md.initialization.temperature=DepthAverage(md,md.initialization.temperature);end; 282 if ~isnan(md.initialization.pressure),md.initialization.pressure=project2d(md,md.initialization.pressure,1);end; 283 if ~isnan(md.initialization.sediment_head),md.initialization.sediment_head=project2d(md,md.initialization.sediment_head,1);end; 284 if ~isnan(md.initialization.epl_head),md.initialization.epl_head=project2d(md,md.initialization.epl_head,1);end; 285 if ~isnan(md.initialization.epl_thickness),md.initialization.epl_thickness=project2d(md,md.initialization.epl_thickness,1);end; 286 if ~isnan(md.initialization.waterfraction),md.initialization.waterfraction=project2d(md,md.initialization.waterfraction,1);end; 287 if ~isnan(md.initialization.watercolumn),md.initialization.watercolumn=project2d(md,md.initialization.watercolumn,1);end; 291 if ~isnan(md.initialization.vx), 292 md.initialization.vx=DepthAverage(md,md.initialization.vx); 293 end 294 if ~isnan(md.initialization.vy), 295 md.initialization.vy=DepthAverage(md,md.initialization.vy); 296 end 297 if ~isnan(md.initialization.vz), 298 md.initialization.vz=DepthAverage(md,md.initialization.vz); 299 end 300 if ~isnan(md.initialization.vel), 301 md.initialization.vel=DepthAverage(md,md.initialization.vel); 302 end 303 if ~isnan(md.initialization.temperature), 304 md.initialization.temperature=DepthAverage(md,md.initialization.temperature); 305 end 306 if ~isnan(md.initialization.pressure), 307 md.initialization.pressure=project2d(md,md.initialization.pressure,1); 308 end 309 if ~isnan(md.initialization.sediment_head), 310 md.initialization.sediment_head=project2d(md,md.initialization.sediment_head,1); 311 end 312 if ~isnan(md.initialization.epl_head), 313 md.initialization.epl_head=project2d(md,md.initialization.epl_head,1); 314 end 315 if ~isnan(md.initialization.epl_thickness), 316 md.initialization.epl_thickness=project2d(md,md.initialization.epl_thickness,1); 317 end 318 if ~isnan(md.initialization.waterfraction), 319 md.initialization.waterfraction=project2d(md,md.initialization.waterfraction,1); 320 end 321 if ~isnan(md.initialization.watercolumn), 322 md.initialization.watercolumn=project2d(md,md.initialization.watercolumn,1); 323 end 324 288 325 %giaivins 289 326 if isa(md.gia,'giaivins'), … … 299 336 md.flowequation.borderHO=project2d(md,md.flowequation.borderHO,1); 300 337 md.flowequation.borderFS=project2d(md,md.flowequation.borderFS,1); 301 end 338 end 302 339 303 340 %boundary conditions … … 307 344 md.stressbalance.referential=project2d(md,md.stressbalance.referential,md.mesh.numberoflayers); 308 345 md.stressbalance.loadingforce=project2d(md,md.stressbalance.loadingforce,md.mesh.numberoflayers); 309 if numel(md.masstransport.spcthickness)>1 md.masstransport.spcthickness=project2d(md,md.masstransport.spcthickness,md.mesh.numberoflayers); end 310 if numel(md.damage.spcdamage)>1, md.damage.spcdamage=project2d(md,md.damage.spcdamage,md.mesh.numberoflayers); end 311 if numel(md.levelset.spclevelset)>1, md.levelset.spclevelset=project2d(md,md.levelset.spclevelset,md.mesh.numberoflayers); end 346 if numel(md.masstransport.spcthickness)>1, 347 md.masstransport.spcthickness=project2d(md,md.masstransport.spcthickness,md.mesh.numberoflayers); 348 end 349 if numel(md.damage.spcdamage)>1, 350 md.damage.spcdamage=project2d(md,md.damage.spcdamage,md.mesh.numberoflayers); 351 end 352 if numel(md.levelset.spclevelset)>1, 353 md.levelset.spclevelset=project2d(md,md.levelset.spclevelset,md.mesh.numberoflayers); 354 end 312 355 md.thermal.spctemperature=project2d(md,md.thermal.spctemperature,md.mesh.numberoflayers); 313 356 … … 362 405 md.geometry.bed=project2d(md,md.geometry.bed,1); 363 406 end 364 365 407 if ~isnan(md.mask.ocean_levelset), 366 408 md.mask.ocean_levelset=project2d(md,md.mask.ocean_levelset,1); … … 371 413 372 414 %lat long 373 if numel(md.mesh.lat) ==md.mesh.numberofvertices, md.mesh.lat=project2d(md,md.mesh.lat,1); end 374 if numel(md.mesh.long)==md.mesh.numberofvertices, md.mesh.long=project2d(md,md.mesh.long,1); end 415 if numel(md.mesh.lat)==md.mesh.numberofvertices, 416 md.mesh.lat=project2d(md,md.mesh.lat,1); 417 end 418 if numel(md.mesh.long)==md.mesh.numberofvertices, 419 md.mesh.long=project2d(md,md.mesh.long,1); 420 end 375 421 376 422 %outputdefinitions … … 388 434 end 389 435 390 %Initialize withthe 2d mesh436 %Initialize the 2d mesh 391 437 mesh=mesh2d(); 392 438 mesh.x=md.mesh.x2d; … … 395 441 mesh.numberofelements=md.mesh.numberofelements2d; 396 442 mesh.elements=md.mesh.elements2d; 397 if numel(md.mesh.lat) ==md.mesh.numberofvertices, mesh.lat=project2d(md,md.mesh.lat,1); end 398 if numel(md.mesh.long)==md.mesh.numberofvertices, mesh.long=project2d(md,md.mesh.long,1); end 443 if numel(md.mesh.lat)==md.mesh.numberofvertices, 444 mesh.lat=project2d(md,md.mesh.lat,1); 445 end 446 if numel(md.mesh.long)==md.mesh.numberofvertices, 447 mesh.long=project2d(md,md.mesh.long,1); 448 end 399 449 mesh.epsg=md.mesh.epsg; 400 if numel(md.mesh.scale_factor)==md.mesh.numberofvertices, mesh.scale_factor=project2d(md,md.mesh.scale_factor,1); end 401 if ~isnan(md.mesh.vertexonboundary), mesh.vertexonboundary=project2d(md,md.mesh.vertexonboundary,1); end 402 if ~isnan(md.mesh.elementconnectivity), mesh.elementconnectivity=project2d(md,md.mesh.elementconnectivity,1); end 450 if numel(md.mesh.scale_factor)==md.mesh.numberofvertices, 451 mesh.scale_factor=project2d(md,md.mesh.scale_factor,1); 452 end 453 if ~isnan(md.mesh.vertexonboundary), 454 mesh.vertexonboundary=project2d(md,md.mesh.vertexonboundary,1); 455 end 456 if ~isnan(md.mesh.elementconnectivity), 457 mesh.elementconnectivity=project2d(md,md.mesh.elementconnectivity,1); 458 end 403 459 md.mesh=mesh; 404 460 md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices); … … 622 678 md2.mesh.elementconnectivity=ElementConnectivity(md2.mesh.elements,md2.mesh.vertexconnectivity); 623 679 md2.mesh.segments=contourenvelope(md2.mesh); 624 md2.mesh.vertexonboundary=zeros(numberofvertices2,1); md2.mesh.vertexonboundary(md2.mesh.segments(:,1:2))=1; 680 md2.mesh.vertexonboundary=zeros(numberofvertices2,1); 681 md2.mesh.vertexonboundary(md2.mesh.segments(:,1:2))=1; 625 682 else 626 683 %First do the connectivity for the contourenvelope in 2d … … 628 685 md2.mesh.elementconnectivity=ElementConnectivity(md2.mesh.elements2d,md2.mesh.vertexconnectivity); 629 686 segments=contourenvelope(md2.mesh); 630 md2.mesh.vertexonboundary=zeros(numberofvertices2/md2.mesh.numberoflayers,1); md2.mesh.vertexonboundary(segments(:,1:2))=1; 687 md2.mesh.vertexonboundary=zeros(numberofvertices2/md2.mesh.numberoflayers,1); 688 md2.mesh.vertexonboundary(segments(:,1:2))=1; 631 689 md2.mesh.vertexonboundary=repmat(md2.mesh.vertexonboundary,md2.mesh.numberoflayers,1); 632 690 %Then do it for 3d as usual -
issm/trunk-jpl/src/m/classes/model.py
r25455 r25499 412 412 md2.mesh.vertexconnectivity = NodeConnectivity(md2.mesh.elements, md2.mesh.numberofvertices) 413 413 md2.mesh.elementconnectivity = ElementConnectivity(md2.mesh.elements, md2.mesh.vertexconnectivity) 414 md2.mesh.segments = contourenvelope(md2 )414 md2.mesh.segments = contourenvelope(md2.mesh) 415 415 md2.mesh.vertexonboundary = np.zeros(numberofvertices2, bool) 416 416 md2.mesh.vertexonboundary[md2.mesh.segments[:, 0:2] - 1] = True … … 419 419 md2.mesh.vertexconnectivity = NodeConnectivity(md2.mesh.elements2d, md2.mesh.numberofvertices2d) 420 420 md2.mesh.elementconnectivity = ElementConnectivity(md2.mesh.elements2d, md2.mesh.vertexconnectivity) 421 segments = contourenvelope(md2)421 msegments = contourenvelope(md2.mesh) 422 422 md2.mesh.vertexonboundary = np.zeros(int(numberofvertices2 / md2.mesh.numberoflayers), bool) 423 423 md2.mesh.vertexonboundary[segments[:, 0:2] - 1] = True … … 696 696 697 697 This routine collapses a 3d model into a 2d model and collapses all 698 the fi leds of the 3d model by taking their depth -averaged values698 the fields of the 3d model by taking their depth-averaged values 699 699 700 700 Usage: 701 701 md = collapse(md) 702 703 See also: EXTRUDE, MODELEXTRACT 702 704 """ 703 705 704 #Check that the model is really a 3d model 705 if md.mesh.domaintype().lower() != '3d': 706 raise Exception("only a 3D model can be collapsed") 707 708 #dealing with the friction law 709 #drag is limited to nodes that are on the bedrock. 710 if hasattr(md.friction, 'coefficient'): 706 # Check that the model is really a 3d model 707 if md.mesh.elementtype() != 'Penta': 708 raise Exception("collapse error message: only a 3d mesh can be collapsed") 709 710 # Start with changing all the fields from the 3d mesh 711 712 # Dealing with the friction law 713 # Drag is limited to nodes that are on the bedrock. 714 if md.friction.__class__.__name__ == 'friction': 711 715 md.friction.coefficient = project2d(md, md.friction.coefficient, 1) 712 713 #p and q (same deal, except for element that are on the bedrock: )714 if hasattr(md.friction, 'p'):715 716 md.friction.p = project2d(md, md.friction.p, 1) 716 if hasattr(md.friction, 'q'):717 717 md.friction.q = project2d(md, md.friction.q, 1) 718 719 if hasattr(md.friction, 'coefficientcoulomb'):718 elif md.friction.__class__.__name__ == 'frictioncoulomb': 719 md.friction.coefficient = project2d(md, md.friction.coefficient, 1) 720 720 md.friction.coefficientcoulomb = project2d(md, md.friction.coefficientcoulomb, 1) 721 if hasattr(md.friction, 'C'): 721 md.friction.p = project2d(md, md.friction.p, 1) 722 md.friction.q = project2d(md, md.friction.q, 1) 723 elif md.friction.__class__.__name__ == 'frictionhydro': 724 md.friction.q = project2d(md, md.friction.q, 1) 722 725 md.friction.C = project2d(md, md.friction.C, 1) 723 if hasattr(md.friction, 'As'):724 726 md.friction.As = project2d(md, md.friction.As, 1) 725 if hasattr(md.friction, 'effective_pressure') and not np.isnan(md.friction.effective_pressure).all():726 727 md.friction.effective_pressure = project2d(md, md.friction.effective_pressure, 1) 727 if hasattr(md.friction, 'water_layer'): 728 elif md.friction.__class__.__name__ == 'frictionwaterlayer': 729 md.friction.coefficient = project2d(md, md.friction.coefficient, 1) 730 md.friction.p = project2d(md, md.friction.p, 1) 731 md.friction.q = project2d(md, md.friction.q, 1) 728 732 md.friction.water_layer = project2d(md, md.friction.water_layer, 1) 729 if hasattr(md.friction, 'm'): 733 elif md.friction.__class__.__name__ == 'frictionweertman': 734 md.friction.C = project2d(md, md.friction.C, 1) 730 735 md.friction.m = project2d(md, md.friction.m, 1) 731 732 #observations 736 elif md.friction.__class__.__name__ == 'frictionweertmantemp': 737 md.friction.C = project2d(md, md.friction.C, 1) 738 md.friction.m = project2d(md, md.friction.m, 1) 739 else: 740 print('friction type not supported') 741 742 # Observations 733 743 if not np.isnan(md.inversion.vx_obs).all(): 734 744 md.inversion.vx_obs = project2d(md, md.inversion.vx_obs, md.mesh.numberoflayers) … … 741 751 if not np.isnan(md.inversion.cost_functions_coefficients).all(): 742 752 md.inversion.cost_functions_coefficients = project2d(md, md.inversion.cost_functions_coefficients, md.mesh.numberoflayers) 743 if isinstance(md.inversion.min_parameters, np.ndarray): 744 if md.inversion.min_parameters.size > 1: 745 md.inversion.min_parameters = project2d(md, md.inversion.min_parameters, md.mesh.numberoflayers) 746 if isinstance(md.inversion.max_parameters, np.ndarray): 747 if md.inversion.max_parameters.size > 1: 748 md.inversion.max_parameters = project2d(md, md.inversion.max_parameters, md.mesh.numberoflayers) 749 if hasattr(md.smb, 'mass_balance'): 750 if not np.isnan(md.smb.mass_balance).all(): 753 if isinstance(md.inversion.min_parameters, np.ndarray) and md.inversion.min_parameters.size > 1: 754 md.inversion.min_parameters = project2d(md, md.inversion.min_parameters, md.mesh.numberoflayers) 755 if isinstance(md.inversion.max_parameters, np.ndarray) and md.inversion.max_parameters.size > 1: 756 md.inversion.max_parameters = project2d(md, md.inversion.max_parameters, md.mesh.numberoflayers) 757 if md.smb.__class__.__name__ == 'SMBforcing' and not np.isnan(md.smb.mass_balance).all(): 751 758 md.smb.mass_balance = project2d(md, md.smb.mass_balance, md.mesh.numberoflayers) 752 753 #results 759 elif md.smb.__class__.__name__ == 'SMBhenning' and not np.isnan(md.smb.smbref).all(): 760 md.smb.smbref = project2d(md, md.smb.smbref, md.mesh.numberoflayers) 761 762 # Results 754 763 if not np.isnan(md.initialization.vx).all(): 755 764 md.initialization.vx = DepthAverage(md, md.initialization.vx) … … 770 779 if not np.isnan(md.initialization.epl_thickness).all(): 771 780 md.initialization.epl_thickness = project2d(md, md.initialization.epl_thickness, 1) 772 773 #giaivins 781 if not np.isnan(md.initialization.waterfraction).all(): 782 md.initialization.waterfraction = project2d(md, md.initialization.waterfraction, 1) 783 if not np.isnan(md.initialization.watercolumn).all(): 784 md.initialization.watercolumn = project2d(md, md.initialization.watercolumn, 1) 785 786 # giaivins 774 787 if md.gia.__class__.__name__ == 'giaivins': 775 788 if not np.isnan(md.gia.mantle_viscosity).all(): … … 778 791 md.gia.lithosphere_thickness = project2d(md, md.gia.lithosphere_thickness, 1) 779 792 780 # elementstype793 # elementstype 781 794 if not np.isnan(md.flowequation.element_equation).all(): 782 795 md.flowequation.element_equation = project2d(md, md.flowequation.element_equation, 1) … … 786 799 md.flowequation.borderFS = project2d(md, md.flowequation.borderFS, 1) 787 800 788 # Hydrologydc variables 789 hydrofields = md.hydrology.__dict__.keys() 790 for field in hydrofields: 791 try: 792 isvector = np.logical_or(np.shape(md.hydrology.__dict__[field])[0] == md.mesh.numberofelements, 793 np.shape(md.hydrology.__dict__[field])[0] == md.mesh.numberofvertices) 794 except IndexError: 795 isvector = False 796 #we colpase only fields that are vertices or element based 797 if isvector: 798 md.hydrology.__dict__[field] = project2d(md, md.hydrology.__dict__[field], 1) 799 800 #boundary conditions 801 # Boundary conditions 801 802 md.stressbalance.spcvx = project2d(md, md.stressbalance.spcvx, md.mesh.numberoflayers) 802 803 md.stressbalance.spcvy = project2d(md, md.stressbalance.spcvy, md.mesh.numberoflayers) … … 804 805 md.stressbalance.referential = project2d(md, md.stressbalance.referential, md.mesh.numberoflayers) 805 806 md.stressbalance.loadingforce = project2d(md, md.stressbalance.loadingforce, md.mesh.numberoflayers) 807 # TODO: 808 # - Check if md.mesh.numberoflayershould really be offset by 1. 809 # - Find out why md.masstransport.spcthickness is not offset, but the 810 # other fields are. 811 # - If offset is required, figure out if it can be abstarcted away to 812 # another part of the API. 806 813 if np.size(md.masstransport.spcthickness) > 1: 807 814 md.masstransport.spcthickness = project2d(md, md.masstransport.spcthickness, md.mesh.numberoflayers) … … 812 819 md.thermal.spctemperature = project2d(md, md.thermal.spctemperature, md.mesh.numberoflayers - 1) 813 820 814 #materials 821 # Hydrologydc variables 822 if md.hydrology.__class__.__name__ == 'hydrologydc': 823 md.hydrology.spcsediment_head = project2d(md, md.hydrology.spcsediment_head, 1) 824 md.hydrology.mask_eplactive_node = project2d(md, md.hydrology.mask_eplactive_node, 1) 825 md.hydrology.sediment_transmitivity = project2d(md, md.hydrology.sediment_transmitivity, 1) 826 md.hydrology.basal_moulin_input = project2d(md, md.hydrology.basal_moulin_input, 1) 827 if md.hydrology.isefficientlayer == 1: 828 md.hydrology.spcepl_head = project2d(md, md.hydrology.spcepl_head, 1) 829 # hydrofields = md.hydrology.__dict__.keys() 830 # for field in hydrofields: 831 # try: 832 # isvector = np.logical_or(np.shape(md.hydrology.__dict__[field])[0] == md.mesh.numberofelements, 833 # np.shape(md.hydrology.__dict__[field])[0] == md.mesh.numberofvertices) 834 # except IndexError: 835 # isvector = False 836 # #we collapse only fields that are vertices or element based 837 # if isvector: 838 # md.hydrology.__dict__[field] = project2d(md, md.hydrology.__dict__[field], 1) 839 840 # Materials 815 841 md.materials.rheology_B = DepthAverage(md, md.materials.rheology_B) 816 842 md.materials.rheology_n = project2d(md, md.materials.rheology_n, 1) 817 843 818 # damage:844 # Damage 819 845 if md.damage.isdamage: 820 846 md.damage.D = DepthAverage(md, md.damage.D) 821 847 822 #special for thermal modeling: 823 md.basalforcings.groundedice_melting_rate = project2d(md, md.basalforcings.groundedice_melting_rate, 1) 824 md.basalforcings.floatingice_melting_rate = project2d(md, md.basalforcings.floatingice_melting_rate, 1) 848 # Special for thermal modeling 849 if not np.isnan(md.basalforcings.groundedice_melting_rate).all(): 850 md.basalforcings.groundedice_melting_rate = project2d(md, md.basalforcings.groundedice_melting_rate, 1) 851 if hasattr(md.basalforcings, 'floatingice_melting_rate') and not np.isnan(md.basalforcings.floatingice_melting_rate).all(): 852 md.basalforcings.floatingice_melting_rate = project2d(md, md.basalforcings.floatingice_melting_rate, 1) 825 853 md.basalforcings.geothermalflux = project2d(md, md.basalforcings.geothermalflux, 1) #bedrock only gets geothermal flux 826 854 827 #update of connectivity matrix 855 if hasattr(md.calving, 'coeff') and not np.isnan(md.calving.coeff).all(): 856 md.calving.coeff = project2d(md, md.calving.coeff, 1) 857 if hasattr(md.frontalforcings, 'meltingrate') and not np.isnan(md.frontalforcings.meltingrate).all(): 858 md.frontalforcings.meltingrate = project2d(md, md.frontalforcings.meltingrate, 1) 859 860 # Update of connectivity matrix 828 861 md.mesh.average_vertex_connectivity = 25 829 862 830 #parameters 863 # Collapse the mesh 864 nodes2d = md.mesh.numberofvertices2d 865 elements2d = md.mesh.numberofelements2d 866 867 # Parameters 831 868 md.geometry.surface = project2d(md, md.geometry.surface, 1) 832 869 md.geometry.thickness = project2d(md, md.geometry.thickness, 1) 833 870 md.geometry.base = project2d(md, md.geometry.base, 1) 834 if isinstance(md.geometry.bed, np.ndarray):871 if not np.isnan(md.geometry.bed).all(): 835 872 md.geometry.bed = project2d(md, md.geometry.bed, 1) 836 md.mask.ocean_levelset = project2d(md, md.mask.ocean_levelset, 1) 837 md.mask.ice_levelset = project2d(md, md.mask.ice_levelset, 1) 838 839 #OutputDefinitions 873 if not np.isnan(md.mask.ocean_levelset).all(): 874 md.mask.ocean_levelset = project2d(md, md.mask.ocean_levelset, 1) 875 if not np.isnan(md.mask.ice_levelset).all(): 876 md.mask.ice_levelset = project2d(md, md.mask.ice_levelset, 1) 877 878 # Lat/long 879 if np.size(md.mesh.lat) == md.mesh.numberofvertices: 880 md.mesh.lat = project2d(md, md.mesh.lat, 1) 881 if np.size(md.mesh.long) == md.mesh.numberofvertices: 882 md.mesh.long = project2d(md, md.mesh.long, 1) 883 884 # OutputDefinitions 840 885 if md.outputdefinition.definitions: 841 886 for solutionfield, field in list(md.outputdefinition.__dict__.items()): 842 887 if isinstance(field, list): 843 # get each definition888 # Get each definition 844 889 for i, fieldi in enumerate(field): 845 890 if fieldi: 846 891 fieldr = getattr(md.outputdefinition, solutionfield)[i] 847 # get subfields892 # Get subfields 848 893 for solutionsubfield, subfield in list(fieldi.__dict__.items()): 849 894 if np.size(subfield) == md.mesh.numberofvertices: … … 852 897 setattr(fieldr, solutionsubfield, project2d(md, subfield, 1)) 853 898 854 # Initialize with the 2d mesh899 # Initialize he 2d mesh 855 900 mesh = mesh2d() 856 901 mesh.x = md.mesh.x2d … … 859 904 mesh.numberofelements = md.mesh.numberofelements2d 860 905 mesh.elements = md.mesh.elements2d 906 # if not np.isnan(md.mesh.vertexonboundary).all(): 907 # mesh.vertexonboundary = project2d(md, md.mesh.vertexonboundary, 1) 908 # if not np.isnan(md.mesh.elementconnectivity).all(): 909 # mesh.elementconnectivity = project2d(md, md.mesh.elementconnectivity, 1) 910 if np.size(md.mesh.lat) == md.mesh.numberofvertices: 911 mesh.lat = project2d(md, md.mesh.lat, 1) 912 if np.size(md.mesh.long) == md.mesh.numberofvertices: 913 mesh.long = project2d(md, md.mesh.long, 1) 914 mesh.epsg = md.mesh.epsg 915 if np.size(md.mesh.scale_factor) == md.mesh.numberofvertices: 916 mesh.scale_factor = project2d(md, md.mesh.scale_factor, 1) 861 917 if not np.isnan(md.mesh.vertexonboundary).all(): 862 mesh.vertexonboundary = project2d(md, md.mesh.vertexonboundary, 1) 863 if not np.isnan(md.mesh.elementconnectivity).all(): 864 mesh.elementconnectivity = project2d(md, md.mesh.elementconnectivity, 1) 865 if isinstance(md.mesh.lat, np.ndarray): 866 if md.mesh.lat.size == md.mesh.numberofvertices: 867 mesh.lat = project2d(md, md.mesh.lat, 1) 868 if isinstance(md.mesh.long, np.ndarray): 869 if md.mesh.long.size == md.mesh.numberofvertices: 870 md.mesh.long = project2d(md, md.mesh.long, 1) 871 mesh.epsg = md.mesh.epsg 872 if isinstance(md.mesh.scale_factor, np.ndarray): 873 if md.mesh.scale_factor.size == md.mesh.numberofvertices: 874 md.mesh.scale_factor = project2d(md, md.mesh.scale_factor, 1) 918 mesh.vertexonboundary= project2d(md, md.mesh.vertexonboundary, 1) 919 if not np.isnan(md.mesh.elementonboundary).all(): 920 mesh.elementonboundary = project2d(md, md.mesh.elementonboundary, 1) 875 921 md.mesh = mesh 876 922 md.mesh.vertexconnectivity = NodeConnectivity(md.mesh.elements, md.mesh.numberofvertices) 877 923 md.mesh.elementconnectivity = ElementConnectivity(md.mesh.elements, md.mesh.vertexconnectivity) 878 md.mesh.segments = contourenvelope(md )924 md.mesh.segments = contourenvelope(md.mesh) 879 925 880 926 return md -
issm/trunk-jpl/src/m/classes/sealevelmodel.m
r25455 r25499 174 174 175 175 %initialize, to avoid issues of having more transitions than meshes. 176 self.transitions={}; self.eltransitions={}; 176 self.transitions={}; 177 self.eltransitions={}; 177 178 178 179 %for elements: … … 180 181 ye=self.earth.mesh.y(self.earth.mesh.elements)*[1;1;1]/3; 181 182 ze=self.earth.mesh.z(self.earth.mesh.elements)*[1;1;1]/3; 182 183 183 184 for i=1:length(self.icecaps), 184 185 mdi=self.icecaps{i}; … … 196 197 self.eltransitions{end+1}=meshintersect3d(xe,ye,ze,xei,yei,zei,'force',force); 197 198 end 198 199 199 end % }}} 200 200 function checkintersections(self) % {{{ … … 397 397 eval(['capfieldj= self.icecaps{' num2str(j) '}.' string ';']); 398 398 if ~isequal(capfieldi(end,:),capfieldj(end,:)), 399 error(['Time stamps for ' string ' field isdifferent between icecaps ' num2str(i) ' and ' num2str(j)]);399 error(['Time stamps for ' string ' field are different between icecaps ' num2str(i) ' and ' num2str(j)]); 400 400 end 401 401 end -
issm/trunk-jpl/src/m/classes/sealevelmodel.py
r25477 r25499 1 from copy import deepcopy 1 2 import warnings 2 3 import numpy as np 3 4 from fielddisplay import fielddisplay 4 from fieldnames import fieldnames5 5 from generic import generic 6 from getsubattr import getsubattr 6 7 from issmsettings import issmsettings 7 8 from meshintersect3d import meshintersect3d … … 10 11 from modelmerge3d import modelmerge3d 11 12 from pairoptions import pairoptions 13 from planetradius import planetradius 14 from plotmodel import plotmodel 12 15 from private import private 16 from setsubattr import setsubattr 13 17 from TwoDToThreeD import TwoDToThreeD 14 from plotmodel import plotmodel 15 from plot3 import plot3 16 from loneedges import loneedges 17 from planetradius import planetradius 18 18 19 19 20 class sealevelmodel(object): … … 174 175 175 176 # For elements 176 onesmatrix = np.array([[1], [1], [1]]) 177 xe = self.earth.mesh.x[self.earth.mesh.elements] * onesmatrix / 3 178 ye = self.earth.mesh.y[self.earth.mesh.elements] * onesmatrix / 3 179 ze = self.earth.mesh.z[self.earth.mesh.elements] * onesmatrix / 3 177 xe = np.mean(self.earth.mesh.x[self.earth.mesh.elements - 1], axis=1) 178 ye = np.mean(self.earth.mesh.y[self.earth.mesh.elements - 1], axis=1) 179 ze = np.mean(self.earth.mesh.z[self.earth.mesh.elements - 1], axis=1) 180 180 181 181 for i in range(len(self.icecaps)): … … 184 184 185 185 # For elements 186 xei = mdi.mesh.x[mdi.mesh.elements] * onesmatrix / 3187 yei = mdi.mesh.y[mdi.mesh.elements] * onesmatrix / 3188 zei = mdi.mesh.z[mdi.mesh.elements] * onesmatrix / 3186 xei = np.mean(mdi.mesh.x[mdi.mesh.elements - 1], axis=1) 187 yei = np.mean(mdi.mesh.y[mdi.mesh.elements - 1], axis=1) 188 zei = np.mean(mdi.mesh.z[mdi.mesh.elements - 1], axis=1) 189 189 190 190 print('Computing vertex intersections for basin {}'.format(self.basins[i].name)) … … 300 300 301 301 # Make 3D model 302 models = self.icecaps302 models = deepcopy(self.icecaps) 303 303 for i in range(len(models)): 304 304 models[i] = TwoDToThreeD(models[i], self.planet) … … 308 308 for i in range(1, len(models)): 309 309 md = modelmerge3d(md, models[i], 'tolerance', tolerance) 310 md.private.bamg.landmask = np. vstack((md.private.bamg.landmask, models[i].private.bamg.landmask))310 md.private.bamg.landmask = np.hstack((md.private.bamg.landmask, models[i].private.bamg.landmask)) 311 311 312 312 # Look for lone edges if asked for it … … 317 317 ind1 = edges(i, 1) 318 318 ind2 = edges(i, 2) 319 # TODO: Reconfigure the following in the process of bringing plotting online 319 320 plot3([md.mesh.x[ind1], md.mesh.x[ind2]], [md.mesh.y[ind1], md.mesh.y[ind2]], [md.mesh.z[ind1], md.mesh.z[ind2]], 'g*-') 320 321 … … 323 324 324 325 # Create mesh radius 325 self.earth.mesh.r = planetradius('earth') 326 self.earth.mesh.r = planetradius('earth') * np.ones((md.mesh.numberofvertices, )) 326 327 #}}} 327 328 … … 349 350 def transfer(self, string): #{{{ 350 351 # Recover field size in one icecap 351 n = np.size(getattr(self.icecaps[0], string), 0)352 n = getsubattr(self.icecaps[0], string).shape[0] 352 353 353 354 if n == self.icecaps[0].mesh.numberofvertices: 354 setattr(self.earth, string, np.zeros((self.earth.mesh.numberofvertices, ))) 355 setsubattr(self.earth, string, np.zeros((self.earth.mesh.numberofvertices, ))) # Assign array of zeros to target attribute 356 earth_attr = getsubattr(self.earth, string) # Retrieve reference to target attribute 355 357 for i in range(len(self.icecaps)): 356 getattr(self.earth, string)[self.transitions[i]] = getattr(self.icecaps[i], string)357 elif n == (self. self.icecaps[0].mesh.numberofvertices + 1):358 earth_attr[self.transitions[i]] = getsubattr(self.icecaps[i], string) 359 elif n == (self.icecaps[0].mesh.numberofvertices + 1): 358 360 # Dealing with transient dataset 359 361 # Check that all timetags are similar between all icecaps #{{{ 360 362 for i in range(len(self.icecaps)): 361 capfieldi = get attr(self.icecaps[i], string)362 for j in range( 1, len(self.icecaps)):363 capfieldj = get attr(self.icecaps[j], string)363 capfieldi = getsubattr(self.icecaps[i], string) 364 for j in range(i + 1, len(self.icecaps)): 365 capfieldj = getsubattr(self.icecaps[j], string) 364 366 if capfieldi[-1, :] != capfieldj[-1, :]: 365 raise Exception("Time stamps for {} field isdifferent between icecaps {} and {}".format(string, i, j))366 capfield1 = get attr(self.icecaps[0], string)367 raise Exception("Time stamps for {} field are different between icecaps {} and {}".format(string, i, j)) 368 capfield1 = getsubattr(self.icecaps[0], string) 367 369 times = capfield1[-1, :] 368 370 nsteps = len(times) … … 374 376 # Transfer all the time fields #{{{ 375 377 for i in range(len(self.icecaps)): 376 capfieldi = get attr(self.icecaps[i], string)378 capfieldi = getsubattr(self.icecaps[i], string) 377 379 for j in range(nsteps): 378 field[self.transitions[i], j] = capfieldi[0:- 2, j] # Transfer only the values, not the time379 set attr(self.earth, string, field) # Do not forget to plug the field variable into its final location380 field[self.transitions[i], j] = capfieldi[0:-1, j] # Transfer only the values, not the time 381 setsubattr(self.earth, string, field) # Do not forget to plug the field variable into its final location 380 382 #}}} 381 383 elif n == (self.icecaps[0].mesh.numberofelements): 382 setattr(self.earth, string, np.zeros((self.earth.mesh.numberofvertices, ))) 384 setsubattr(self.earth, string, np.zeros((self.earth.mesh.numberofelements, ))) # Assign array of zeros to target attribute 385 earth_attr = getsubattr(self.earth, string) # Retrieve reference to target attribute 383 386 for i in range(len(self.icecaps)): 384 getattr(self.earth, string)[self.eltransitions[i]] = getattr(self.icecaps[i], string)387 earth_attr[self.eltransitions[i]] = getsubattr(self.icecaps[i], string) 385 388 else: 386 389 raise Exception('not supported yet') -
issm/trunk-jpl/src/m/classes/surfaceload.py
r25171 r25499 7 7 8 8 class surfaceload(object): 9 ''' 10 SURFACELOAD class definition 9 """SURFACELOAD class definition 11 10 12 13 14 '''11 Usage: 12 surfaceload = surfaceload() 13 """ 15 14 16 15 def __init__(self, *args): #{{{ … … 58 57 def marshall(self, prefix, md, fid): #{{{ 59 58 if len(self.icethicknesschange) == 0: 60 self.icethicknesschange = np.zeros( md.mesh.numberofelements + 1)59 self.icethicknesschange = np.zeros((md.mesh.numberofelements + 1, )) 61 60 62 61 if len(self.waterheightchange) == 0: 63 self.waterheightchange = np.zeros( md.mesh.numberofelements + 1)62 self.waterheightchange = np.zeros((md.mesh.numberofelements + 1, )) 64 63 65 64 if len(self.other) == 0: 66 self.other = np.zeros( md.mesh.numberofelements + 1)65 self.other = np.zeros((md.mesh.numberofelements + 1, )) 67 66 68 67 WriteData(fid, prefix, 'object', self, 'fieldname', 'icethicknesschange', 'name', 'md.solidearth.surfaceload.icethicknesschange', 'format', 'DoubleMat', 'mattype', 2, 'timeserieslength', md.mesh.numberofelements + 1, 'yts', md.constants.yts) -
issm/trunk-jpl/src/m/consistency/checkfield.py
r25385 r25499 8 8 9 9 def checkfield(md, *args): 10 ''' 11 CHECKFIELD - check field consistency 12 13 Used to check model consistency 10 """CHECKFIELD - check field consistency 11 12 Used to check model consistency 14 13 15 Requires: 16 'field' or 'fieldname' option. If 'fieldname' is provided, it will retrieve it from the model md. (md.(fieldname)) 17 If 'field' is provided, it will assume the argument following 18 'field' is a numeric array. 19 20 Available options: 14 Requires: 15 'field' or 'fieldname' option. If 'fieldname' is provided, it will 16 retrieve it from the model md. (md.(fieldname)) 17 If 'field' is provided, it will assume the argument following 'field' 18 is a numeric array. 19 20 Available options: 21 21 - NaN: 1 if check that there is no NaN 22 22 - size: [lines cols], NaN for non checked dimensions, or 'universal' … … 34 34 - message: overloaded error message 35 35 36 37 38 '''36 Usage: 37 md = checkfield(md, fieldname, options) 38 """ 39 39 40 40 #get options … … 76 76 #Check that vector size will not be confusing for ModelProcessorx 77 77 if (md.mesh.numberofvertices == md.mesh.numberofelements): 78 raise RuntimeError('number of vertices is the same as number of elements')78 raise Exception('number of vertices is the same as number of elements') 79 79 elif (md.mesh.numberofvertices + 1 == md.mesh.numberofelements): 80 raise RuntimeError('number of vertices + 1 is the same as number of elements')80 raise Exception('number of vertices + 1 is the same as number of elements') 81 81 elif (md.mesh.numberofvertices == md.mesh.numberofelements + 1): 82 raise RuntimeError('number of vertices is the same as number of elements + 1')82 raise Exception('number of vertices is the same as number of elements + 1') 83 83 84 84 #Uniform field 85 if ( np.size(field, 0)== 1):85 if (field.shape[0] == 1): 86 86 if (np.ndim(field) > 1 and np.shape(field)[1] != 1): 87 87 md = md.checkmessage(options.getfieldvalue('message', "field '{}' is not supported".format(fieldname))) … … 112 112 113 113 else: 114 raise RuntimeError("fieldsize '{}' not supported yet".format(fieldsize))114 raise Exception("fieldsize '{}' not supported yet".format(fieldsize)) 115 115 116 116 else: … … 155 155 md = md.checkmessage(options.getfieldvalue('message', "field '{}' value should be '{}'".format(fieldname, fieldvalues[0]))) 156 156 elif len(fieldvalues) == 2: 157 md = md.checkmessage(options.getfieldvalue('message', "field '{}' values should be '{}' '{}' or ' %s'".format(fieldname, fieldvalues[0], fieldvalues[1])))157 md = md.checkmessage(options.getfieldvalue('message', "field '{}' values should be '{}' '{}' or '{}'".format(fieldname, fieldvalues[0], fieldvalues[1]))) 158 158 else: 159 159 md = md.checkmessage(options.getfieldvalue('message', "field '{}' should have values in {}".format(fieldname, fieldvalues))) … … 166 166 if np.size(lowerbound) > 1: #checking elementwise 167 167 if any(field < lowerbound): 168 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have values above %d" %(fieldname, lowerbound)))168 md = md.checkmessage(options.getfieldvalue('message', "field {} should have values above {}".format(fieldname, lowerbound))) 169 169 else: 170 170 minval = np.nanmin(field) … … 178 178 179 179 if minval < lowerbound: 180 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have values above %d" %(fieldname, lowerbound)))180 md = md.checkmessage(options.getfieldvalue('message', "field {} should have values above {}".format(fieldname, lowerbound))) 181 181 182 182 if options.exist('>'): … … 186 186 if np.size(lowerbound) > 1: #checking elementwise 187 187 if any(field <= lowerbound): 188 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have values above %d" %(fieldname, lowerbound)))188 md = md.checkmessage(options.getfieldvalue('message', "field {} should have values above {}".format(fieldname, lowerbound))) 189 189 else: 190 190 minval = np.nanmin(field) … … 198 198 199 199 if minval <= lowerbound: 200 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have values above %d" %(fieldname, lowerbound)))200 md = md.checkmessage(options.getfieldvalue('message', "field {} should have values above {}".format(fieldname, lowerbound))) 201 201 202 202 #check smaller … … 207 207 if np.size(upperbound) > 1: #checking elementwise 208 208 if any(field > upperbound): 209 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have values below %d" %(fieldname, upperbound)))209 md = md.checkmessage(options.getfieldvalue('message', "field {} should have values below {}".format(fieldname, upperbound))) 210 210 else: 211 211 maxval = np.nanmax(field) … … 220 220 maxval = field.fov_forward_indices[0] 221 221 if maxval > upperbound: 222 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have values below %d" %(fieldname, upperbound)))222 md = md.checkmessage(options.getfieldvalue('message', "field {} should have values below {}".format(fieldname, upperbound))) 223 223 224 224 if options.exist('<'): … … 228 228 if np.size(upperbound) > 1: #checking elementwise 229 229 if any(field >= upperbound): 230 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have values below %d" %(fieldname, upperbound)))230 md = md.checkmessage(options.getfieldvalue('message', "field {} should have values below {}".format(fieldname, upperbound))) 231 231 232 232 else: … … 241 241 242 242 if maxval >= upperbound: 243 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have values below %d" %(fieldname, upperbound)))243 md = md.checkmessage(options.getfieldvalue('message', "field {} should have values below {}".format(fieldname, upperbound))) 244 244 245 245 #check file 246 246 if options.getfieldvalue('file', 0): 247 247 if not os.path.exists(field): 248 md = md.checkmessage("file provided in '%s': '%s' does not exist" %(fieldname, field))248 md = md.checkmessage("file provided in {}: {} does not exist".format(fieldname, field)) 249 249 250 250 #Check row of strings 251 251 if options.exist('stringrow'): 252 252 if not isinstance(field, list): 253 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should be a list" % fieldname))253 md = md.checkmessage(options.getfieldvalue('message', "field {} should be a list".format(fieldname))) 254 254 255 255 #Check forcings (size and times) 256 256 if options.getfieldvalue('timeseries', 0): 257 if np.size(field, 0) == md.mesh.numberofvertices or np.size(field, 0)== md.mesh.numberofelements:257 if field.shape[0] == md.mesh.numberofvertices or field.shape[0] == md.mesh.numberofelements: 258 258 if np.ndim(field) > 1 and not np.size(field, 1) == 1: 259 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have only one column as there are md.mesh.numberofvertices lines" % fieldname))260 elif np.size(field, 0) == md.mesh.numberofvertices + 1 or np.size(field, 0)== md.mesh.numberofelements + 1:259 md = md.checkmessage(options.getfieldvalue('message', "field {} should have only one column as there are md.mesh.numberofvertices lines".format(fieldname))) 260 elif field.shape[0] == md.mesh.numberofvertices + 1 or field.shape[0] == md.mesh.numberofelements + 1: 261 261 if np.ndim(field) > 1 and not all(field[-1, :] == np.sort(field[-1, :])): 262 md = md.checkmessage(options.getfieldvalue('message', "field '%s' columns should be sorted chronologically" % fieldname))262 md = md.checkmessage(options.getfieldvalue('message', "field {} columns should be sorted chronologically".format(fieldname))) 263 263 if np.ndim(field) > 1 and any(field[-1, 0:-1] == field[-1, 1:]): 264 md = md.checkmessage(options.getfieldvalue('message', "field '%s' columns must not contain duplicate timesteps" % fieldname))265 else: 266 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have md.mesh.numberofvertices or md.mesh.numberofvertices + 1 lines" % fieldname))264 md = md.checkmessage(options.getfieldvalue('message', "field {} columns must not contain duplicate timesteps".format(fieldname))) 265 else: 266 md = md.checkmessage(options.getfieldvalue('message', "field {} should have md.mesh.numberofvertices or md.mesh.numberofvertices + 1 lines".format(fieldname))) 267 267 268 268 #Check single value forcings (size and times) 269 269 if options.getfieldvalue('singletimeseries', 0): 270 if np.size(field, 0)== 2:270 if field.shape[0] == 2: 271 271 if not all(field[-1, :] == np.sort(field[-1, :])): 272 md = md.checkmessage(options.getfieldvalue('message', "field '%s' columns should be sorted chronologically" % fieldname))272 md = md.checkmessage(options.getfieldvalue('message', "field {} columns should be sorted chronologically".format(fieldname))) 273 273 if any(field[-1, 0:-1] == field[-1, 1:]): 274 md = md.checkmessage(options.getfieldvalue('message', "field '%s' columns must not contain duplicate timesteps" % fieldname))275 elif np.size(field, 0)== 1:274 md = md.checkmessage(options.getfieldvalue('message', "field {} columns must not contain duplicate timesteps".format(fieldname))) 275 elif field.shape[0] == 1: 276 276 if np.ndim(field) > 1 and not np.size(field, 1) == 1: 277 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should be either a scalar or have 2 lines" % fieldname))278 else: 279 md = md.checkmessage(options.getfieldvalue('message', "field '%s' should have 2 lines or be a scalar" % fieldname))277 md = md.checkmessage(options.getfieldvalue('message', "field {} should be either a scalar or have 2 lines".format(fieldname))) 278 else: 279 md = md.checkmessage(options.getfieldvalue('message', "field {} should have 2 lines or be a scalar".format(fieldname))) 280 280 281 281 return md -
issm/trunk-jpl/src/m/geometry/GetAreas3DTria.m
r19311 r25499 2 2 %GETAREAS3DTRIA - compute areas of triangles with 3D coordinates 3 3 % 4 % compute areas of trianguls with 3D coordinates4 % Compute areas of triangles with 3D coordinates 5 5 % 6 6 % Usage: 7 % areas 7 % areas=GetAreas3DTria(index,x,y,z); 8 8 % 9 9 % Examples: 10 % areas 10 % areas=GetAreas3DTria(md.mesh.elements,md.mesh.x,md.mesh.y,md.mesh.z); 11 11 12 12 %get number of elements and number of nodes 13 nels=size(index,1); 14 nods=length(x); 13 nels=size(index,1); 14 nods=length(x); 15 15 16 16 %some checks 17 17 if nargout~=1 | (nargin~=3 & nargin~=4), 18 18 help GetAreas3DTria 19 error('GetAreas error message: bad usage')19 error('GetAreas3DTria error message: bad usage') 20 20 end 21 21 if ((length(y)~=nods) | (nargin==4 & length(z)~=nods)), 22 error('GetAreas3DTria error message: x, yand z do not have the same length')22 error('GetAreas3DTria error message: x, y, and z do not have the same length') 23 23 end 24 24 25 if max(index(:))>nods, 25 26 error(['GetAreas3DTria error message: index should not have values above ' num2str(nods) ]) 26 27 end 27 28 if (nargin==4 & size(index,2)~=3), 28 error('GetAreas3DTria error message: index should have 3 columns for 2d meshes .')29 error('GetAreas3DTria error message: index should have 3 columns for 2d meshes') 29 30 end 30 31 … … 37 38 %compute the volume of each element 38 39 if nargin==4, 39 % area of triangles with 3D coordinats 40 for j=1:nels 41 m1=[x1(j) x2(j) x3(j); y1(j) y2(j) y3(j); 1 1 1]; 42 m2=[y1(j) y2(j) y3(j); z1(j) z2(j) z3(j); 1 1 1]; 43 m3=[z1(j) z2(j) z3(j); x1(j) x2(j) x3(j); 1 1 1]; 44 areas(j)=sqrt(det(m1)^2 + det(m2)^2 + det(m3)^2)/2; 45 end 46 end 47 48 40 % area of triangles with 3D coordinates 41 for i=1:nels 42 m1=[x1(i) x2(i) x3(i); y1(i) y2(i) y3(i); 1 1 1]; 43 m2=[y1(i) y2(i) y3(i); z1(i) z2(i) z3(i); 1 1 1]; 44 m3=[z1(i) z2(i) z3(i); x1(i) x2(i) x3(i); 1 1 1]; 45 areas(i)=sqrt(det(m1)^2 + det(m2)^2 + det(m3)^2)/2; 46 end 47 end -
issm/trunk-jpl/src/m/interp/averaging.m
r17686 r25499 43 43 end 44 44 45 %load some variables (it is much faster if the variab es are loaded from md once for all)45 %load some variables (it is much faster if the variables are loaded from md once for all) 46 46 if layer==0, 47 47 index=md.mesh.elements; … … 87 87 end 88 88 89 %return output as a full matrix (C code do not like sparse matrices)89 %return output as a full matrix (C code does not like sparse matrices) 90 90 average=full(average_node); -
issm/trunk-jpl/src/m/interp/averaging.py
r24256 r25499 1 1 import numpy as np 2 from GetAreas import GetAreas3 2 try: 4 3 from scipy.sparse import csc_matrix … … 6 5 print("could not import scipy, no averaging capabilities enabled") 7 6 7 from GetAreas import GetAreas 8 8 9 9 10 def averaging(md, data, iterations, layer=0): 10 ''' 11 AVERAGING - smooths the input over the mesh 11 """AVERAGING - smooths the input over the mesh 12 12 13 This routine takes a list over the elements or the nodes in input14 and returna list over the nodes.15 For each iterations it computes the average over each element (average16 of the vertices values) and then computes the average over each node17 by taking the average of the element around a node weighted by the18 elements volume19 For 3d mesh, a last argument can be added to specify the layer to beaveraged on.13 This routine takes a list of the elements or the nodes in input and return 14 a list over the nodes. 15 For each iterations it computes the average over each element (average of 16 the vertices values) and then computes the average over each node by taking 17 the average of the element around a node weighted by the elements volume. 18 For 3d mesh, a last argument can be added to specify the layer to be 19 averaged on. 20 20 21 22 23 21 Usage: 22 smoothdata = averaging(md, data, iterations) 23 smoothdata = averaging(md, data, iterations, layer) 24 24 25 26 27 28 29 '''25 Examples: 26 velsmoothed = averaging(md, md.initialization.vel, 4) 27 pressure = averaging(md, md.initialization.pressure, 0) 28 temperature = averaging(md, md.initialization.temperature, 1, 1) 29 """ 30 30 31 31 if len(data) != md.mesh.numberofelements and len(data) != md.mesh.numberofvertices: … … 37 37 layer = 0 38 38 39 # initialization39 # Initialization 40 40 if layer == 0: 41 41 weights = np.zeros(md.mesh.numberofvertices, ) … … 45 45 data = data[(layer - 1) * md.mesh.numberofvertices2d + 1:layer * md.mesh.numberofvertices2d, :] 46 46 47 # load some variables (it is much faster if the variabes are loaded from md once for all)47 # Load some variables (it is much faster if the variables are loaded from md once for all) 48 48 if layer == 0: 49 49 index = md.mesh.elements … … 55 55 numberofelements = md.mesh.numberofelements2d 56 56 57 # build some variables57 # Build some variables 58 58 if md.mesh.dimension() == 3 and layer == 0: 59 59 rep = 6 … … 66 66 areas = GetAreas(index, md.mesh.x2d, md.mesh.y2d) 67 67 68 index = index - 1 # since python indexes startingfrom zero68 index = index - 1 # Python indexes from zero 69 69 line = index.flatten(1) 70 70 areas = np.vstack(areas).reshape(-1, ) … … 72 72 linesize = rep * numberofelements 73 73 74 # update weights that holds the volume of all the element holding the node i74 # Update weights that holds the volume of all the element holding the node i 75 75 weights = csc_matrix((np.tile(areas, (rep, 1)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1)) 76 76 77 # initialization77 # Initialization 78 78 if len(data) == numberofelements: 79 79 average_node = csc_matrix((np.tile(areas * data, (rep, 1)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1)) … … 83 83 average_node = csc_matrix(data.reshape(-1, 1)) 84 84 85 # loop over iteration85 # Loop over iteration 86 86 for i in np.arange(1, iterations + 1): 87 87 average_el = np.asarray(np.dot(average_node.todense()[index].reshape(numberofelements, rep), np.vstack(summation))).reshape(-1, ) … … 90 90 average_node = csc_matrix(average_node) 91 91 92 # return output as a full matrix (C code donot like sparse matrices)92 # Return output as a full matrix (C code does not like sparse matrices) 93 93 average = np.asarray(average_node.todense()).reshape(-1, ) 94 94 -
issm/trunk-jpl/src/m/mesh/TwoDToThreeD.m
r25455 r25499 1 1 function md=TwoDToThreeD(md,planet) 2 3 2 %reproject model into lat,long if necessary: 4 3 if ~strcmpi(md.mesh.proj,epsg2proj(4326)), -
issm/trunk-jpl/src/m/mesh/findsegments.m
r25457 r25499 66 66 %'el1' is connected to only one element 67 67 else 68 69 %find the vertex the 'el1' does not share with 'els2' 68 %find the vertex that 'el1' does not share with 'els2' 70 69 flag=setdiff(nods1,md.mesh.elements(els2,:)); 71 70 72 71 for j=1:3, 73 nods=nods1; nods(j)=[]; 72 nods=nods1; 73 nods(j)=[]; 74 74 if any(ismember(flag,nods)), 75 75 -
issm/trunk-jpl/src/m/mesh/findsegments.py
r25455 r25499 35 35 pos = np.nonzero(elementonboundary)[0] 36 36 num_segments = len(pos) 37 segments = np.zeros((num_segments, 3)) 37 segments = np.zeros((num_segments, 3)).astype(int) 38 38 count = 0 39 39 … … 56 56 57 57 # Get the vertices on the boundary and build segment 58 nods1 = np.delete(nods1, np.where(n ods1 == flag)[0])58 nods1 = np.delete(nods1, np.where(np.in1d(nods1, flag, assume_unique=True))) 59 59 segments[count, :] = np.append(nods1, el1 + 1) 60 60 … … 72 72 # 'el1' is connected to only one element 73 73 else: 74 # NOTE: This block is untested as it does not get touched by test2004 (remove this note once it has been tested) 75 74 76 # Find the vertex that 'el1' does not share with 'els2' 75 flag = els2 76 77 exit() 77 flag = np.setdiff1d(nods, md.mesh.elements[els2, :]) 78 79 for j in range(3): 80 nods = nods1 81 nods = np.delete(nods, j) 82 if np.any(np.in1d(flag, nods)): 83 segments[count, :] = np.append(nods, el1 + 1) 84 85 # Swap segment nodes if necessary 86 ord1 = np.where(nods1[0] == md.mesh.elements[el1, :])[0][0] 87 ord2 = np.where(nods1[1] == md.mesh.elements[el1, :])[0][0] 88 89 if ((ord1 == 0 and ord2 == 1) or (ord1 == 1 and ord2 == 2) or (ord1 == 2 and ord2 == 0)): 90 temp = segments[count, 0] 91 segments[count, 0] = segments[count, 1] 92 segments[count, 1] = temp 93 94 segments[count, 0:2] = np.flip(segments[count, 0:2]) # NOTE: Upper bound of index range is non-inclusive 95 count = count + 1 78 96 79 97 return segments -
issm/trunk-jpl/src/m/mesh/meshintersect3d.py
r25065 r25499 1 import math2 3 1 import matplotlib.pyplot as plt 4 2 from mpl_toolkits.mplot3d import Axes3D … … 9 7 10 8 def meshintersect3d(x, y, z, xs, ys, zs, *args): #{{{ 11 ''' 12 MESHINTERSECT - returns indices (into x, y, and z) of common values between 13 (x, y, z) and (xs, ys, zs) (i.e. x(index) = xs; y(index) = ys). 14 ''' 9 """MESHINTERSECT - returns indices (into x, y, and z) of common values 10 between (x, y, z) and (xs, ys, zs) (i.e. x(index) = xs; y(index) = ys). 11 """ 15 12 16 13 # Process options … … 19 16 # Retrieve tolerance 20 17 maxtol = options.getfieldvalue('maxtol', 100000) # 100 km 21 tolincrement = options.getfieldvalue('tolincrement', [])18 tolincrement = options.getfieldvalue('tolincrement', 10) 22 19 force = options.getfieldvalue('force', 0) 23 20 24 # Go through lats, longs and find within tolerance, the index of the corresponding value in lat, long25 indices = np.zeros( len(xs))21 # Go through lats, longs and find, within tolerance, the index of the corresponding value in lat, long 22 indices = np.zeros((len(xs), )) 26 23 27 24 for i in range(len(xs)): 28 25 tolerance = 0 29 distance = math.sqrt((x - xs[i]) ** 2 + (y - ys[i]) ** 2 + (z - zs[i]) ** 2) 26 distance = ((x - xs[i]) ** 2 + (y - ys[i]) ** 2 + (z - zs[i]) ** 2) ** 0.5 # NOTE: math.sqrt cannot be applied element-wise to a list/numpy.array 27 s = np.where(distance == 0)[0] 30 28 31 s = np.where(distance == 0)[0] 32 if s.size(): 33 if s.size() > 1: 29 if len(s): 30 if len(s) > 1: 34 31 # We have two vertices that are coincident! Not good 32 # 33 # TODO: Reconfigure the following in the process of bringing plotting online 35 34 for j in range(len(s)): 36 35 plot(x[s[j]], y[s[j]], z[s[j]], c='cyan', s=40) … … 46 45 # We could not find a 0 distance, find the lowest tolerance that generates a find 47 46 count = 1 48 while not s.size():47 while not len(s): 49 48 if count > 1000: 50 print('could not find a vertex matching vertex %i of input mesh!' % i) 51 print('Might think anbout changing tolerance increment') 52 raise RuntimeError('') 49 raise Exception('could not find a vertex matching vertex {} of input mesh!\nMight think anbout changing tolerance increment'.format(i)) 53 50 tolerance = tolerance + tolincrement 54 s = np.where(distance < tolerance) 51 s = np.where(distance < tolerance)[0] 55 52 count = count + 1 56 53 if tolerance > maxtol: 57 print('found matching vertices %i in output mesh for input mesh vertex %i' % (s, i)) 58 print('however, these vertices are farther than the max tolerance allowed!') 59 raise RuntimeError('') 54 raise Exception('found matching vertices {} in output mesh for input mesh vertex {}\nhowever, these vertices are farther than the max tolerance allowed!'.format(s, i)) 60 55 61 56 # Recover minimum distance 62 57 sf = distance[s] 63 pos = np.where(sf == sf.min())58 pos = np.where(sf == np.min(sf))[0] 64 59 s = s[pos] 65 60 indices[i] = s 66 61 67 if np.where(indices == 0).size():62 if len(np.where(indices == 0)[0]) > 1: # NOTE: This check is different than the corresponding one under MATLAB as one index may indeed be '0' 68 63 raise RuntimeError('issue with transition vector having one empty slot') 64 65 # Convert results to type 'int' to avoid modifying structures to which they are assigned 66 indices = indices.astype(int) 67 68 return indices 69 69 #}}} -
issm/trunk-jpl/src/m/mesh/modelmerge3d.py
r25455 r25499 112 112 113 113 # Vertex on boundary 114 md.mesh.vertexconnectivity = np.zeros((md.mesh.numberofvertices, )) 115 md.mesh.vertexonboundary[md.mesh.segments[:, 0:1]] = 1 116 print(md.mesh.vertexonboundary) 114 md.mesh.vertexonboundary = np.zeros((md.mesh.numberofvertices, )) 115 md.mesh.vertexonboundary[md.mesh.segments[:, 0:2] - 1] = 1 117 116 118 117 # Some checks … … 120 119 raise Exception('issue in modelmerge, one of the element ids is > number of vertices!') 121 120 122 exit()121 return md 123 122 124 123 -
issm/trunk-jpl/src/m/parameterization/contourenvelope.m
r19955 r25499 27 27 isfile=0; 28 28 else 29 error('contourenvelope error message: 29 error('contourenvelope error message: second argument should be a file or an elements flag'); 30 30 end 31 31 end -
issm/trunk-jpl/src/m/parameterization/contourenvelope.py
r25455 r25499 1 import copy 1 2 import os.path 2 3 import numpy as np 3 import copy 4 5 from ContourToMesh import ContourToMesh 6 from ElementConnectivity import ElementConnectivity 7 import MatlabFuncs as m 4 8 from NodeConnectivity import NodeConnectivity 5 from ElementConnectivity import ElementConnectivity6 from ContourToMesh import ContourToMesh7 import MatlabFuncs as m8 9 9 10 10 def contourenvelope(m d, *args):11 def contourenvelope(mh, *args): 11 12 """CONTOURENVELOPE - build a set of segments enveloping a contour .exp 12 13 13 14 Usage: 14 segments = contourenvelope(m d, varargin)15 segments = contourenvelope(mh, *args) 15 16 16 17 Example: 17 segments = contourenvelope(m d, 'Stream.exp')18 segments = contourenvelope(m d)18 segments = contourenvelope(mh, 'Stream.exp') 19 segments = contourenvelope(mh) 19 20 """ 20 21 21 #some checks 22 if len(args) > 1: 23 raise RuntimeError("contourenvelope error message: bad usage") 22 # Some checks 23 nargs = len(args) 24 24 25 if len(args) == 1: 25 if nargs > 1: 26 print(contourenvelope.__doc__) 27 raise Exception("contourenvelope error message: bad usage") 28 29 if nargs == 1: 26 30 flags = args[0] 27 31 … … 35 39 isfile = 0 36 40 else: 37 raise TypeError("contourenvelope error message: 41 raise TypeError("contourenvelope error message: second argument should be a file or an elements flag") 38 42 39 # Now, build the connectivity tables for this mesh.40 # Computing connectivity41 if np.size(m d.mesh.vertexconnectivity, axis=0) != md.mesh.numberofvertices and np.size(md.mesh.vertexconnectivity, axis=0) != md.mesh.numberofvertices2d:42 m d.mesh.vertexconnectivity = NodeConnectivity(md.mesh.elements, md.mesh.numberofvertices)43 if np.size(m d.mesh.elementconnectivity, axis=0) != md.mesh.numberofelements and np.size(md.mesh.elementconnectivity, axis=0) != md.mesh.numberofelements2d:44 m d.mesh.elementconnectivity = ElementConnectivity(md.mesh.elements, md.mesh.vertexconnectivity)43 # Now, build the connectivity tables for this mesh 44 # Computing connectivity 45 if np.size(mh.vertexconnectivity, axis=0) != mh.numberofvertices and np.size(mh.vertexconnectivity, axis=0) != mh.numberofvertices2d: 46 mh.vertexconnectivity = NodeConnectivity(mh.elements, mh.numberofvertices) 47 if np.size(mh.elementconnectivity, axis=0) != mh.numberofelements and np.size(mh.elementconnectivity, axis=0) != mh.numberofelements2d: 48 mh.elementconnectivity = ElementConnectivity(mh.elements, mh.vertexconnectivity) 45 49 46 50 #get nodes inside profile 47 elementconnectivity = copy.deepcopy(m d.mesh.elementconnectivity)48 if m d.mesh.dimension() == 2:49 elements = copy.deepcopy(m d.mesh.elements)50 x = copy.deepcopy(m d.mesh.x)51 y = copy.deepcopy(m d.mesh.y)52 numberofvertices = copy.deepcopy(m d.mesh.numberofvertices)53 numberofelements = copy.deepcopy(m d.mesh.numberofelements)51 elementconnectivity = copy.deepcopy(mh.elementconnectivity) 52 if mh.dimension() == 2: 53 elements = copy.deepcopy(mh.elements) 54 x = copy.deepcopy(mh.x) 55 y = copy.deepcopy(mh.y) 56 numberofvertices = copy.deepcopy(mh.numberofvertices) 57 numberofelements = copy.deepcopy(mh.numberofelements) 54 58 else: 55 elements = copy.deepcopy(m d.mesh.elements2d)56 x = copy.deepcopy(m d.mesh.x2d)57 y = copy.deepcopy(m d.mesh.y2d)58 numberofvertices = copy.deepcopy(m d.mesh.numberofvertices2d)59 numberofelements = copy.deepcopy(m d.mesh.numberofelements2d)59 elements = copy.deepcopy(mh.elements2d) 60 x = copy.deepcopy(mh.x2d) 61 y = copy.deepcopy(mh.y2d) 62 numberofvertices = copy.deepcopy(mh.numberofvertices2d) 63 numberofelements = copy.deepcopy(mh.numberofelements2d) 60 64 61 65 if len(args) == 1: 62 63 66 if isfile: 64 # get flag list of elements and nodes inside the contour67 # Get flag list of elements and nodes inside the contour 65 68 nodein = ContourToMesh(elements, x, y, file, 'node', 1) 66 69 elemin = (np.sum(nodein(elements), axis=1) == np.size(elements, axis=1)) 67 #modify element connectivity70 # Modify element connectivity 68 71 elemout = np.nonzero(np.logical_not(elemin))[0] 69 72 elementconnectivity[elemout, :] = 0 70 73 elementconnectivity[np.nonzero(m.ismember(elementconnectivity, elemout + 1))] = 0 71 74 else: 72 # get flag list of elements and nodes inside the contour75 # Get flag list of elements and nodes inside the contour 73 76 nodein = np.zeros(numberofvertices) 74 77 elemin = np.zeros(numberofelements) … … 78 81 nodein[elements[pos, :] - 1] = 1 79 82 80 #modify element connectivity83 # Modify element connectivity 81 84 elemout = np.nonzero(np.logical_not(elemin))[0] 82 85 elementconnectivity[elemout, :] = 0 83 86 elementconnectivity[np.nonzero(m.ismember(elementconnectivity, elemout + 1))] = 0 84 87 85 # Find element on boundary86 # First: find elements on the boundary of the domain88 # Find element on boundary 89 # First: find elements on the boundary of the domain 87 90 flag = copy.deepcopy(elementconnectivity) 88 91 if len(args) == 1: … … 90 93 elementonboundary = np.logical_and(np.prod(flag, axis=1) == 0, np.sum(flag, axis=1) > 0) 91 94 92 # Find segments on boundary95 # Find segments on boundary 93 96 pos = np.nonzero(elementonboundary)[0] 94 97 num_segments = np.size(pos) -
issm/trunk-jpl/src/m/solve/marshall.m
r25315 r25499 45 45 % % Uncomment the following to make a copy of the binary input file for debugging 46 46 % % purposes (can be fed into scripts/ReadBin.py). 47 %copyfile([md.miscellaneous.name '.bin'], [md.miscellaneous.name '.m.bin'])47 copyfile([md.miscellaneous.name '.bin'], [md.miscellaneous.name '.m.bin']) 48 48 if st==-1, 49 49 error(['marshall error message: could not close file ' [md.miscellaneous.name '.bin']]); -
issm/trunk-jpl/src/m/solve/marshall.py
r25315 r25499 44 44 # # Uncomment the following to make a copy of the binary input file for 45 45 # # debugging purposes (can be fed into scripts/ReadBin.py). 46 #copy_cmd = "cp {}.bin {}.py.bin".format(md.miscellaneous.name, md.miscellaneous.name)47 #subprocess.call(copy_cmd, shell=True)46 copy_cmd = "cp {}.bin {}.py.bin".format(md.miscellaneous.name, md.miscellaneous.name) 47 subprocess.call(copy_cmd, shell=True) 48 48 except IOError as e: 49 49 print("marshall error message: could not close file '{}.bin' due to:".format(md.miscellaneous.name), e) -
issm/trunk-jpl/src/m/solve/solve.py
r25300 r25499 12 12 13 13 def solve(md, solutionstring, *args): 14 ''' 15 SOLVE - apply solution sequence for this model 14 """SOLVE - apply solution sequence for this model 16 15 17 18 19 16 Usage: 17 md = solve(md, solutionstring, varargin) 18 where varargin is a list of paired arguments of string OR enums 20 19 21 20 solution types available comprise: … … 43 42 directory) where the restart file is located 44 43 45 46 47 48 '''44 Examples: 45 md = solve(md, 'Stressbalance') 46 md = solve(md, 'sb') 47 """ 49 48 50 49 #recover and process solve options -
issm/trunk-jpl/test/NightlyRun/test2004.m
r25455 r25499 93 93 94 94 %miscellaneous: 95 md.mesh.proj=bas.proj; md.miscellaneous.name=bas.name; 95 md.mesh.proj=bas.proj; 96 md.miscellaneous.name=bas.name; 96 97 97 98 %recover mask where we have land: … … 324 325 sl.caticecaps('tolerance',tolerance,'loneedgesdetect',loneedgesdetect); 325 326 326 %figure out how each icecap's mesh connects to the larger earth mesh:327 %figure out how each icecap's mesh connects to the larger Earth mesh: 327 328 sl.intersections('force',1); 328 329
Note:
See TracChangeset
for help on using the changeset viewer.