- Timestamp:
- Oct 4, 2006, 11:00:56 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r3678 r3689 110 110 [4.5, 4.5, 0.], 111 111 [3.0, -1.5, -1.5]]) 112 113 def test_get_maximum_1(self): 114 quantity = Conserved_quantity(self.mesh4, 115 [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]]) 116 assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroids 117 118 v = quantity.get_maximum_value() 119 assert v == 5 120 121 i = quantity.get_maximum_index() 122 assert i == 1 123 124 x,y = quantity.get_maximum_location() 125 xref, yref = 4.0/3, 4.0/3 126 assert x == xref 127 assert y == yref 128 129 v = quantity.get_values(interpolation_points = [[x,y]]) 130 assert allclose(v, 5) 131 132 def test_get_maximum_2(self): 133 134 a = [0.0, 0.0] 135 b = [0.0, 2.0] 136 c = [2.0,0.0] 137 d = [0.0, 4.0] 138 e = [2.0, 2.0] 139 f = [4.0,0.0] 140 141 points = [a, b, c, d, e, f] 142 #bac, bce, ecf, dbe 143 vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 144 145 domain = Domain(points, vertices) 146 147 quantity = Quantity(domain) 148 quantity.set_values(lambda x, y: x+2*y) #2 4 4 6 149 150 v = quantity.get_maximum_value() 151 assert v == 6 152 153 i = quantity.get_maximum_index() 154 assert i == 3 155 156 x,y = quantity.get_maximum_location() 157 xref, yref = 2.0/3, 8.0/3 158 assert x == xref 159 assert y == yref 160 161 v = quantity.get_values(interpolation_points = [[x,y]]) 162 assert allclose(v, 6) 163 164 165 #Multiple locations for maximum - 166 #Test that the algorithm picks the first occurrence 167 v = quantity.get_maximum_value(indices=[0,1,2]) 168 assert allclose(v, 4) 169 170 i = quantity.get_maximum_index(indices=[0,1,2]) 171 assert i == 1 172 173 x,y = quantity.get_maximum_location(indices=[0,1,2]) 174 xref, yref = 4.0/3, 4.0/3 175 assert x == xref 176 assert y == yref 177 178 v = quantity.get_values(interpolation_points = [[x,y]]) 179 assert allclose(v, 4) 180 181 # More test of indices...... 182 v = quantity.get_maximum_value(indices=[2,3]) 183 assert allclose(v, 6) 184 185 i = quantity.get_maximum_index(indices=[2,3]) 186 assert i == 3 187 188 x,y = quantity.get_maximum_location(indices=[2,3]) 189 xref, yref = 2.0/3, 8.0/3 190 assert x == xref 191 assert y == yref 192 193 v = quantity.get_values(interpolation_points = [[x,y]]) 194 assert allclose(v, 6) 195 196 112 197 113 198 def test_boundary_allocation(self): … … 1389 1474 # quantity.get_values(location = 'centroids') 1390 1475 1476 1477 1478 1479 def test_get_values_2(self): 1480 """Different mesh (working with domain object) - also check centroids. 1481 """ 1482 1483 1484 a = [0.0, 0.0] 1485 b = [0.0, 2.0] 1486 c = [2.0,0.0] 1487 d = [0.0, 4.0] 1488 e = [2.0, 2.0] 1489 f = [4.0,0.0] 1490 1491 points = [a, b, c, d, e, f] 1492 #bac, bce, ecf, dbe 1493 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 1494 1495 domain = Domain(points, vertices) 1496 1497 quantity = Quantity(domain) 1498 quantity.set_values(lambda x, y: x+2*y) #2 4 4 6 1499 1500 assert allclose(quantity.get_values(location='centroids'), [2,4,4,6]) 1501 assert allclose(quantity.get_values(location='centroids', indices=[1,3]), [4,6]) 1502 1503 1504 assert allclose(quantity.get_values(location='vertices'), [[4,0,2], 1505 [4,2,6], 1506 [6,2,4], 1507 [8,4,6]]) 1508 1509 assert allclose(quantity.get_values(location='vertices', indices=[1,3]), [[4,2,6], 1510 [8,4,6]]) 1511 1512 1513 assert allclose(quantity.get_values(location='edges'), [[1,3,2], 1514 [4,5,3], 1515 [3,5,4], 1516 [5,7,6]]) 1517 assert allclose(quantity.get_values(location='edges', indices=[1,3]), 1518 [[4,5,3], 1519 [5,7,6]]) 1520 1521 # Check averaging over vertices 1522 #a: 0 1523 #b: (4+4+4)/3 1524 #c: (2+2+2)/3 1525 #d: 8 1526 #e: (6+6+6)/3 1527 #f: 4 1528 assert(quantity.get_values(location='unique vertices'), [0, 4, 2, 8, 6, 4]) 1529 1530 1531 1532 1533 1534 1535 def test_get_interpolated_values(self): 1536 1537 from mesh_factory import rectangular 1538 from shallow_water import Domain 1539 from Numeric import zeros, Float 1540 1541 #Create basic mesh 1542 points, vertices, boundary = rectangular(1, 3) 1543 domain = Domain(points, vertices, boundary) 1544 1545 #Constant values 1546 quantity = Quantity(domain,[[0,0,0],[1,1,1],[2,2,2],[3,3,3], 1547 [4,4,4],[5,5,5]]) 1548 1549 1550 1551 # Get interpolated values at centroids 1552 interpolation_points = domain.get_centroid_coordinates() 1553 answer = quantity.get_values(location='centroids') 1554 1555 1556 #print quantity.get_values(points=interpolation_points) 1557 assert allclose(answer, quantity.get_values(interpolation_points=interpolation_points)) 1558 1559 1560 #Arbitrary values 1561 quantity = Quantity(domain,[[0,1,2],[3,1,7],[2,1,2],[3,3,7], 1562 [1,4,-9],[2,5,0]]) 1563 1564 1565 # Get interpolated values at centroids 1566 interpolation_points = domain.get_centroid_coordinates() 1567 answer = quantity.get_values(location='centroids') 1568 #print answer 1569 #print quantity.get_values(points=interpolation_points) 1570 assert allclose(answer, quantity.get_values(interpolation_points=interpolation_points)) 1571 1572 1573 #FIXME TODO 1574 #indices = [0,5,3] 1575 #answer = [0.5,1,5] 1576 #assert allclose(answer, 1577 # quantity.get_values(indices=indices, \ 1578 # location = 'unique vertices')) 1579 1580 1581 1582 1583 def test_get_interpolated_values_2(self): 1584 a = [0.0, 0.0] 1585 b = [0.0, 2.0] 1586 c = [2.0,0.0] 1587 d = [0.0, 4.0] 1588 e = [2.0, 2.0] 1589 f = [4.0,0.0] 1590 1591 points = [a, b, c, d, e, f] 1592 #bac, bce, ecf, dbe 1593 vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 1594 1595 domain = Domain(points, vertices) 1596 1597 quantity = Quantity(domain) 1598 quantity.set_values(lambda x, y: x+2*y) #2 4 4 6 1599 1600 #First pick one point 1601 x, y = 2.0/3, 8.0/3 1602 v = quantity.get_values(interpolation_points = [[x,y]]) 1603 assert allclose(v, 6) 1604 1605 # Then another to test that algorithm won't blindly 1606 # reuse interpolation matrix 1607 x, y = 4.0/3, 4.0/3 1608 v = quantity.get_values(interpolation_points = [[x,y]]) 1609 assert allclose(v, 4) 1610 1611 1612 1613 1391 1614 def test_getting_some_vertex_values(self): 1392 1615 """
Note: See TracChangeset
for help on using the changeset viewer.