Changeset 8852
- Timestamp:
- Apr 26, 2013, 9:04:35 PM (12 years ago)
- Location:
- trunk/anuga_core/source/anuga/operators
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/operators/rate_operators.py
r8850 r8852 92 92 rate = self.get_spatial_rate(x,y,t) 93 93 else: 94 rate = self.get_ rate(t)94 rate = self.get_non_spatial_rate(t) 95 95 96 96 if self.verbose is True: … … 113 113 + factor*rate*timestep, self.elev_c[indices]) 114 114 115 def get_rate(self, t=None): 115 116 def get_non_spatial_rate(self, t=None): 116 117 """Provide a rate to calculate added volume 117 118 """ … … 175 176 y = self.coord_c[:,1] 176 177 178 #print x.shape,y.shape 179 assert isinstance(t, (int, float)) 180 assert len(x) == len(y) 181 177 182 #print xy 178 183 #print t … … 274 279 def timestepping_statistics(self): 275 280 276 message = indent + self.label + ': Rate = ' + str(self.get_rate()) 281 if self.rate_spatial: 282 rate = self.get_spatial_rate() 283 min_rate = num.min(rate) 284 max_rate = num.max(rate) 285 message = indent + self.label + ': Min rate = %g, Max rate = %g '% (min_rate,max_rate) 286 else: 287 message = indent + self.label + ': Rate = ' + str(self.get_non_spatial_rate()) 288 289 277 290 return message 278 291 -
trunk/anuga_core/source/anuga/operators/test_rate_operators.py
r8850 r8852 420 420 421 421 # Apply operator to these triangles 422 factor = 10.0 423 424 425 def main_spatial_rate(x,y,t): 426 # x and y should be an n by 1 array 427 return x + y 428 429 default_rate = 0.0 430 431 432 operator = Rate_operator(domain, rate=main_spatial_rate, factor=factor, \ 433 default_rate = default_rate) 434 435 436 # Apply Operator 437 domain.timestep = 2.0 438 operator() 439 440 t = operator.get_time() 441 x = operator.coord_c[:,0] 442 y = operator.coord_c[:,1] 443 d = operator.get_timestep()*main_spatial_rate(x,y,t)*factor + 1 444 445 #print "d" 446 #print d 447 stage_ex = num.array([ 1.0, 1.0, 1.0, 1.0]) 448 stage_ex[:] = d 449 450 if verbose: 451 print domain.quantities['elevation'].centroid_values 452 print domain.quantities['stage'].centroid_values 453 print domain.quantities['xmomentum'].centroid_values 454 print domain.quantities['ymomentum'].centroid_values 455 456 assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) 457 assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) 458 assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) 459 460 def test_rate_operator_functions_spatial_indices(self): 461 from anuga.config import rho_a, rho_w, eta_w 462 from math import pi, cos, sin 463 464 a = [0.0, 0.0] 465 b = [0.0, 2.0] 466 c = [2.0, 0.0] 467 d = [0.0, 4.0] 468 e = [2.0, 2.0] 469 f = [4.0, 0.0] 470 471 points = [a, b, c, d, e, f] 472 # bac, bce, ecf, dbe 473 vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 474 475 domain = Domain(points, vertices) 476 477 #Flat surface with 1m of water 478 domain.set_quantity('elevation', 0.0) 479 domain.set_quantity('stage', 1.0) 480 domain.set_quantity('friction', 0.0) 481 482 Br = Reflective_boundary(domain) 483 domain.set_boundary({'exterior': Br}) 484 485 verbose = False 486 487 if verbose: 488 print domain.quantities['elevation'].centroid_values 489 print domain.quantities['stage'].centroid_values 490 print domain.quantities['xmomentum'].centroid_values 491 print domain.quantities['ymomentum'].centroid_values 492 493 # Apply operator to these triangles 422 494 indices = [0,1,3] 423 495 factor = 10.0 … … 458 530 assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) 459 531 assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) 460 461 532 462 533 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.