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