1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water driven up a linear slope and time varying boundary, |
---|
4 | similar to a beach environment |
---|
5 | |
---|
6 | This is a very simple test of the parallel algorithm |
---|
7 | """ |
---|
8 | |
---|
9 | |
---|
10 | #------------------------------------------------------------------------------ |
---|
11 | # Import necessary modules |
---|
12 | #------------------------------------------------------------------------------ |
---|
13 | |
---|
14 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
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 | from parallel_api import * |
---|
22 | |
---|
23 | |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | # Initialise |
---|
26 | #------------------------------------------------------------------------------ |
---|
27 | |
---|
28 | if myid == 0: |
---|
29 | #-------------------------------------------------------------------------- |
---|
30 | # Setup computational domain |
---|
31 | #-------------------------------------------------------------------------- |
---|
32 | |
---|
33 | points, vertices, boundary = rectangular_cross(20, 20) # Basic mesh |
---|
34 | |
---|
35 | domain = Domain(points, vertices, boundary) # Create domain |
---|
36 | domain.set_name('runup') # Set sww filename |
---|
37 | |
---|
38 | |
---|
39 | #------------ ------------------------------------------------------------- |
---|
40 | # Setup initial conditions |
---|
41 | #-------------------------------------------------------------------------- |
---|
42 | |
---|
43 | def topography(x,y): |
---|
44 | return -x/2 # linear bed slope |
---|
45 | |
---|
46 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
47 | domain.set_quantity('friction', 0.1) # Constant friction |
---|
48 | domain.set_quantity('stage', -.4) # Constant initial stage |
---|
49 | |
---|
50 | |
---|
51 | #-------------------------------------------------------------------------- |
---|
52 | # Setup boundary conditions |
---|
53 | #-------------------------------------------------------------------------- |
---|
54 | |
---|
55 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
56 | Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values |
---|
57 | |
---|
58 | # Associate boundary tags with boundary objects |
---|
59 | domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br}) |
---|
60 | |
---|
61 | |
---|
62 | #------------------------------------------------------------------------------ |
---|
63 | # Parallel stuff |
---|
64 | #------------------------------------------------------------------------------ |
---|
65 | |
---|
66 | if myid == 0: |
---|
67 | # Distribute the domain |
---|
68 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict,\ |
---|
69 | = distribute_mesh(domain) |
---|
70 | print 'Communication done' |
---|
71 | |
---|
72 | else: |
---|
73 | # Read in the mesh partition that belongs to this |
---|
74 | # processor (note that the information is in the |
---|
75 | # correct form for the GA data structure) |
---|
76 | |
---|
77 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict, \ |
---|
78 | = rec_submesh(0) |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | #------------------------------------------------------------------------------ |
---|
83 | # Start the computations on each subpartion |
---|
84 | #------------------------------------------------------------------------------ |
---|
85 | |
---|
86 | # Build the domain for this processor |
---|
87 | domain = Parallel_Domain(points, vertices, boundary, |
---|
88 | full_send_dict = full_send_dict, |
---|
89 | ghost_recv_dict = ghost_recv_dict) |
---|
90 | |
---|
91 | |
---|
92 | # Name and dir, etc currently has to be set here as they are not |
---|
93 | # transferred from the original domain |
---|
94 | domain.set_name('runup') # Set sww filename |
---|
95 | |
---|
96 | |
---|
97 | #------------------------------------------------------------------------------ |
---|
98 | # Setup initial conditions |
---|
99 | #------------------------------------------------------------------------------ |
---|
100 | for q in quantities: |
---|
101 | domain.set_quantity(q, quantities[q]) # Distribute all quantities |
---|
102 | |
---|
103 | |
---|
104 | #------------------------------------------------------------------------------ |
---|
105 | # Setup parallel boundary conditions |
---|
106 | #------------------------------------------------------------------------------ |
---|
107 | |
---|
108 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
109 | Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values |
---|
110 | |
---|
111 | # Associate boundary tags with boundary objects |
---|
112 | domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br, |
---|
113 | 'ghost': None, 'exterior': Bd}) |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | #------------------------------------------------------------------------------ |
---|
118 | # Evolve system through time |
---|
119 | #------------------------------------------------------------------------------ |
---|
120 | |
---|
121 | for t in domain.evolve(yieldstep = 0.1, finaltime = 10.0): |
---|
122 | domain.write_time() |
---|
123 | |
---|
124 | |
---|
125 | |
---|