1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | |
---|
4 | """Simple water flow example using ANUGA |
---|
5 | |
---|
6 | Water driven up a linear slope and time varying boundary, |
---|
7 | similar to a beach environment |
---|
8 | |
---|
9 | This is a very simple test of the parallel algorithm using the simplified parallel API |
---|
10 | """ |
---|
11 | |
---|
12 | |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | # Import necessary modules |
---|
15 | #------------------------------------------------------------------------------ |
---|
16 | |
---|
17 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
18 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
19 | from anuga.shallow_water import Domain |
---|
20 | from anuga.shallow_water import Reflective_boundary |
---|
21 | from anuga.shallow_water import Dirichlet_boundary |
---|
22 | from anuga.shallow_water import Time_boundary |
---|
23 | from anuga.shallow_water import Transmissive_boundary |
---|
24 | |
---|
25 | from parallel_api import distribute, myid |
---|
26 | |
---|
27 | |
---|
28 | #-------------------------------------------------------------------------- |
---|
29 | # Setup computational domain |
---|
30 | #-------------------------------------------------------------------------- |
---|
31 | points, vertices, boundary = rectangular_cross(10, 10) # Basic mesh |
---|
32 | domain = Domain(points, vertices, boundary) # Create domain |
---|
33 | domain.set_name('runup') # Set sww filename |
---|
34 | domain.set_datadir('.') # Set output dir |
---|
35 | |
---|
36 | |
---|
37 | #-------------------------------------------------------------------------- |
---|
38 | # Setup initial conditions |
---|
39 | #-------------------------------------------------------------------------- |
---|
40 | |
---|
41 | def topography(x,y): |
---|
42 | return -x/2 # linear bed slope |
---|
43 | |
---|
44 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
45 | domain.set_quantity('friction', 0.1) # Constant friction |
---|
46 | domain.set_quantity('stage', -.4) # Constant initial stage |
---|
47 | |
---|
48 | |
---|
49 | #------------------------------------------------------------------------------ |
---|
50 | # Setup boundary conditions |
---|
51 | #------------------------------------------------------------------------------ |
---|
52 | |
---|
53 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
54 | Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values |
---|
55 | |
---|
56 | # Associate boundary tags with boundary objects |
---|
57 | domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br}) |
---|
58 | |
---|
59 | |
---|
60 | #-------------------------------------------------------------------------- |
---|
61 | # Create the parallel domain |
---|
62 | #-------------------------------------------------------------------------- |
---|
63 | domain = distribute(domain, verbose=True) |
---|
64 | |
---|
65 | |
---|
66 | #------------------------------------------------------------------------------ |
---|
67 | # Evolve system through time |
---|
68 | #------------------------------------------------------------------------------ |
---|
69 | |
---|
70 | interpolation_points = [[0.4,0.5], [0.6,0.5], [0.8,0.5], [0.9,0.5]] |
---|
71 | gauge_values = [] |
---|
72 | for _ in interpolation_points: |
---|
73 | gauge_values.append([]) |
---|
74 | |
---|
75 | time = [] |
---|
76 | |
---|
77 | for t in domain.evolve(yieldstep = 0.1, finaltime = 5.0): |
---|
78 | domain.write_time() |
---|
79 | |
---|
80 | |
---|
81 | # Record time series at known points |
---|
82 | time.append(domain.get_time()) |
---|
83 | |
---|
84 | stage = domain.get_quantity('stage') |
---|
85 | w = stage.get_values(interpolation_points=interpolation_points) |
---|
86 | |
---|
87 | for i, _ in enumerate(interpolation_points): |
---|
88 | gauge_values[i].append(w[i]) |
---|
89 | |
---|
90 | |
---|
91 | print |
---|
92 | print time |
---|
93 | print |
---|
94 | for i, (x,y) in enumerate(interpolation_points): |
---|
95 | print i, gauge_values[i] |
---|
96 | print |
---|
97 | |
---|
98 | |
---|
99 | try: |
---|
100 | from pylab import * |
---|
101 | except: |
---|
102 | pass |
---|
103 | else: |
---|
104 | ion() |
---|
105 | hold(False) |
---|
106 | plot(time, gauge_values[i], 'r.-') |
---|
107 | #time, predicted_gauge_values[i], 'k-') |
---|
108 | |
---|
109 | title('Gauge %d (%f,%f)' %(i,x,y)) |
---|
110 | xlabel('time(s)') |
---|
111 | ylabel('stage (m)') |
---|
112 | #legend(('Observed', 'Modelled'), shadow=True, loc='upper left') |
---|
113 | #savefig('Gauge_%d.png' %i, dpi = 300) |
---|
114 | |
---|
115 | raw_input('Next') |
---|
116 | |
---|
117 | |
---|
118 | |
---|