forked from rkwi/mpi4py_anuga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_parallel_sw_merimbula.py
210 lines (154 loc) · 6.38 KB
/
run_parallel_sw_merimbula.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"""Run parallel shallow water domain.
run using command like:
mpirun -np m python run_parallel_sw_merimbula.py
where m is the number of processors to be used.
Will produce sww files with names domain_Pn_m.sww where m is number of processors and
n in [0, m-1] refers to specific processor that owned this part of the partitioned mesh.
"""
#------------------------------------------------------------------------------
# Import necessary modules
#------------------------------------------------------------------------------
import os
import sys
import time
import numpy as num
#------------------------
# ANUGA Modules
#------------------------
from anuga import Domain
from anuga import Reflective_boundary
from anuga import Dirichlet_boundary
from anuga import Time_boundary
from anuga import Transmissive_boundary
from anuga import Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
from anuga import rectangular_cross
from anuga import create_domain_from_file
from anuga_parallel import distribute, myid, numprocs, finalize, barrier
import anuga_parallel.parallel_abstraction as par
def myhook(etype, value, tb):
import traceback
print "myid=", myid
traceback.print_exception(etype, value, tb)
par.abort()
sys.excepthook = myhook
#--------------------------------------------------------------------------
# Setup parameters
#--------------------------------------------------------------------------
mesh_filename = "merimbula_10785_1.tsh" ; x0 = 756000.0 ; x1 = 756500.0; yieldstep = 50; finaltime = 1000
#mesh_filename = "merimbula_17156.tsh" ; x0 = 756000.0 ; x1 = 756500.0; yieldstep = 50; finaltime = 500
#mesh_filename = "merimbula_43200_1.tsh" ; x0 = 756000.0 ; x1 = 756500.0; yieldstep = 50; finaltime = 500
###mesh_filename = "test-100.tsh" ; x0 = 200.0 ; x1 = 300.0; yieldstep = 1; finaltime = 50
#mesh_filename = "test-20.tsh" ; x0 = 250.0 ; x1 = 350.0; yieldstep = 1; finaltime = 50
verbose = True
#--------------------------------------------------------------------------
# Setup procedures
#--------------------------------------------------------------------------
class Set_Stage:
"""Set an initial condition with constant water height, for x0<x<x1
"""
def __init__(self, x0=0.25, x1=0.5, h=1.0):
self.x0 = x0
self.x1 = x1
self.h = h
def __call__(self, x, y):
return self.h*((x>self.x0)&(x<self.x1))+1.0
class Set_Elevation:
"""Set an elevation
"""
def __init__(self, h=1.0):
self.x0 = x0
self.x1 = x1
self.h = h
def __call__(self, x, y):
return x/self.h
#--------------------------------------------------------------------------
# Setup Domain only on processor 0
#--------------------------------------------------------------------------
if myid == 0:
domain = create_domain_from_file(mesh_filename)
#domain.set_quantity('stage', Set_Stage(x0, x1, 1.0))
domain.set_quantity('stage', 0.0)
#domain.set_datadir('.')
domain.set_name('merimbula_new')
domain.set_store(True)
domain.set_store_vertices_smoothly(True)
#domain.set_quantity('elevation', Set_Elevation(500.0))
#print domain.statistics()
#print domain.get_extent()
#print domain.get_extent(absolute=True)
#print domain.geo_reference
else:
domain = None
#--------------------------------------------------------------------------
# Distribute sequential domain on processor 0 to other processors
#--------------------------------------------------------------------------
if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN'
domain = distribute(domain, verbose=True)
#--------------------------------------------------------------------------
# On all processors, setup evolve parameters for domains on all processors
# (all called "domain"
#--------------------------------------------------------------------------
domain.set_flow_algorithm('2_0')
#domain.set_store_vertices_smoothly(True)
#domain.smooth = False
#domain.set_default_order(2)
#domain.set_timestepping_method('rk2')
#domain.set_CFL(0.7)
#domain.set_beta(1.5)
#for p in range(numprocs):
# if myid == p:
# print 'P%d'%p
# print domain.get_extent()
# print domain.get_extent(absolute=True)
# print domain.geo_reference
# print domain.s2p_map
# print domain.p2s_map
# print domain.tri_l2g
# print domain.node_l2g
# else:
# pass
#
# barrier()
domain.set_quantities_to_be_stored({'elevation':1,
'friction':1,
'stage':2,
'xmomentum':2,
'ymomentum':2})
#------------------------------------------------------------------------------
# Setup boundary conditions
# This must currently happen *after* domain has been distributed
#------------------------------------------------------------------------------
Br = Reflective_boundary(domain) # Solid reflective wall
from math import sin
Bts = Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain, lambda t: 10*sin(t/60))
domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Bts})
#bdy_ids = domain.tag_boundary_cells['open']
#vol_ids = domain.boundary_cells[bdy_ids]
#edge_ids = domain.boundary_edges[bdy_ids]
#print domain.mesh.edge_midpoint_coordinates[3*vol_ids+edge_ids]
#------------------------------------------------------------------------------
# Evolution
#------------------------------------------------------------------------------
if myid == 0 and verbose: print 'EVOLVE'
barrier()
t0 = time.time()
for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
if myid == 0:
#domain.write_time()
print 'P:' + str(myid) + ' ' + domain.timestepping_statistics()
barrier()
for p in range(numprocs):
if myid == p:
print 'Processor %g ' %myid
print 'That took %.2f seconds' %(time.time()-t0)
print 'Communication time %.2f seconds'%domain.communication_time
print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time
print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time
else:
pass
barrier()
#--------------------------------------------------
# Merge the individual sww files into one file
#--------------------------------------------------
domain.sww_merge(delete_old=False)
finalize()