[4713] | 1 | """Example of shallow water wave equation. |
---|
| 2 | |
---|
| 3 | Generate slope |
---|
| 4 | |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | ###################### |
---|
| 8 | # Module imports |
---|
| 9 | # |
---|
| 10 | from mesh_factory import rectangular |
---|
| 11 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
| 12 | Constant_height, Time_boundary, File_boundary |
---|
| 13 | from Numeric import array |
---|
| 14 | |
---|
| 15 | #Create basic mesh |
---|
| 16 | points, vertices, boundary = rectangular(10, 10, 100, 100) |
---|
| 17 | |
---|
| 18 | #Create shallow water domain |
---|
| 19 | domain = Domain(points, vertices, boundary) |
---|
| 20 | domain.smooth = False |
---|
| 21 | domain.default_order=2 |
---|
| 22 | |
---|
| 23 | ####################### |
---|
| 24 | #Bed-slope and friction |
---|
| 25 | def x_slope(x, y): |
---|
| 26 | return -x/3 |
---|
| 27 | |
---|
| 28 | #domain.set_quantity('elevation', x_slope) |
---|
| 29 | domain.set_quantity('elevation', lambda x,y: -x/3) |
---|
| 30 | domain.set_quantity('friction', 0.1) |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | ###################### |
---|
| 34 | # Boundary conditions |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | #Write file |
---|
| 38 | import os, time |
---|
| 39 | from anuga.config import time_format |
---|
| 40 | from math import sin, pi |
---|
| 41 | |
---|
| 42 | finaltime = 100 |
---|
| 43 | filename = 'bed_w_boundary' |
---|
| 44 | fid = open(filename + '.txt', 'w') |
---|
| 45 | start = time.mktime(time.strptime('2000', '%Y')) |
---|
| 46 | dt = 5 #Five second intervals |
---|
| 47 | t = 0.0 |
---|
| 48 | while t <= finaltime: |
---|
| 49 | t_string = time.strftime(time_format, time.gmtime(t+start)) |
---|
| 50 | fid.write('%s, %f %f %f\n' %(t_string, 10*sin(t*0.1*pi), 0.0, 0.0)) |
---|
| 51 | |
---|
| 52 | t += dt |
---|
| 53 | |
---|
| 54 | fid.close() |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | #Convert ASCII file to NetCDF (Which is what we really like!) |
---|
| 58 | from anuga.pyvolution.data_manager import timefile2swww |
---|
| 59 | timefile2swww(filename, quantity_names = domain.conserved_quantities) |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | Br = Reflective_boundary(domain) |
---|
| 63 | Bd = Dirichlet_boundary([0.2,0.,0.]) |
---|
| 64 | Bw = Time_boundary(domain=domain, |
---|
| 65 | f=lambda t: [(10*sin(t*0.1*pi)), 0.0, 0.0]) |
---|
| 66 | |
---|
| 67 | Bf = File_boundary(filename + '.sww', domain) |
---|
| 68 | |
---|
| 69 | #domain.set_boundary({'left': Bw, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
| 70 | domain.set_boundary({'left': Bf, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | ###################### |
---|
| 74 | #Initial condition |
---|
| 75 | h = 0.5 |
---|
| 76 | h = 0.0 |
---|
| 77 | domain.set_quantity('stage', Constant_height(x_slope, h)) |
---|
| 78 | |
---|
| 79 | domain.check_integrity() |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | ###################### |
---|
| 83 | #Evolution |
---|
| 84 | for t in domain.evolve(yieldstep = 1, finaltime = 100.0): |
---|
| 85 | domain.write_time() |
---|
| 86 | |
---|