Changeset 1007
- Timestamp:
- Mar 4, 2005, 4:58:03 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/shallow_water.py
r998 r1007 696 696 wv = domain.quantities['stage'].vertex_values 697 697 zv = domain.quantities['elevation'].vertex_values 698 hv = wv -zv698 hv = wv - zv 699 699 700 700 #Call C-extension 701 701 from shallow_water_ext import h_limiter 702 h _limiter(domain, hc, hv)703 704 return hv 702 hvbar = h_limiter(domain, hc, hv) 703 704 return hvbar 705 705 706 706 -
inundation/ga/storm_surge/pyvolution/shallow_water_ext.c
r1000 r1007 239 239 alpha = 1.0; //Flat bed 240 240 241 //printf("dz = %.3f, alpha = %.8f\n", dz, alpha); 241 242 242 243 // Let … … 743 744 PyArrayObject 744 745 *hv, *hc, //Depth at vertices and centroids 745 //*hvbar, //Limited depth at vertices (return values) FIXME: Not used?746 *hvbar, //Limited depth at vertices (return values) FIXME: Not used? 746 747 *neighbours; 747 748 748 749 int k, i, n, N, k3; 749 //int dimensions[2];750 int dimensions[2]; 750 751 double beta_h; //Safety factor (see config.py) 751 752 double *hmin, *hmax, hn; … … 769 770 770 771 //Create hvbar 771 //dimensions[0] = N;772 //dimensions[1] = 3;773 //hvbar = (PyArrayObject *) PyArray_FromDims(2, dimensions, PyArray_DOUBLE);772 dimensions[0] = N; 773 dimensions[1] = 3; 774 hvbar = (PyArrayObject *) PyArray_FromDims(2, dimensions, PyArray_DOUBLE); 774 775 775 776 … … 785 786 for (i=0; i<3; i++) { 786 787 n = ((long*) neighbours -> data)[k3+i]; 787 //((double*) hvbar -> data)[k3+i] = ((double*) hc -> data)[k]; 788 789 //Initialise hvbar with valus from hv 790 ((double*) hvbar -> data)[k3+i] = ((double*) hv -> data)[k3+i]; 791 788 792 if (n >= 0) { 789 793 hn = ((double*) hc -> data)[n]; //Neighbour's centroid value … … 796 800 797 801 // Call underlying routine 798 _limit(N, beta_h, (double*) hc -> data, (double*) hv -> data, hmin, hmax);802 _limit(N, beta_h, (double*) hc -> data, (double*) hvbar -> data, hmin, hmax); 799 803 800 804 // // //Py_DECREF(domain); //FIXME: NEcessary? … … 803 807 804 808 //return result using PyArray to avoid memory leak 805 //return PyArray_Return(hvbar);806 return Py_BuildValue("");809 return PyArray_Return(hvbar); 810 //return Py_BuildValue(""); 807 811 } 808 812 -
inundation/ga/storm_surge/pyvolution/test_shallow_water.py
r907 r1007 1445 1445 assert allclose(X[1,:], [0.0143507718962, 0.0142502147066, 0.00931268339717]) 1446 1446 assert allclose(Y[1,:], [-0.000117062180693, 7.94434448109e-005, -0.000151505429018]) 1447 1447 1448 1449 1450 def test_balance_deep_and_shallow(self): 1451 """Test that balanced limiters preserve conserved quantites. 1452 """ 1453 import copy 1454 1455 a = [0.0, 0.0] 1456 b = [0.0, 2.0] 1457 c = [2.0, 0.0] 1458 d = [0.0, 4.0] 1459 e = [2.0, 2.0] 1460 f = [4.0, 0.0] 1461 1462 points = [a, b, c, d, e, f] 1463 1464 #bac, bce, ecf, dbe 1465 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 1466 1467 mesh = Domain(points, elements) 1468 mesh.check_integrity() 1469 1470 #Create a deliberate overshoot 1471 mesh.set_quantity('stage', [[3,0,3], [2,2,6], [5,3,8], [8,3,5]]) 1472 mesh.set_quantity('elevation', 0) #Flat bed 1473 stage = mesh.quantities['stage'] 1474 1475 ref_centroid_values = copy.copy(stage.centroid_values[:]) #Copy 1476 1477 #Limit 1478 mesh.distribute_to_vertices_and_edges() 1479 1480 #Assert that quantities are conserved 1481 from Numeric import sum 1482 for k in range(mesh.number_of_elements): 1483 assert allclose (ref_centroid_values[k], 1484 sum(stage.vertex_values[k,:])/3) 1485 1486 1487 #Now try with a non-flat bed - closely hugging initial stage in places 1488 #This will create alphas in the range [0, 0.478260, 1] 1489 mesh.set_quantity('stage', [[3,0,3], [2,2,6], [5,3,8], [8,3,5]]) 1490 mesh.set_quantity('elevation', [[0,0,0], 1491 [1.8,1.9,5.9], 1492 [4.6,0,0], 1493 [0,2,4]]) 1494 stage = mesh.quantities['stage'] 1495 1496 ref_centroid_values = copy.copy(stage.centroid_values[:]) #Copy 1497 ref_vertex_values = copy.copy(stage.vertex_values[:]) #Copy 1498 1499 #Limit 1500 mesh.distribute_to_vertices_and_edges() 1501 1502 1503 #Assert that all vertex quantities have changed 1504 for k in range(mesh.number_of_elements): 1505 #print ref_vertex_values[k,:], stage.vertex_values[k,:] 1506 assert not allclose (ref_vertex_values[k,:], stage.vertex_values[k,:]) 1507 #and assert that quantities are still conserved 1508 from Numeric import sum 1509 for k in range(mesh.number_of_elements): 1510 assert allclose (ref_centroid_values[k], 1511 sum(stage.vertex_values[k,:])/3) 1512 1513 1514 #Also check that Python and C version produce the same 1515 assert allclose (stage.vertex_values, 1516 [[2,2,2], 1517 [1.93333333, 2.03333333, 6.03333333], 1518 [6.93333333, 4.53333333, 4.53333333], 1519 [5.33333333, 5.33333333, 5.33333333]]) 1520 1521 1522 1523 1448 1524 1449 1525 def test_second_order_flat_bed_onestep(self): … … 2693 2769 if __name__ == "__main__": 2694 2770 suite = unittest.makeSuite(TestCase,'test') 2695 #suite = unittest.makeSuite(TestCase,'test_ spatio_temporal_boundary_2')2771 #suite = unittest.makeSuite(TestCase,'test_balance_deep_and_shallow') 2696 2772 runner = unittest.TextTestRunner() 2697 2773 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.