1 | """Example of shallow water wave equation |
---|
2 | using time boundary from a file |
---|
3 | """ |
---|
4 | |
---|
5 | ###################### |
---|
6 | # Module imports |
---|
7 | # |
---|
8 | from mesh_factory import rectangular |
---|
9 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
10 | Constant_height, Time_boundary, File_boundary |
---|
11 | from Numeric import array, ones |
---|
12 | |
---|
13 | #Create basic mesh (100m x 100m) |
---|
14 | points, vertices, boundary = rectangular(50, 50, 100, 100) |
---|
15 | |
---|
16 | #Create shallow water domain |
---|
17 | domain = Domain(points, vertices, boundary) |
---|
18 | domain.smooth = False |
---|
19 | domain.visualise = False |
---|
20 | domain.default_order = 2 |
---|
21 | domain.store = True #Store for visualisation purposes |
---|
22 | domain.format = 'sww' #Native netcdf visualisation format |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | ####################### |
---|
27 | #Bed-slope and friction |
---|
28 | domain.set_quantity('elevation', 0.0) #Flat |
---|
29 | #domain.set_quantity('elevation', lambda x,y: -(x+y)/3) #Slopy |
---|
30 | domain.set_quantity('friction', 0.1) |
---|
31 | |
---|
32 | |
---|
33 | ###################### |
---|
34 | # Boundary conditions |
---|
35 | |
---|
36 | |
---|
37 | #Write file |
---|
38 | import os, time |
---|
39 | from config import time_format |
---|
40 | from math import sin, pi |
---|
41 | |
---|
42 | filename = 'Eden_Australia_31082004.txt' |
---|
43 | |
---|
44 | Br = Reflective_boundary(domain) |
---|
45 | Bd = Dirichlet_boundary([1. ,0.,0.]) |
---|
46 | Bw = Time_boundary(domain=domain, |
---|
47 | f=lambda t: [(1*sin(t*pi/20)), 0.0, 0.0]) |
---|
48 | |
---|
49 | Bf = File_boundary(filename, domain) |
---|
50 | |
---|
51 | #domain.set_boundary({'left': Bw, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
52 | domain.set_boundary({'left': Bf, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
53 | |
---|
54 | |
---|
55 | ###################### |
---|
56 | #Initial condition (constant) |
---|
57 | domain.set_quantity('stage', 0.0) |
---|
58 | domain.check_integrity() |
---|
59 | |
---|
60 | |
---|
61 | ###################### |
---|
62 | #Evolution |
---|
63 | for t in domain.evolve(yieldstep = 60, finaltime = 385*15*60): |
---|
64 | domain.write_time() |
---|
65 | |
---|