Changeset 989
- Timestamp:
- Mar 2, 2005, 5:49:23 PM (20 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/analytical solutions/Analytical_solution_Yoon_import_mesh.py
r774 r989 4 4 and used by Yoon and Chou. 5 5 6 Copyright 200 47 Christopher Zoppou, Stephen Roberts, Ole Nielsen , Duncan Gray8 Geoscience Australia6 Copyright 2005 7 Christopher Zoppou, Stephen Roberts, Ole Nielsen 8 ANU, Geoscience Australia 9 9 10 10 """ 11 11 12 # #####################12 #--------------- 13 13 # Module imports 14 14 import sys 15 15 from os import sep 16 16 sys.path.append('..'+sep+'pyvolution') 17 18 17 from shallow_water import Domain, Dirichlet_boundary 19 18 from math import sqrt, cos, sin, pi 20 19 from mesh_factory import strang_mesh 20 from util import inside_polygon 21 from Numeric import asarray 22 from least_squares import Interpolation 21 23 22 23 ###################### 24 # Domain 25 # Strang_domain will search through the file and test to see if there are 26 # two or three entries. Two entries are for points and three for triangles. 27 24 #------------------------------- 25 # Set up the domain of triangles 26 # Strang_domain will search 27 # through the file and test to 28 # see if there are two or three 29 # entries. Two entries are for 30 # points and three for triangles. 28 31 points, elements = strang_mesh('yoon_circle.pt') 29 32 domain = Domain(points, elements) 30 33 34 #---------------- 35 # Order of scheme 31 36 domain.default_order = 2 37 32 38 domain.smooth = True 33 39 34 40 #------------------------------------- 35 41 # Provide file name for storing output 36 domain.store = True42 domain.store = False 37 43 domain.format = 'sww' 38 domain.filename = 'yoon_strang_second_order' 39 44 domain.filename = 'yoon_mesh_second_order.2' 40 45 print 'Number of triangles = ', len(domain) 41 46 42 #Reduction operation for get_vertex_values 47 #---------------------------------------------------------- 48 # Decide which quantities are to be stored at each timestep 49 domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] 50 51 #------------------------------------------ 52 # Reduction operation for get_vertex_values 43 53 from util import mean 44 domain.reduction = mean 45 #domain.reduction = min #Looks better near steep slopes 54 domain.reduction = mean #domain.reduction = min #Looks better near steep slopes 46 55 47 56 48 ###################### 49 #Initial condition 50 # 57 #------------------ 58 # Initial condition 51 59 print 'Initial condition' 52 60 t = 0.0 … … 58 66 A = (L**4 - R0**4)/(L**4 + R0**4) 59 67 omega = 2./L*sqrt(2.*g*D0) 60 print 'omega = ',omega61 68 T = pi/omega 62 print T63 69 64 65 # Set bed-elevation and friction(None)70 #------------------ 71 # Set bed elevation 66 72 def x_slope(x,y): 67 73 n = x.shape[0] … … 71 77 z[i] = -D0*(1.-r*r/L/L) 72 78 return z 73 74 79 domain.set_quantity('elevation', x_slope) 75 80 76 #Set the initial water stage 77 def stage(x,y): 81 #---------------------------- 82 # Set the initial water level 83 def level(x,y): 78 84 z = x_slope(x,y) 79 85 n = x.shape[0] … … 86 92 h[i] = z[i] 87 93 return h 88 89 domain.set_quantity('stage', stage) 94 domain.set_quantity('stage', level) 90 95 91 96 92 ############ 93 #Boundary 97 #--------- 98 # Boundary 99 print 'Boundary conditions' 94 100 domain.set_boundary({'exterior': Dirichlet_boundary([0.0, 0.0, 0.0])}) 101 102 #--------------------------------------------- 103 # Find triangle that contains the point points 104 # and print to file 105 points = [0.,0.] 106 for n in range(len(domain.triangles)): 107 t = domain.triangles[n] 108 tri = [domain.coordinates[t[0]],domain.coordinates[t[1]],domain.coordinates[t[2]]] 109 110 if inside_polygon(points,tri): 111 print 'Point is within triangle with vertices '+'%s'%tri 112 n_point = n 113 t = domain.triangles[n_point] 114 tri = [domain.coordinates[t[0]],domain.coordinates[t[1]],domain.coordinates[t[2]]] 115 116 filename=domain.filename 117 file = open(filename,'w') 95 118 96 97 ###################### 98 #Evolution 119 #---------- 120 # Evolution 99 121 import time 100 122 t0 = time.time() 101 for t in domain.evolve(yieldstep = 10.0, finaltime = 5000):123 for t in domain.evolve(yieldstep = 20.0, finaltime = 3000 ): 102 124 domain.write_time() 103 125 126 tri_array = asarray(tri) 127 t_array = asarray([[0,1,2]]) 128 interp = Interpolation(tri_array,t_array,[points]) 129 130 stage = domain.get_quantity('stage')[n_point] 131 xmomentum = domain.get_quantity('xmomentum')[n_point] 132 ymomentum = domain.get_quantity('ymomentum')[n_point] 133 134 interp_stage = interp.interpolate([[stage[0]],[stage[1]],[stage[2]]]) 135 interp_xmomentum = interp.interpolate([[xmomentum[0]],[xmomentum[1]],[xmomentum[2]]]) 136 interp_ymomentum = interp.interpolate([[ymomentum[0]],[ymomentum[1]],[ymomentum[2]]]) 137 138 file.write( '%10.6f %10.6f %10.6f %10.6f\n'%(t,interp_stage[0][0],interp_xmomentum[0][0],interp_ymomentum[0][0]) ) 139 140 file.close() 104 141 print 'That took %.2f seconds' %(time.time()-t0) 105 106 -
inundation/ga/storm_surge/pyvolution-1d/quantity.py
r513 r989 446 446 Q1.limit() 447 447 448 from matplotlib.matlab import *448 from pylab import * 449 449 plot(Xc,Qc) 450 450 -
inundation/ga/storm_surge/pyvolution/shallow_water.py
r955 r989 59 59 Generic_domain = Domain #Rename 60 60 61 #Shalow water domain 61 62 class Domain(Generic_domain): 62 63 … … 435 436 #Update optimal_timestep 436 437 try: 437 timestep = min(timestep, domain.radii[k]/max_speed)438 timestep = min(timestep, 0.5*domain.radii[k]/max_speed) 438 439 except ZeroDivisionError: 439 440 pass … … 1501 1502 1502 1503 1504 1505 def compute_fluxes_python(domain): 1506 """Compute all fluxes and the timestep suitable for all volumes 1507 in domain. 1508 1509 Compute total flux for each conserved quantity using "flux_function" 1510 1511 Fluxes across each edge are scaled by edgelengths and summed up 1512 Resulting flux is then scaled by area and stored in 1513 explicit_update for each of the three conserved quantities 1514 stage, xmomentum and ymomentum 1515 1516 The maximal allowable speed computed by the flux_function for each volume 1517 is converted to a timestep that must not be exceeded. The minimum of 1518 those is computed as the next overall timestep. 1519 1520 Post conditions: 1521 domain.explicit_update is reset to computed flux values 1522 domain.timestep is set to the largest step satisfying all volumes. 1523 """ 1524 1525 import sys 1526 from Numeric import zeros, Float 1527 1528 N = domain.number_of_elements 1529 1530 #Shortcuts 1531 Stage = domain.quantities['stage'] 1532 Xmom = domain.quantities['xmomentum'] 1533 Ymom = domain.quantities['ymomentum'] 1534 Bed = domain.quantities['elevation'] 1535 1536 #Arrays 1537 stage = Stage.edge_values 1538 xmom = Xmom.edge_values 1539 ymom = Ymom.edge_values 1540 bed = Bed.edge_values 1541 1542 stage_bdry = Stage.boundary_values 1543 xmom_bdry = Xmom.boundary_values 1544 ymom_bdry = Ymom.boundary_values 1545 1546 flux = zeros((N,3), Float) #Work array for summing up fluxes 1547 1548 #Loop 1549 timestep = float(sys.maxint) 1550 for k in range(N): 1551 1552 for i in range(3): 1553 #Quantities inside volume facing neighbour i 1554 ql = [stage[k, i], xmom[k, i], ymom[k, i]] 1555 zl = bed[k, i] 1556 1557 #Quantities at neighbour on nearest face 1558 n = domain.neighbours[k,i] 1559 if n < 0: 1560 m = -n-1 #Convert negative flag to index 1561 qr = [stage_bdry[m], xmom_bdry[m], ymom_bdry[m]] 1562 zr = zl #Extend bed elevation to boundary 1563 else: 1564 m = domain.neighbour_edges[k,i] 1565 qr = [stage[n, m], xmom[n, m], ymom[n, m]] 1566 zr = bed[n, m] 1567 1568 1569 #Outward pointing normal vector 1570 normal = domain.normals[k, 2*i:2*i+2] 1571 1572 #Flux computation using provided function 1573 edgeflux, max_speed = flux_function(normal, ql, qr, zl, zr) 1574 1575 flux[k,:] = edgeflux 1576 1577 return flux 1578 1579 1580 1581 1582 1583 1584 1503 1585 ############################################## 1504 1586 #Initialise module … … 1519 1601 1520 1602 #distribute_to_vertices_and_edges = distribute_to_vertices_and_edges_c 1603 1521 1604 1522 1605 -
inundation/ga/storm_surge/pyvolution/shallow_water_ext.c
r907 r989 626 626 //timestep = min(timestep, domain.radii[k]/max_speed) 627 627 if (max_speed > epsilon) { 628 timestep = min(timestep, ((double *) radii -> data)[k]/max_speed);628 timestep = min(timestep, 0.5*((double *) radii -> data)[k]/max_speed); 629 629 } 630 630 } // end for i … … 767 767 hvbar = (PyArrayObject *) PyArray_FromDims(2, dimensions, PyArray_DOUBLE); 768 768 769 769 770 770 771 //Find min and max of this and neighbour's centroid values 771 772 hmin = malloc(N * sizeof(double)); … … 779 780 for (i=0; i<3; i++) { 780 781 n = ((long*) neighbours -> data)[k3+i]; 782 ((double*) hvbar -> data)[k3+i] = ((double*) hc -> data)[k]; 781 783 if (n >= 0) { 782 784 hn = ((double*) hc -> data)[n]; //Neighbour's centroid value -
inundation/ga/storm_surge/pyvolution/util.py
r969 r989 1016 1016 Polygon_function(polygons) 1017 1017 1018 where polygons is a dictionaryof the form1019 1020 {P0: v0, P1: v1, ...}1018 where polygons is a list of tuples of the form 1019 1020 [ (P0, v0), (P1, v1), ...] 1021 1021 1022 1022 with Pi being lists of vertices defining polygons and vi either
Note: See TracChangeset
for help on using the changeset viewer.