1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water flowing down a channel |
---|
4 | """ |
---|
5 | |
---|
6 | #------------------------------------------------------------------------------ |
---|
7 | # Import necessary modules |
---|
8 | #------------------------------------------------------------------------------ |
---|
9 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
10 | from anuga.shallow_water import Domain |
---|
11 | from anuga.shallow_water import Reflective_boundary |
---|
12 | from anuga.shallow_water import Dirichlet_boundary |
---|
13 | from anuga.shallow_water import Time_boundary |
---|
14 | |
---|
15 | |
---|
16 | #------------------------------------------------------------------------------ |
---|
17 | # Setup computational domain |
---|
18 | #------------------------------------------------------------------------------ |
---|
19 | length = 10. |
---|
20 | width = 5. |
---|
21 | dx = dy = 1 # Resolution: Length of subdivisions on both axes |
---|
22 | |
---|
23 | points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) |
---|
24 | domain = Domain(points, vertices, boundary) |
---|
25 | domain.set_name('channel_2') # Output name |
---|
26 | |
---|
27 | |
---|
28 | #------------------------------------------------------------------------------ |
---|
29 | # Setup initial conditions |
---|
30 | #------------------------------------------------------------------------------ |
---|
31 | def topography(x,y): |
---|
32 | return -x/10 # linear bed slope |
---|
33 | |
---|
34 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
35 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
36 | domain.set_quantity('stage', expression='elevation') # Dry |
---|
37 | |
---|
38 | |
---|
39 | #------------------------------------------------------------------------------ |
---|
40 | # Setup boundary conditions |
---|
41 | #------------------------------------------------------------------------------ |
---|
42 | Bi = Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
43 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
44 | Bo = Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
45 | |
---|
46 | domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
47 | |
---|
48 | |
---|
49 | #------------------------------------------------------------------------------ |
---|
50 | # Evolve system through time |
---|
51 | #------------------------------------------------------------------------------ |
---|
52 | for t in domain.evolve(yieldstep = 0.2, finaltime = 40.0): |
---|
53 | domain.write_time() |
---|
54 | |
---|
55 | #print 'Stage(10,2.5) = ', domain.get_quantity('stage').get_values(interpolation_points=[[10, 2.5]]) |
---|
56 | |
---|
57 | from Numeric import allclose |
---|
58 | #if allclose(t, 20): |
---|
59 | if domain.get_quantity('stage').get_values(interpolation_points=[[10, 2.5]]) > 0: |
---|
60 | print 'Stage > 0: Changing boundary' |
---|
61 | domain.modify_boundary({'right': Bo}) |
---|
62 | |
---|
63 | |
---|
64 | import sys; sys.exit() |
---|
65 | |
---|
66 | import time |
---|
67 | t0 = time.time() |
---|
68 | |
---|
69 | |
---|
70 | s = 'for t in domain.evolve(yieldstep = 0.2, finaltime = 40.0): domain.write_time(); domain.get_quantity("stage").get_values(interpolation_points=[[10, 2.5]])' |
---|
71 | |
---|
72 | import profile, pstats |
---|
73 | FN = 'profile.dat' |
---|
74 | |
---|
75 | profile.run(s, FN) |
---|
76 | |
---|
77 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
78 | |
---|
79 | S = pstats.Stats(FN) |
---|
80 | #S.sort_stats('time').print_stats(20) |
---|
81 | s = S.sort_stats('cumulative').print_stats(30) |
---|
82 | |
---|
83 | print s |
---|
84 | |
---|