1 | |
---|
2 | """Run parallel shallow water domain. |
---|
3 | |
---|
4 | run using command like: |
---|
5 | |
---|
6 | mpirun -np m python run_parallel_sw_merimbula.py |
---|
7 | |
---|
8 | where m is the number of processors to be used. |
---|
9 | |
---|
10 | Will produce sww files with names domain_Pn_m.sww where m is number of processors and |
---|
11 | n in [0, m-1] refers to specific processor that owned this part of the partitioned mesh. |
---|
12 | """ |
---|
13 | |
---|
14 | #------------------------------------------------------------------------------ |
---|
15 | # Import necessary modules |
---|
16 | #------------------------------------------------------------------------------ |
---|
17 | |
---|
18 | import os |
---|
19 | import sys |
---|
20 | import time |
---|
21 | import numpy as num |
---|
22 | |
---|
23 | #------------------------ |
---|
24 | # ANUGA Modules |
---|
25 | #------------------------ |
---|
26 | |
---|
27 | from anuga import Domain |
---|
28 | from anuga import Reflective_boundary |
---|
29 | from anuga import Dirichlet_boundary |
---|
30 | from anuga import Time_boundary |
---|
31 | from anuga import Transmissive_boundary |
---|
32 | |
---|
33 | from anuga import rectangular_cross |
---|
34 | from anuga import create_domain_from_file |
---|
35 | |
---|
36 | |
---|
37 | from anuga_parallel import distribute, myid, numprocs, finalize |
---|
38 | |
---|
39 | |
---|
40 | #-------------------------------------------------------------------------- |
---|
41 | # Setup parameters |
---|
42 | #-------------------------------------------------------------------------- |
---|
43 | |
---|
44 | mesh_filename = "merimbula_10785_1.tsh" ; x0 = 756000.0 ; x1 = 756500.0 |
---|
45 | #mesh_filename = "merimbula_43200.tsh" ; x0 = 756000.0 ; x1 = 756500.0 |
---|
46 | #mesh_filename = "test-100.tsh" ; x0 = 0.25 ; x1 = 0.5 |
---|
47 | yieldstep = 20 |
---|
48 | finaltime = 500 |
---|
49 | verbose = True |
---|
50 | |
---|
51 | #-------------------------------------------------------------------------- |
---|
52 | # Setup procedures |
---|
53 | #-------------------------------------------------------------------------- |
---|
54 | class Set_Stage: |
---|
55 | """Set an initial condition with constant water height, for x0<x<x1 |
---|
56 | """ |
---|
57 | |
---|
58 | def __init__(self, x0=0.25, x1=0.5, h=1.0): |
---|
59 | self.x0 = x0 |
---|
60 | self.x1 = x1 |
---|
61 | self.h = h |
---|
62 | |
---|
63 | def __call__(self, x, y): |
---|
64 | return self.h*((x>self.x0)&(x<self.x1)) |
---|
65 | |
---|
66 | #-------------------------------------------------------------------------- |
---|
67 | # Setup Domain only on processor 0 |
---|
68 | #-------------------------------------------------------------------------- |
---|
69 | if myid == 0: |
---|
70 | domain = create_domain_from_file(mesh_filename) |
---|
71 | domain.set_quantity('stage', Set_Stage(x0, x1, 2.0)) |
---|
72 | else: |
---|
73 | domain = None |
---|
74 | |
---|
75 | #-------------------------------------------------------------------------- |
---|
76 | # Distribute sequential domain on processor 0 to other processors |
---|
77 | #-------------------------------------------------------------------------- |
---|
78 | |
---|
79 | if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN' |
---|
80 | domain = distribute(domain,verbose=True) |
---|
81 | |
---|
82 | #domain.smooth = False |
---|
83 | |
---|
84 | domain.set_default_order(2) |
---|
85 | domain.set_timestepping_method('rk2') |
---|
86 | #domain.set_CFL(0.7) |
---|
87 | #domain.set_beta(1.5) |
---|
88 | domain.set_name('meribula') |
---|
89 | |
---|
90 | #------------------------------------------------------------------------------ |
---|
91 | # Setup boundary conditions |
---|
92 | # This must currently happen *after* domain has been distributed |
---|
93 | #------------------------------------------------------------------------------ |
---|
94 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
95 | |
---|
96 | domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Br}) |
---|
97 | |
---|
98 | #------------------------------------------------------------------------------ |
---|
99 | # Evolution |
---|
100 | #------------------------------------------------------------------------------ |
---|
101 | if myid == 0 and verbose: print 'EVOLVE' |
---|
102 | |
---|
103 | t0 = time.time() |
---|
104 | |
---|
105 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
106 | if myid == 0: |
---|
107 | domain.write_time() |
---|
108 | |
---|
109 | |
---|
110 | if myid == 0: |
---|
111 | print 'Number of processors %g ' %numprocs |
---|
112 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
113 | print 'Communication time %.2f seconds'%domain.communication_time |
---|
114 | print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time |
---|
115 | print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time |
---|
116 | |
---|
117 | |
---|
118 | #-------------------------------------------------- |
---|
119 | # Merge the individual sww files into one file |
---|
120 | #-------------------------------------------------- |
---|
121 | domain.sww_merge(verbose=True) |
---|
122 | |
---|
123 | finalize() |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | |
---|