[229] | 1 | """Example of shallow water wave equation. |
---|
| 2 | |
---|
| 3 | Generate slope |
---|
| 4 | |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | ###################### |
---|
| 8 | # Module imports |
---|
| 9 | # |
---|
[660] | 10 | from os import sep, path |
---|
[229] | 11 | from mesh_factory import rectangular |
---|
| 12 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
[659] | 13 | Constant_height |
---|
[229] | 14 | from Numeric import array |
---|
[659] | 15 | from util import Polygon_function, read_polygon |
---|
[229] | 16 | |
---|
[901] | 17 | |
---|
[229] | 18 | #Create basic mesh |
---|
[664] | 19 | N = 50 |
---|
[659] | 20 | points, vertices, boundary = rectangular(N, N, 100, 100) |
---|
[229] | 21 | |
---|
| 22 | #Create shallow water domain |
---|
| 23 | domain = Domain(points, vertices, boundary) |
---|
[483] | 24 | domain.store = True |
---|
[659] | 25 | domain.set_name('polygons') |
---|
[901] | 26 | print "Output being written to " + domain.get_datadir() + sep + \ |
---|
[664] | 27 | domain.filename + "_size%d." %len(domain) + domain.format |
---|
[660] | 28 | |
---|
| 29 | |
---|
[659] | 30 | domain.default_order=2 |
---|
[229] | 31 | |
---|
[483] | 32 | #Set driving forces |
---|
| 33 | manning = 0.07 |
---|
| 34 | manning = 0.0 |
---|
[773] | 35 | inflow_stage = 10.0 |
---|
[483] | 36 | domain.set_quantity('friction', manning) |
---|
[229] | 37 | |
---|
[664] | 38 | def wiggle(x, y): |
---|
| 39 | from Numeric import sin |
---|
| 40 | from math import pi |
---|
| 41 | return 10 + sin(2*pi*x/10) |
---|
[483] | 42 | |
---|
[664] | 43 | def slope(x, y): |
---|
| 44 | return 20*(x/100+y/100) |
---|
[505] | 45 | |
---|
[659] | 46 | #Define polynomials |
---|
| 47 | p0 = [[20,27], [30,25], [40,40], [20,40]] |
---|
| 48 | p1 = [[80,19], [90,20], [85,50], [80,55], [75,58], [70,60], [60,24]] |
---|
| 49 | p2 = read_polygon('testpoly.txt') |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | #Set elevation |
---|
| 53 | domain.set_quantity('elevation', |
---|
[664] | 54 | Polygon_function([(p0,slope), (p1,wiggle), (p2,15)])) |
---|
[773] | 55 | #domain.set_quantity('stage', |
---|
[664] | 56 | # Polygon_function([(p0,slope), (p1,wiggle), (p2,15)])) |
---|
[659] | 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | |
---|
[229] | 63 | ###################### |
---|
| 64 | # Boundary conditions |
---|
| 65 | Br = Reflective_boundary(domain) |
---|
[773] | 66 | Bd = Dirichlet_boundary([inflow_stage,0.,0.]) |
---|
[229] | 67 | |
---|
| 68 | domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
| 69 | domain.check_integrity() |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | ###################### |
---|
| 73 | #Evolution |
---|
[659] | 74 | for t in domain.evolve(yieldstep = 1, finaltime = 1): |
---|
[229] | 75 | domain.write_time() |
---|
| 76 | |
---|
[483] | 77 | print 'Done' |
---|
| 78 | |
---|