Changeset 206
- Timestamp:
- Aug 23, 2004, 4:36:00 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/quantity.py
r205 r206 298 298 299 299 300 def set_values(self, values, location='vertices'):300 def set_values(self, X, location='vertices'): 301 301 """Set values for quantity 302 302 303 values: Compatible list or Numeric array (see below)303 X: Compatible list, Numeric array (see below), constant or function 304 304 location: Where values are to be stored. 305 305 Permissible options are: vertices, edges, centroid … … 312 312 The values will be stored in elements following their 313 313 internal ordering. 314 315 If values are described a function, it will be evaluated at specified points 314 316 315 317 If selected location is vertices, values for centroid and edges … … 319 321 """ 320 322 321 #FIXME: Should take functions as argument as well 322 #FIXME: Should take constants as well 323 323 324 #FIXME: Should do location erro check here only 325 326 327 import types 328 329 if callable(X): 330 #Use function specific method 331 self.set_function_values(X, location) 332 elif type(X) in [types.FloatType, types.IntType, types.LongType]: 333 if location == 'vertices': 334 self.vertex_values[:] = X 335 elif location == 'edges': 336 self.edge_values[:] = X 337 elif location == 'centroids': 338 self.centroid_values[:] = X 339 else: 340 raise 'Invalid location: %s' %location 341 else: 342 #Use array specific method 343 self.set_array_values(X, location) 344 345 346 def set_function_values(self, f, location='vertices'): 347 """Set values for quantity using specified function 348 349 f: x, y -> z Function where x, y and z are arrays 350 location: Where values are to be stored. 351 Permissible options are: vertices, edges, centroid 352 Default is "vertices" 353 """ 354 355 356 if location == 'vertices': 357 V = self.domain.get_vertex_coordinates() 358 359 for i in range(3): 360 self.set_values(f(V[:,2*i], V[:,2*i+1]), location) 361 elif location == 'edges': 362 raise 'Not yet implemented' 363 elif location == 'centroids': 364 V = self.domain.centroids 365 self.set_values(f(V[:,0], V[:,1]), location) 366 else: 367 raise 'Invalid location: %s' %location 368 369 370 def set_array_values(self, values, location='vertices'): 371 """Set values for quantity 372 373 values: Numeric array 374 location: Where values are to be stored. 375 Permissible options are: vertices, edges, centroid 376 Default is "vertices" 377 378 In case of location == 'centroid' the dimension values must 379 be a list of a Numerical array of length N, N being the number 380 of elements in the mesh. Otherwise it must be of dimension Nx3 381 382 The values will be stored in elements following their 383 internal ordering. 384 385 If selected location is vertices, values for centroid and edges 386 will be assigned interpolated values. 387 In any other case, only values for the specified locations 388 will be assigned and the others will be left undefined. 389 """ 390 324 391 from Numeric import array, Float 325 392
Note: See TracChangeset
for help on using the changeset viewer.