- Timestamp:
- Jan 13, 2009, 11:51:22 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r6129 r6145 6 6 from domain import * 7 7 from anuga.config import epsilon 8 from Numeric import allclose, array, ones, Float 8 9 import Numeric as num 9 10 10 11 … … 95 96 #Centroids 96 97 q = domain.get_conserved_quantities(0) 97 assert allclose(q, [2., 2., 0.])98 assert num.allclose(q, [2., 2., 0.]) 98 99 99 100 q = domain.get_conserved_quantities(1) 100 assert allclose(q, [5., 5., 0.])101 assert num.allclose(q, [5., 5., 0.]) 101 102 102 103 q = domain.get_conserved_quantities(2) 103 assert allclose(q, [3., 3., 0.])104 assert num.allclose(q, [3., 3., 0.]) 104 105 105 106 q = domain.get_conserved_quantities(3) 106 assert allclose(q, [0., 0., 0.])107 assert num.allclose(q, [0., 0., 0.]) 107 108 108 109 109 110 #Edges 110 111 q = domain.get_conserved_quantities(0, edge=0) 111 assert allclose(q, [2.5, 2.5, 0.])112 assert num.allclose(q, [2.5, 2.5, 0.]) 112 113 q = domain.get_conserved_quantities(0, edge=1) 113 assert allclose(q, [2., 2., 0.])114 assert num.allclose(q, [2., 2., 0.]) 114 115 q = domain.get_conserved_quantities(0, edge=2) 115 assert allclose(q, [1.5, 1.5, 0.])116 assert num.allclose(q, [1.5, 1.5, 0.]) 116 117 117 118 for i in range(3): 118 119 q = domain.get_conserved_quantities(1, edge=i) 119 assert allclose(q, [5, 5, 0.])120 assert num.allclose(q, [5, 5, 0.]) 120 121 121 122 122 123 q = domain.get_conserved_quantities(2, edge=0) 123 assert allclose(q, [4.5, 4.5, 0.])124 assert num.allclose(q, [4.5, 4.5, 0.]) 124 125 q = domain.get_conserved_quantities(2, edge=1) 125 assert allclose(q, [4.5, 4.5, 0.])126 assert num.allclose(q, [4.5, 4.5, 0.]) 126 127 q = domain.get_conserved_quantities(2, edge=2) 127 assert allclose(q, [0., 0., 0.])128 assert num.allclose(q, [0., 0., 0.]) 128 129 129 130 130 131 q = domain.get_conserved_quantities(3, edge=0) 131 assert allclose(q, [3., 3., 0.])132 assert num.allclose(q, [3., 3., 0.]) 132 133 q = domain.get_conserved_quantities(3, edge=1) 133 assert allclose(q, [-1.5, -1.5, 0.])134 assert num.allclose(q, [-1.5, -1.5, 0.]) 134 135 q = domain.get_conserved_quantities(3, edge=2) 135 assert allclose(q, [-1.5, -1.5, 0.])136 assert num.allclose(q, [-1.5, -1.5, 0.]) 136 137 137 138 … … 179 180 Q = domain.create_quantity_from_expression(expression) 180 181 181 assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],182 [1,1,10], [-5, 4, 4]])182 assert num.allclose(Q.vertex_values, [[2,3,4], [6,6,6], 183 [1,1,10], [-5, 4, 4]]) 183 184 184 185 expression = '(xmomentum*xmomentum + ymomentum*ymomentum)**0.5' … … 188 189 Y = domain.quantities['ymomentum'].vertex_values 189 190 190 assert allclose(Q.vertex_values, (X**2 + Y**2)**0.5)191 assert num.allclose(Q.vertex_values, (X**2 + Y**2)**0.5) 191 192 192 193 … … 314 315 Q = domain.quantities['depth'] 315 316 316 assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],317 [1,1,10], [-5, 4, 4]])317 assert num.allclose(Q.vertex_values, [[2,3,4], [6,6,6], 318 [1,1,10], [-5, 4, 4]]) 318 319 319 320 … … 344 345 345 346 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')347 A = num.array([[1,2,3], [5,5,-5], [0,0,9], [-6,3,3]], 'f') 348 B = num.array([[2,4,4], [3,2,1], [6,-3,4], [4,5,-1]], 'f') 348 349 349 350 #print A … … 359 360 domain.set_quantity('elevation', A) 360 361 domain.add_quantity('elevation', B) 361 assert allclose(elevation.vertex_values, A+B)362 assert num.allclose(elevation.vertex_values, A+B) 362 363 363 364 domain.add_quantity('elevation', 4) 364 assert allclose(elevation.vertex_values, A+B+4)365 assert num.allclose(elevation.vertex_values, A+B+4) 365 366 366 367 … … 370 371 domain.set_quantity('depth', 1.0) 371 372 domain.add_quantity('depth', expression = 'stage - elevation') 372 assert allclose(depth.vertex_values, stage.vertex_values-elevation.vertex_values+1)373 assert num.allclose(depth.vertex_values, stage.vertex_values-elevation.vertex_values+1) 373 374 374 375 … … 376 377 reference = 2*stage.vertex_values - depth.vertex_values 377 378 domain.add_quantity('stage', expression = 'stage - depth') 378 assert allclose(stage.vertex_values, reference)379 assert num.allclose(stage.vertex_values, reference) 379 380 380 381 … … 388 389 389 390 domain.add_quantity('depth', f) 390 assert allclose(stage.vertex_values, depth.vertex_values)391 assert num.allclose(stage.vertex_values, depth.vertex_values) 391 392 392 393 … … 458 459 domain.check_integrity() 459 460 460 assert allclose(domain.neighbours, [[-1,-2,-3]])461 assert num.allclose(domain.neighbours, [[-1,-2,-3]]) 461 462 462 463 … … 547 548 [0,0,9], [-6, 3, 3]]) 548 549 549 assert allclose( domain.quantities['stage'].centroid_values,550 [2,5,3,0] )550 assert num.allclose( domain.quantities['stage'].centroid_values, 551 [2,5,3,0] ) 551 552 552 553 domain.set_quantity('xmomentum', [[1,1,1], [2,2,2], … … 560 561 561 562 #First order extrapolation 562 assert allclose( domain.quantities['stage'].vertex_values,563 [[ 2., 2., 2.],564 [ 5., 5., 5.],565 [ 3., 3., 3.],566 [ 0., 0., 0.]])563 assert num.allclose( domain.quantities['stage'].vertex_values, 564 [[ 2., 2., 2.], 565 [ 5., 5., 5.], 566 [ 3., 3., 3.], 567 [ 0., 0., 0.]]) 567 568 568 569 … … 603 604 604 605 for name in domain.conserved_quantities: 605 domain.quantities[name].explicit_update = array([4.,3.,2.,1.])606 domain.quantities[name].semi_implicit_update = array([1.,1.,1.,1.])606 domain.quantities[name].explicit_update = num.array([4.,3.,2.,1.]) 607 domain.quantities[name].semi_implicit_update = num.array([1.,1.,1.,1.]) 607 608 608 609 … … 611 612 domain.update_conserved_quantities() 612 613 613 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4])614 denom = ones(4,Float)-domain.timestep*sem614 sem = num.array([1.,1.,1.,1.])/num.array([1, 2, 3, 4]) 615 denom = num.ones(4, num.Float)-domain.timestep*sem 615 616 616 617 # x = array([1, 2, 3, 4]) + array( [.4,.3,.2,.1] ) 617 618 # x /= denom 618 619 619 x = array([1., 2., 3., 4.])620 x = num.array([1., 2., 3., 4.]) 620 621 x /= denom 621 x += domain.timestep* array( [4,3,2,1] )622 x += domain.timestep*num.array( [4,3,2,1] ) 622 623 623 624 for name in domain.conserved_quantities: 624 assert allclose(domain.quantities[name].centroid_values, x)625 assert num.allclose(domain.quantities[name].centroid_values, x) 625 626 626 627 … … 654 655 [0,0,9], [-6, 3, 3]]) 655 656 656 assert allclose( domain.quantities['stage'].centroid_values,657 [2,5,3,0] )657 assert num.allclose( domain.quantities['stage'].centroid_values, 658 [2,5,3,0] ) 658 659 659 660 domain.set_quantity('xmomentum', [[1,1,1], [2,2,2], … … 667 668 668 669 #First order extrapolation 669 assert allclose( domain.quantities['stage'].vertex_values,670 [[ 2., 2., 2.],671 [ 5., 5., 5.],672 [ 3., 3., 3.],673 [ 0., 0., 0.]])670 assert num.allclose( domain.quantities['stage'].vertex_values, 671 [[ 2., 2., 2.], 672 [ 5., 5., 5.], 673 [ 3., 3., 3.], 674 [ 0., 0., 0.]]) 674 675 675 676 domain.build_tagged_elements_dictionary({'mound':[0,1]}) … … 686 687 from mesh_factory import rectangular 687 688 from shallow_water import Domain 688 from Numeric import zeros, Float689 689 690 690 #Create basic mesh … … 703 703 from mesh_factory import rectangular 704 704 from shallow_water import Domain 705 from Numeric import zeros, Float706 705 707 706 #Create basic mesh … … 721 720 domain.set_region([set_bottom_friction, set_top_friction]) 722 721 #print domain.quantities['friction'].get_values() 723 assert allclose(domain.quantities['friction'].get_values(),\724 [[ 0.09, 0.09, 0.09],725 [ 0.09, 0.09, 0.09],726 [ 0.07, 0.07, 0.07],727 [ 0.07, 0.07, 0.07],728 [ 1.0, 1.0, 1.0],729 [ 1.0, 1.0, 1.0]])722 assert num.allclose(domain.quantities['friction'].get_values(),\ 723 [[ 0.09, 0.09, 0.09], 724 [ 0.09, 0.09, 0.09], 725 [ 0.07, 0.07, 0.07], 726 [ 0.07, 0.07, 0.07], 727 [ 1.0, 1.0, 1.0], 728 [ 1.0, 1.0, 1.0]]) 730 729 731 730 domain.set_region([set_all_friction]) 732 731 #print domain.quantities['friction'].get_values() 733 assert allclose(domain.quantities['friction'].get_values(),734 [[ 10.09, 10.09, 10.09],735 [ 10.09, 10.09, 10.09],736 [ 10.07, 10.07, 10.07],737 [ 10.07, 10.07, 10.07],738 [ 11.0, 11.0, 11.0],739 [ 11.0, 11.0, 11.0]])732 assert num.allclose(domain.quantities['friction'].get_values(), 733 [[ 10.09, 10.09, 10.09], 734 [ 10.09, 10.09, 10.09], 735 [ 10.07, 10.07, 10.07], 736 [ 10.07, 10.07, 10.07], 737 [ 11.0, 11.0, 11.0], 738 [ 11.0, 11.0, 11.0]]) 740 739 741 740 … … 746 745 from mesh_factory import rectangular 747 746 from shallow_water import Domain 748 from Numeric import zeros, Float749 747 750 748 #Create basic mesh … … 766 764 767 765 #print domain.quantities['friction'].get_values() 768 assert allclose(domain.quantities['friction'].get_values(),\769 [[ 0.09, 0.09, 0.09],770 [ 0.09, 0.09, 0.09],771 [ 0.07, 0.07, 0.07],772 [ 0.07, 0.07, 0.07],773 [ 1.0, 1.0, 1.0],774 [ 1.0, 1.0, 1.0]])766 assert num.allclose(domain.quantities['friction'].get_values(), 767 [[ 0.09, 0.09, 0.09], 768 [ 0.09, 0.09, 0.09], 769 [ 0.07, 0.07, 0.07], 770 [ 0.07, 0.07, 0.07], 771 [ 1.0, 1.0, 1.0], 772 [ 1.0, 1.0, 1.0]]) 775 773 776 774 domain.set_region([set_bottom_friction, set_top_friction]) 777 775 #print domain.quantities['friction'].get_values() 778 assert allclose(domain.quantities['friction'].get_values(),\779 [[ 0.09, 0.09, 0.09],780 [ 0.09, 0.09, 0.09],781 [ 0.07, 0.07, 0.07],782 [ 0.07, 0.07, 0.07],783 [ 1.0, 1.0, 1.0],784 [ 1.0, 1.0, 1.0]])776 assert num.allclose(domain.quantities['friction'].get_values(), 777 [[ 0.09, 0.09, 0.09], 778 [ 0.09, 0.09, 0.09], 779 [ 0.07, 0.07, 0.07], 780 [ 0.07, 0.07, 0.07], 781 [ 1.0, 1.0, 1.0], 782 [ 1.0, 1.0, 1.0]]) 785 783 786 784 domain.set_region([set_all_friction]) 787 785 #print domain.quantities['friction'].get_values() 788 assert allclose(domain.quantities['friction'].get_values(),789 [[ 10.09, 10.09, 10.09],790 [ 10.09, 10.09, 10.09],791 [ 10.07, 10.07, 10.07],792 [ 10.07, 10.07, 10.07],793 [ 11.0, 11.0, 11.0],794 [ 11.0, 11.0, 11.0]])786 assert num.allclose(domain.quantities['friction'].get_values(), 787 [[ 10.09, 10.09, 10.09], 788 [ 10.09, 10.09, 10.09], 789 [ 10.07, 10.07, 10.07], 790 [ 10.07, 10.07, 10.07], 791 [ 11.0, 11.0, 11.0], 792 [ 11.0, 11.0, 11.0]]) 795 793 796 794 #-------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.