Changeset 7815 for anuga_work/development/anuga_1d/quantity.py
- Timestamp:
- Jun 9, 2010, 5:34:19 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/anuga_1d/quantity.py
r7793 r7815 271 271 self.centroid_values[i] = (v0 + v1)/2.0 272 272 273 274 275 273 276 def set_values(self, X, location='vertices'): 274 277 """Set values for quantity … … 294 297 """ 295 298 296 if location not in ['vertices', 'centroids' ]:297 msg = 'Invalid location: %s, (possible choices vertices, centroids )' %location299 if location not in ['vertices', 'centroids', 'unique_vertices']: 300 msg = 'Invalid location: %s, (possible choices vertices, centroids, unique_vertices)' %location 298 301 raise msg 299 302 … … 309 312 310 313 elif type(X) in [types.FloatType, types.IntType, types.LongType]: 311 if location == 'centroids': 312 self.centroid_values[:] = X 313 else: 314 self.vertex_values[:] = X 314 315 self.centroid_values[:,] = float(X) 316 self.vertex_values[:,:] = float(X) 317 318 elif isinstance(X, Quantity): 319 self.set_array_values(X.vertex_values, location) 315 320 316 321 else: … … 318 323 self.set_array_values(X, location) 319 324 320 if location == 'vertices' :321 #Intialise centroid and edge values325 if location == 'vertices' or location == 'unique_vertices': 326 #Intialise centroid 322 327 self.interpolate() 328 329 if location == 'centroid': 330 self.extrapolate_first_order() 323 331 324 332 … … 353 361 values: Numeric array 354 362 location: Where values are to be stored. 355 Permissible options are: vertices, centroid, edges363 Permissible options are: vertices, centroid, unique_vertices 356 364 Default is "vertices" 357 365 358 366 In case of location == 'centroid' the dimension values must 359 367 be a list of a Numerical array of length N, N being the number 360 of elements in the mesh. Otherwise it must be of dimension Nx2 368 of elements in the mesh. If location == 'unique_vertices' the 369 dimension values must be a list or a Numeric array of length N+1. 370 Otherwise it must be of dimension Nx2 361 371 362 372 The values will be stored in elements following their … … 375 385 N = self.centroid_values.shape[0] 376 386 377 msg = 'Number of values must match number of elements'378 assert values.shape[0] == N, msg379 387 380 388 if location == 'centroids': 389 msg = 'Number of values must match number of elements' 390 assert values.shape[0] == N, msg 381 391 assert len(values.shape) == 1, 'Values array must be 1d' 382 self.centroid_values = values 383 #elif location == 'edges': 384 # assert len(values.shape) == 2, 'Values array must be 2d' 385 # msg = 'Array must be N x 2' 386 # self.edge_values = values 387 else: 392 393 for i in range(N): 394 self.centroid_values[i] = values[i] 395 396 self.vertex_values[:,0] = values 397 self.vertex_values[:,1] = values 398 399 if location == 'vertices': 400 msg = 'Number of values must match number of elements' 401 assert values.shape[0] == N, msg 388 402 assert len(values.shape) == 2, 'Values array must be 2d' 389 403 msg = 'Array must be N x 2' 390 404 assert values.shape[1] == 2, msg 391 405 392 self.vertex_values[:] = values 406 self.vertex_values[:,:] = values[:,:] 407 408 if location == 'unique_vertices': 409 msg = 'Number of values must match number of elements +1' 410 assert values.shape[0] == N+1, msg 411 assert len(values.shape) == 1, 'Values array must be 1d' 412 413 self.vertex_values[:,0] = values[0:-1] 414 self.vertex_values[:,1] = values[1:N+1] 415 416 417 393 418 394 419
Note: See TracChangeset
for help on using the changeset viewer.