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.visualise = True |
---|
22 | domain.default_order=2 |
---|
23 | |
---|
24 | ####################### |
---|
25 | #Bed-slope and friction |
---|
26 | def x_slope(x, y): |
---|
27 | return -x/3 |
---|
28 | |
---|
29 | #domain.set_quantity('elevation', x_slope) |
---|
30 | domain.set_quantity('elevation', lambda x,y: -x/3) |
---|
31 | domain.set_quantity('friction', 0.1) |
---|
32 | |
---|
33 | |
---|
34 | ###################### |
---|
35 | # Boundary conditions |
---|
36 | |
---|
37 | |
---|
38 | #Write file |
---|
39 | import os, time |
---|
40 | from config import time_format |
---|
41 | from math import sin, pi |
---|
42 | |
---|
43 | finaltime = 100 |
---|
44 | filename = 'bed_w_boundary.bdry' |
---|
45 | fid = open(filename, 'w') |
---|
46 | start = time.mktime(time.strptime('2000', '%Y')) |
---|
47 | dt = 5 #Five second intervals |
---|
48 | t = 0.0 |
---|
49 | while t <= finaltime: |
---|
50 | t_string = time.strftime(time_format, time.gmtime(t+start)) |
---|
51 | fid.write('%s, %f %f %f\n' %(t_string, 10*sin(t*0.1*pi), 0.0, 0.0)) |
---|
52 | |
---|
53 | t += dt |
---|
54 | |
---|
55 | fid.close() |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | Br = Reflective_boundary(domain) |
---|
60 | Bd = Dirichlet_boundary([0.2,0.,0.]) |
---|
61 | Bw = Time_boundary(domain=domain, |
---|
62 | f=lambda t: [(10*sin(t*0.1*pi)), 0.0, 0.0]) |
---|
63 | |
---|
64 | Bf = File_boundary(filename, domain) |
---|
65 | |
---|
66 | #domain.set_boundary({'left': Bw, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
67 | domain.set_boundary({'left': Bf, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
68 | |
---|
69 | |
---|
70 | ###################### |
---|
71 | #Initial condition |
---|
72 | h = 0.5 |
---|
73 | h = 0.0 |
---|
74 | domain.set_quantity('stage', Constant_height(x_slope, h)) |
---|
75 | |
---|
76 | domain.check_integrity() |
---|
77 | |
---|
78 | |
---|
79 | ###################### |
---|
80 | #Evolution |
---|
81 | for t in domain.evolve(yieldstep = 1, finaltime = 100.0): |
---|
82 | domain.write_time() |
---|
83 | |
---|