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 | # Read in processor information |
---|
25 | #------------------------------------------------------------------------------ |
---|
26 | |
---|
27 | numprocs = pypar.size() |
---|
28 | myid = pypar.rank() |
---|
29 | processor_name = pypar.Get_processor_name() |
---|
30 | print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name) |
---|
31 | |
---|
32 | |
---|
33 | #------------------------------------------------------------------------------ |
---|
34 | # Initialise |
---|
35 | #------------------------------------------------------------------------------ |
---|
36 | |
---|
37 | if myid == 0: |
---|
38 | #-------------------------------------------------------------------------- |
---|
39 | # Setup computational domain |
---|
40 | #-------------------------------------------------------------------------- |
---|
41 | |
---|
42 | points, vertices, boundary = rectangular_cross(10, 10) # Basic mesh |
---|
43 | |
---|
44 | domain = Domain(points, vertices, boundary) # Create domain |
---|
45 | domain.set_name('runup') # Set sww filename |
---|
46 | |
---|
47 | |
---|
48 | #------------ ------------------------------------------------------------- |
---|
49 | # Setup initial conditions |
---|
50 | #-------------------------------------------------------------------------- |
---|
51 | |
---|
52 | def topography(x,y): |
---|
53 | return -x/2 # linear bed slope |
---|
54 | |
---|
55 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
56 | domain.set_quantity('friction', 0.1) # Constant friction |
---|
57 | domain.set_quantity('stage', -.4) # Constant initial stage |
---|
58 | |
---|
59 | |
---|
60 | #------------ ------------------------------------------------------------- |
---|
61 | # Distribute the domain |
---|
62 | #-------------------------------------------------------------------------- |
---|
63 | |
---|
64 | # Subdivide the mesh |
---|
65 | print 'Subdivide mesh' |
---|
66 | nodes, triangles, boundary, triangles_per_proc, quantities = \ |
---|
67 | pmesh_divide_metis(domain, numprocs) |
---|
68 | |
---|
69 | # Build the mesh that should be assigned to each processor, |
---|
70 | # this includes ghost nodes and the communicaiton pattern |
---|
71 | print 'Build submeshes' |
---|
72 | submesh = build_submesh(nodes, triangles, boundary,\ |
---|
73 | quantities, triangles_per_proc) |
---|
74 | |
---|
75 | # Send the mesh partition to the appropriate processor |
---|
76 | print 'Distribute submeshes' |
---|
77 | for p in range(1, numprocs): |
---|
78 | send_submesh(submesh, triangles_per_proc, p) |
---|
79 | |
---|
80 | # Build the local mesh for processor 0 |
---|
81 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \ |
---|
82 | extract_hostmesh(submesh, triangles_per_proc) |
---|
83 | |
---|
84 | print 'Communication done' |
---|
85 | |
---|
86 | else: |
---|
87 | # Read in the mesh partition that belongs to this |
---|
88 | # processor (note that the information is in the |
---|
89 | # correct form for the GA data structure) |
---|
90 | |
---|
91 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict, \ |
---|
92 | = rec_submesh(0) |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | #------------------------------------------------------------------------------ |
---|
97 | # Start the computations on each subpartion |
---|
98 | #------------------------------------------------------------------------------ |
---|
99 | |
---|
100 | # Build the domain for this processor |
---|
101 | domain = Parallel_Domain(points, vertices, boundary, |
---|
102 | full_send_dict = full_send_dict, |
---|
103 | ghost_recv_dict = ghost_recv_dict) |
---|
104 | |
---|
105 | |
---|
106 | # Name and dir, etc currently has to be set here as they are not |
---|
107 | # transferred from the original domain |
---|
108 | domain.set_name('runup') # Set sww filename |
---|
109 | |
---|
110 | |
---|
111 | #------------------------------------------------------------------------------ |
---|
112 | # Setup initial conditions |
---|
113 | #------------------------------------------------------------------------------ |
---|
114 | for q in quantities: |
---|
115 | domain.set_quantity(q, quantities[q]) # Distribute all quantities |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | #------------------------------------------------------------------------------ |
---|
120 | # Setup parallel boundary conditions |
---|
121 | #------------------------------------------------------------------------------ |
---|
122 | |
---|
123 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
124 | Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values |
---|
125 | |
---|
126 | # Associate boundary tags with boundary objects |
---|
127 | domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br, |
---|
128 | 'ghost': None, 'exterior': Bd}) |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | #------------------------------------------------------------------------------ |
---|
133 | # Evolve system through time |
---|
134 | #------------------------------------------------------------------------------ |
---|
135 | |
---|
136 | for t in domain.evolve(yieldstep = 0.1, finaltime = 10.0): |
---|
137 | domain.write_time() |
---|
138 | |
---|
139 | |
---|
140 | |
---|