1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Benchmark problem from teh third International Workshop on Long-Wave |
---|
4 | Runup Models |
---|
5 | http://www.cee.cornell.edu/longwave/index.cfm?page=benchmark&problem=3 |
---|
6 | |
---|
7 | """ |
---|
8 | |
---|
9 | |
---|
10 | #------------------------------------------------------------------------------ |
---|
11 | # Import necessary modules |
---|
12 | #------------------------------------------------------------------------------ |
---|
13 | |
---|
14 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular |
---|
15 | from anuga.shallow_water import Domain |
---|
16 | from anuga.shallow_water import Reflective_boundary |
---|
17 | from anuga.shallow_water import Dirichlet_boundary |
---|
18 | from anuga.shallow_water import Time_boundary |
---|
19 | from anuga.shallow_water import Transmissive_boundary |
---|
20 | |
---|
21 | |
---|
22 | #------------------------------------------------------------------------------ |
---|
23 | # Setup computational domain |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
26 | bounding_polygon = [[0,10],[10,10],[10,0],[0,0]] |
---|
27 | remainder_res = 0.25 |
---|
28 | meshname = 'test.msh' |
---|
29 | create_mesh_from_regions(bounding_polygon, |
---|
30 | boundary_tags={'top': [0], |
---|
31 | 'right': [1], |
---|
32 | 'bottom': [2], |
---|
33 | 'left': [3]}, |
---|
34 | maximum_triangle_area=remainder_res, |
---|
35 | filename=meshname, |
---|
36 | #interior_regions=interior_regions, |
---|
37 | use_cache=False, |
---|
38 | verbose=True) |
---|
39 | |
---|
40 | from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance |
---|
41 | from anuga.caching import cache |
---|
42 | |
---|
43 | domain = cache(pmesh_to_domain_instance, |
---|
44 | (meshname, Domain), |
---|
45 | dependencies = [meshname]) # Create domain |
---|
46 | domain.set_name('slide') # Output to file runup.sww |
---|
47 | domain.set_datadir('.') # Use current directory for output |
---|
48 | domain.set_quantities_to_be_stored(['stage',# Store all conserved quantities |
---|
49 | 'xmomentum', |
---|
50 | 'ymomentum']) |
---|
51 | |
---|
52 | |
---|
53 | #------------------------------------------------------------------------------ |
---|
54 | # Setup initial conditions |
---|
55 | #------------------------------------------------------------------------------ |
---|
56 | |
---|
57 | from math import tan, radians |
---|
58 | beta = radians(5.7) |
---|
59 | delta = 1. |
---|
60 | mu = 0.01 |
---|
61 | g = 9.81 |
---|
62 | |
---|
63 | def topography(x,y): |
---|
64 | return x*tan(beta) # H(x) = x tan(beta) |
---|
65 | |
---|
66 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
67 | domain.set_quantity('friction', 0.1) # Constant friction |
---|
68 | domain.set_quantity('stage', 0.0) # Constant negative initial stage |
---|
69 | |
---|
70 | from Numeric import sqrt, exp |
---|
71 | t = 0 |
---|
72 | def ho(x,y): |
---|
73 | return delta*exp(x) |
---|
74 | |
---|
75 | #return delta*( -(2*sqrt(x*mu*mu/(delta*tan(beta))) - sqrt(g/delta)*mu*t)**2) |
---|
76 | #------------------------------------------------------------------------------ |
---|
77 | # Setup boundary conditions |
---|
78 | #------------------------------------------------------------------------------ |
---|
79 | |
---|
80 | from math import sin, pi, exp |
---|
81 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
82 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
83 | Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values |
---|
84 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
85 | f=lambda t: [(.1*sin(t*2*pi)-0.3) * exp(-t), 0.0, 0.0]) |
---|
86 | |
---|
87 | # Associate boundary tags with boundary objects |
---|
88 | domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br}) |
---|
89 | |
---|
90 | |
---|
91 | #------------------------------------------------------------------------------ |
---|
92 | # Evolve system through time |
---|
93 | #------------------------------------------------------------------------------ |
---|
94 | |
---|
95 | for t in domain.evolve(yieldstep = 0.1, finaltime = 10.0): |
---|
96 | t1 = domain.get_time() |
---|
97 | t = t1 |
---|
98 | domain.set_quantity('elevation', ho) |
---|
99 | domain.write_time() |
---|
100 | |
---|
101 | |
---|
102 | |
---|