Changeset 460
- Timestamp:
- Oct 28, 2004, 4:22:55 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/quantity.py
r459 r460 240 240 raise msg 241 241 242 #FIXME - roll this back into set_array_values, if possible243 def set_array_values_by_index(self, values, location='vertices', indexes = None):244 from Numeric import array, Float, Int245 246 values = array(values).astype(Float)247 248 if not (indexes == None):249 indexes = array(indexes).astype(Int)250 251 N = self.centroid_values.shape[0]252 253 if location == 'centroids':254 assert len(values.shape) == 1, 'Values array must be 1d'255 256 if indexes == None:257 msg = 'Number of values must match number of elements'258 assert values.shape[0] == N, msg259 260 self.centroid_values = values261 else:262 msg = 'Number of values must match number of indexes'263 assert values.shape[0] == indexes.shape[0], msg264 265 #Brute force266 for i in range(len(indexes)):267 self.centroid_values[indexes[i]] = values[i]268 269 242 270 243 # FIXME have a get_vertex_values as well, so the 'level' quantity can be … … 299 272 #Intialise centroid and edge_values 300 273 self.interpolate() 274 301 275 302 def set_some_vertex_values(self, A, indexes):303 """Set vertex values for some triangles based on input array A304 which is assumed to have one entry per (unique) vertex, i.e.305 one value for each row in array self.domain.coordinates.306 """307 308 from Numeric import array, Float309 310 #Assert that A can be converted to a Numeric array of appropriate dim311 A = array(A, Float)312 msg = 'Number of values must match number of indexes'313 assert A.shape[0] == len(indexes), msg314 if (len(A.shape) == 2):315 assert A.shape[0] == len(indexes), msg316 msg = 'Each vertex must have a list of three values, or one value'317 assert A.shape[1] == 3, msg318 elif (len(A.shape) <> 1):319 msg = 'vertex values must be 1D or 2D.'320 raise msg321 322 #Go through list of triangles323 #FIXME This is brute force. Can it be optimised?324 for element_index, value in map(None, indexes, A):325 if len(A.shape) == 2:326 self.vertex_values[element_index] = value327 else:328 self.vertex_values[element_index, 0] = value329 self.vertex_values[element_index, 1] = value330 self.vertex_values[element_index, 2] = value331 332 #Intialise centroid and edge_values333 self.interpolate()334 335 336 276 def smooth_vertex_values(self, value_array='field_values', 337 277 precision = None):
Note: See TracChangeset
for help on using the changeset viewer.