Changeset 6129
 Timestamp:
 Jan 9, 2009, 2:47:16 PM (14 years ago)
 Location:
 anuga_core/source/anuga/abstract_2d_finite_volumes
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r6127 r6129 30 30 from anuga.utilities.polygon import inside_polygon 31 31 from anuga.abstract_2d_finite_volumes.util import get_textual_float 32 33 from Numeric import zeros, Float, Int, ones 34 from quantity import Quantity 32 35 33 36 import types … … 105 108 106 109 if verbose: print 'Initialising Domain' 107 from Numeric import zeros, Float, Int, ones108 from quantity import Quantity109 110 110 111 # List of quantity names entering … … 374 375 # Assign values 375 376 self.quantities[name].set_values(*args, **kwargs) 376 377 378 def add_quantity(self, name, *args, **kwargs): 379 """Add values to a named quantity 380 381 E.g add_quantity('elevation', X) 382 383 Option are the same as in set_quantity. 384 """ 385 386 # Do the expression stuff 387 if kwargs.has_key('expression'): 388 expression = kwargs['expression'] 389 Q2 = self.create_quantity_from_expression(expression) 390 else: 391 # Create new temporary quantity 392 Q2 = Quantity(self) 393 394 # Assign specified values to temporary quantity 395 Q2.set_values(*args, **kwargs) 396 397 # Add temporary quantity to named quantity 398 Q1 = self.get_quantity(name) 399 self.set_quantity(name, Q1 + Q2) 400 377 401 378 402 def get_quantity_names(self): 
anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r5897 r6129 319 319 320 320 321 322 def test_add_quantity(self): 323 """Test that quantities already set can be added to using 324 add_quantity 325 326 """ 327 328 329 a = [0.0, 0.0] 330 b = [0.0, 2.0] 331 c = [2.0,0.0] 332 d = [0.0, 4.0] 333 e = [2.0, 2.0] 334 f = [4.0,0.0] 335 336 points = [a, b, c, d, e, f] 337 #bac, bce, ecf, dbe, daf, dae 338 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 339 340 domain = Domain(points, vertices, boundary=None, 341 conserved_quantities =\ 342 ['stage', 'xmomentum', 'ymomentum'], 343 other_quantities = ['elevation', 'friction', 'depth']) 344 345 346 A = array([[1,2,3], [5,5,5], [0,0,9], [6,3,3]], 'f') 347 B = array([[2,4,4], [3,2,1], [6,3,4], [4,5,1]], 'f') 348 349 #print A 350 #print B 351 #print A+B 352 353 # Shorthands 354 stage = domain.quantities['stage'] 355 elevation = domain.quantities['elevation'] 356 depth = domain.quantities['depth'] 357 358 # Go testing 359 domain.set_quantity('elevation', A) 360 domain.add_quantity('elevation', B) 361 assert allclose(elevation.vertex_values, A+B) 362 363 domain.add_quantity('elevation', 4) 364 assert allclose(elevation.vertex_values, A+B+4) 365 366 367 # Test using expression 368 domain.set_quantity('stage', [[1,2,3], [5,5,5], 369 [0,0,9], [6, 3, 3]]) 370 domain.set_quantity('depth', 1.0) 371 domain.add_quantity('depth', expression = 'stage  elevation') 372 assert allclose(depth.vertex_values, stage.vertex_valueselevation.vertex_values+1) 373 374 375 # Check self referential expression 376 reference = 2*stage.vertex_values  depth.vertex_values 377 domain.add_quantity('stage', expression = 'stage  depth') 378 assert allclose(stage.vertex_values, reference) 379 380 381 # Test using a function 382 def f(x, y): 383 return x+y 384 385 domain.set_quantity('elevation', f) 386 domain.set_quantity('stage', 5.0) 387 domain.set_quantity('depth', expression = 'stage  elevation') 388 389 domain.add_quantity('depth', f) 390 assert allclose(stage.vertex_values, depth.vertex_values) 391 392 393 394 395 396 321 397 def test_setting_timestepping_method(self): 322 398 """test_set_quanitities_to_be_monitored
Note: See TracChangeset
for help on using the changeset viewer.