1 | ######################################################### |
---|
2 | # |
---|
3 | # Main file for parallel mesh testing. |
---|
4 | # |
---|
5 | # This is a modification of the run_parallel_advection.py |
---|
6 | # file. |
---|
7 | # |
---|
8 | # |
---|
9 | # Authors: Linda Stals, Steve Roberts and Matthew Hardy, |
---|
10 | # June 2005 |
---|
11 | # |
---|
12 | # |
---|
13 | # |
---|
14 | ######################################################### |
---|
15 | |
---|
16 | import time |
---|
17 | |
---|
18 | import numpy as num |
---|
19 | |
---|
20 | from print_stats import print_test_stats, build_full_flag |
---|
21 | |
---|
22 | #---------------------------- |
---|
23 | # Sequential interface |
---|
24 | #--------------------------- |
---|
25 | from anuga.interface import Domain |
---|
26 | from anuga.interface import Transmissive_boundary, Reflective_boundary |
---|
27 | |
---|
28 | #---------------------------- |
---|
29 | # Parallel interface |
---|
30 | #--------------------------- |
---|
31 | from anuga_parallel.interface import Parallel_shallow_water_domain |
---|
32 | from anuga_parallel.interface import parallel_rectangle |
---|
33 | from anuga_parallel.interface import myid, numprocs, get_processor_name |
---|
34 | |
---|
35 | ############################### |
---|
36 | # Read in processor information |
---|
37 | ############################### |
---|
38 | numprocs = numprocs() |
---|
39 | myid = myid() |
---|
40 | processor_name = get_processor_name() |
---|
41 | |
---|
42 | M = 50 |
---|
43 | N = M*numprocs |
---|
44 | |
---|
45 | |
---|
46 | if myid == 0: |
---|
47 | print 'N == %d' %N |
---|
48 | |
---|
49 | points, vertices, boundary, full_send_dict, ghost_recv_dict =\ |
---|
50 | parallel_rectangle(N, M, len1_g=1.0*numprocs, len2_g = 1.0) |
---|
51 | |
---|
52 | print "Myid = ", myid, "no points = ", len(points), \ |
---|
53 | "no vertices = ", len(vertices), "no boundaries = ", len(boundary) |
---|
54 | |
---|
55 | ########################################### |
---|
56 | # Start the computations on each subpartion |
---|
57 | ########################################### |
---|
58 | |
---|
59 | domain = Parallel_shallow_water_domain(points, vertices, boundary, |
---|
60 | full_send_dict = full_send_dict, |
---|
61 | ghost_recv_dict = ghost_recv_dict) |
---|
62 | |
---|
63 | |
---|
64 | #Boundaries |
---|
65 | |
---|
66 | |
---|
67 | T = Transmissive_boundary(domain) |
---|
68 | R = Reflective_boundary(domain) |
---|
69 | |
---|
70 | |
---|
71 | domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R, 'ghost': None} ) |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | domain.check_integrity() |
---|
77 | |
---|
78 | class Set_Stage: |
---|
79 | """Set an initial condition with constant water height, for x<x0 |
---|
80 | """ |
---|
81 | |
---|
82 | def __init__(self, x0=0.25, x1=0.75, y0=0.0, y1=1.0, h=5.0, h0=0.0): |
---|
83 | self.x0 = x0 |
---|
84 | self.x1 = x1 |
---|
85 | self.y0 = y0 |
---|
86 | self.y1 = y1 |
---|
87 | self.h = h |
---|
88 | self.h0 = h0 |
---|
89 | |
---|
90 | def __call__(self, x, y): |
---|
91 | return self.h0 + self.h*((x>self.x0)&(x<self.x1)&(y>self.y0)&(y<self.y1)) |
---|
92 | |
---|
93 | domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 1.0, 0.00)) |
---|
94 | |
---|
95 | |
---|
96 | # Set Evolve parameters |
---|
97 | domain.set_default_order(2) |
---|
98 | domain.set_timestepping_method('rk2') |
---|
99 | |
---|
100 | print domain.get_timestepping_method() |
---|
101 | |
---|
102 | #domain.use_edge_limiter = True |
---|
103 | #domain.tight_slope_limiters = True |
---|
104 | #domain.use_centroid_velocities = False |
---|
105 | |
---|
106 | domain.CFL = 1.0 |
---|
107 | |
---|
108 | domain.set_beta(0.8) |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | if myid == 0: |
---|
113 | import time |
---|
114 | t0 = time.time() |
---|
115 | |
---|
116 | |
---|
117 | # Turn on the visualisation |
---|
118 | visualise = False |
---|
119 | if visualise: |
---|
120 | from anuga.visualiser import RealtimeVisualiser |
---|
121 | vis = RealtimeVisualiser(domain) |
---|
122 | vis.render_quantity_height("elevation", offset=0.001, dynamic=False) |
---|
123 | vis.render_quantity_height("stage", dynamic=True) |
---|
124 | vis.colour_height_quantity('stage', (0.2, 0.2, 0.8)) |
---|
125 | vis.start() |
---|
126 | import time |
---|
127 | time.sleep(2.0) |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | yieldstep = 0.1 |
---|
132 | finaltime = 1.0 |
---|
133 | |
---|
134 | #Check that the boundary value gets propagated to all elements |
---|
135 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
136 | if myid == 0: |
---|
137 | domain.write_time() |
---|
138 | #print_test_stats(domain, tri_full_flag) |
---|
139 | if visualise: |
---|
140 | vis.update() |
---|
141 | |
---|
142 | |
---|
143 | |
---|
144 | if visualise: vis.evolveFinished() |
---|
145 | |
---|
146 | if myid == 0: |
---|
147 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
148 | print 'Communication time %.2f seconds'%domain.communication_time |
---|
149 | print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time |
---|
150 | print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time |
---|
151 | |
---|
152 | |
---|
153 | if visualise: vis.join() |
---|
154 | pypar.finalize() |
---|