[777] | 1 | """Simple example of shallow water wave equation using Pyvolution |
---|
| 2 | |
---|
| 3 | Water driven by linear slope and Dirichlet boundary |
---|
| 4 | |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | ###################### |
---|
| 8 | # Module imports |
---|
| 9 | # |
---|
[1853] | 10 | from pyvolution.mesh_factory import rectangular |
---|
| 11 | from pyvolution.shallow_water import Domain, Reflective_boundary,\ |
---|
[2156] | 12 | Dirichlet_boundary, Time_boundary, Transmissive_boundary |
---|
[777] | 13 | |
---|
[2288] | 14 | #Create basic triangular mesh |
---|
[2438] | 15 | points, vertices, boundary = rectangular(2, 1) |
---|
[777] | 16 | |
---|
| 17 | #Create shallow water domain |
---|
| 18 | domain = Domain(points, vertices, boundary) |
---|
[2288] | 19 | domain.set_name('bedslope') |
---|
[2320] | 20 | domain.set_datadir('.') #Use current directory for output |
---|
| 21 | domain.set_quantities_to_be_stored('stage') #See shallow_water.py |
---|
[777] | 22 | |
---|
[2288] | 23 | |
---|
[777] | 24 | ####################### |
---|
[2155] | 25 | # Initial conditions |
---|
[2156] | 26 | def f(x,y): |
---|
| 27 | return -x/2 |
---|
| 28 | |
---|
| 29 | domain.set_quantity('elevation', f) |
---|
[777] | 30 | domain.set_quantity('friction', 0.1) |
---|
| 31 | |
---|
[2155] | 32 | h = 0.05 # Constant depth |
---|
| 33 | domain.set_quantity('stage', expression = 'elevation + %f' %h) |
---|
[777] | 34 | |
---|
[2155] | 35 | |
---|
[777] | 36 | ###################### |
---|
| 37 | # Boundary conditions |
---|
| 38 | from math import sin, pi |
---|
| 39 | Br = Reflective_boundary(domain) |
---|
| 40 | Bt = Transmissive_boundary(domain) |
---|
| 41 | Bd = Dirichlet_boundary([0.2,0.,0.]) |
---|
| 42 | Bw = Time_boundary(domain=domain, |
---|
| 43 | f=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0]) |
---|
| 44 | |
---|
[2155] | 45 | |
---|
[2320] | 46 | print 'Tags are ', domain.get_boundary_tags() |
---|
| 47 | |
---|
[777] | 48 | domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
[2155] | 49 | #domain.set_boundary({'left': Bw, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
[777] | 50 | |
---|
| 51 | |
---|
| 52 | ###################### |
---|
[2155] | 53 | #Evolution |
---|
[777] | 54 | domain.check_integrity() |
---|
| 55 | |
---|
[2438] | 56 | for t in domain.evolve(yieldstep = 0.1, finaltime = 0.2): |
---|
[777] | 57 | domain.write_time() |
---|
| 58 | |
---|