Changeset 26760
- Timestamp:
- 01/10/22 02:56:47 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/stochasticforcing.py
r26750 r26760 43 43 def setdefaultparameters(self): # {{{ 44 44 # Type of stabilization used 45 self.isstochasticforcing = 0 # stochasticforcing is turned off by default46 self.fields = [] # Need to initialize to list to avoid "RuntimeError: object of type 'float' has no len()" on import of class47 self.randomflag = 1 # true randomness is implemented by default45 self.isstochasticforcing = 0 # stochasticforcing is turned off by default 46 self.fields = [] # Need to initialize to list to avoid "RuntimeError: object of type 'float' has no len()" on import of class 47 self.randomflag = 1 # true randomness is implemented by default 48 48 return self 49 49 #}}} … … 63 63 64 64 # Check that all fields agree with the corresponding md class and if any field needs the default params 65 checkdefaults = False # Need to check defaults only if one of the fields does not have its own dimensionality65 checkdefaults = False # Need to check defaults only if one of the fields does not have its own dimensionality 66 66 structstoch = self.structstochforcing() 67 67 for field in self.fields: … … 91 91 if (type(md.friction).__name__ != mdname): 92 92 raise TypeError('stochasticforcing field {} is only implemented for default friction'.format(field)) 93 if (md.friction.coupling!=0 and md.friction.coupling!=1 and md.friction.coupling!=2):93 if md.friction.coupling not in[0, 1, 2]: 94 94 raise TypeError('stochasticforcing field {} is only implemented for cases md.friction.coupling 0 or 1 or 2'.format(field)) 95 if (np.any(md.friction.q ==0)):96 95 if (np.any(md.friction.q == 0)): 96 raise TypeError('stochasticforcing field {} requires non-zero q exponent'.format(field)) 97 97 98 98 # Checking for specific dimensions 99 if not (field == 'SMBautoregression' or field == 'FrontalForcingsRignotAutoregression'):100 checkdefaults = True # field with non-specific dimensionality99 if field not in['SMBautoregression', 'FrontalForcingsRignotAutoregression']: 100 checkdefaults = True # field with non-specific dimensionality 101 101 102 102 # Retrieve sum of all the field dimensionalities 103 103 size_tot = self.defaultdimension * num_fields 104 indSMBar = -1 # About to check for index of SMBautoregression105 indTFar = -1 # About to check for index of FrontalForcingsRignotAutoregression104 indSMBar = -1 # About to check for index of SMBautoregression 105 indTFar = -1 # About to check for index of FrontalForcingsRignotAutoregression 106 106 if ('SMBautoregression' in self.fields): 107 107 size_tot = size_tot - self.defaultdimension + md.smb.num_basins 108 indSMBar = self.fields.index('SMBautoregression') # Index of SMBar, now check for consistency with TFar timestep (08Nov2021)108 indSMBar = self.fields.index('SMBautoregression') # Index of SMBar, now check for consistency with TFar timestep (08Nov2021) 109 109 if ('FrontalForcingsRignotAutoregression' in self.fields): 110 110 size_tot = size_tot - self.defaultdimension + md.frontalforcings.num_basins 111 indTFar = self.fields.index('FrontalForcingsRignotAutoregression') # Index of TFar, now check for consistency with SMBar timestep (08Nov2021)112 if (indSMBar != -1 and indTFar != -1): # Both autoregressive models are used: check autoregressive time step consistency111 indTFar = self.fields.index('FrontalForcingsRignotAutoregression') # Index of TFar, now check for consistency with SMBar timestep (08Nov2021) 112 if (indSMBar != -1 and indTFar != -1): # Both autoregressive models are used: check autoregressive time step consistency 113 113 covsum = self.covariance[np.sum(self.defaultdimensions[0:indSMBar]).astype(int):np.sum(self.defaultdimensions[0:indSMBar + 1]).astype(int), np.sum(self.defaultdimensions[0:indTFar]).astype(int):np.sum(self.defaultdimensions[0:indTFar + 1]).astype(int)] 114 114 if((md.smb.ar_timestep != md.frontalforcings.ar_timestep) and np.any(covsum != 0)): … … 121 121 if (checkdefaults): 122 122 md = checkfield(md, 'fieldname', 'stochasticforcing.defaultdimension', 'numel', 1, 'NaN', 1, 'Inf', 1, '>', 0) 123 md = checkfield(md, 'fieldname', 'stochasticforcing.default_id', 'Inf',1,'NaN',1,'>=',0,'<=',self.defaultdimension,'size', [md.mesh.numberofelements])123 md = checkfield(md, 'fieldname', 'stochasticforcing.default_id', 'Inf', 1, 'NaN', 1, '>=', 0, '<=', self.defaultdimension, 'size', [md.mesh.numberofelements]) 124 124 return md 125 125 # }}} … … 139 139 else: 140 140 # Retrieve dimensionality of each field 141 dimensions = self.defaultdimension * np.ones((num_fields ,))141 dimensions = self.defaultdimension * np.ones((num_fields)) 142 142 for ind, field in enumerate(self.fields): 143 143 # Checking for specific dimensions … … 148 148 149 149 # Scaling covariance matrix (scale column-by-column and row-by-row) 150 scaledfields = ['DefaultCalving', 'FloatingMeltRate','SMBautoregression','SMBforcing']# list of fields that need scaling * 1/yts150 scaledfields = ['DefaultCalving', 'FloatingMeltRate', 'SMBautoregression', 'SMBforcing'] # list of fields that need scaling * 1/yts 151 151 tempcovariance = np.copy(self.covariance) 152 152 for i in range(num_fields): … … 161 161 self.default_id = np.zeros(md.mesh.numberofelements) 162 162 # Reshape dimensions as column array for marshalling 163 dimensions = dimensions.reshape(1, len(dimensions))163 dimensions = dimensions.reshape(1, len(dimensions)) 164 164 165 165 WriteData(fid, prefix, 'data', num_fields, 'name', 'md.stochasticforcing.num_fields', 'format', 'Integer') 166 166 WriteData(fid, prefix, 'object', self, 'fieldname', 'fields', 'format', 'StringArray') 167 WriteData(fid, prefix, 'data', dimensions, 'name', 'md.stochasticforcing.dimensions', 'format', 'IntMat', 'mattype',2)167 WriteData(fid, prefix, 'data', dimensions, 'name', 'md.stochasticforcing.dimensions', 'format', 'IntMat', 'mattype', 2) 168 168 WriteData(fid, prefix, 'object', self, 'fieldname', 'default_id', 'format', 'IntMat', 'mattype', 2) #12Nov2021 make sure this is zero-indexed! 169 169 WriteData(fid, prefix, 'object', self, 'fieldname', 'defaultdimension', 'format', 'Integer')
Note:
See TracChangeset
for help on using the changeset viewer.