1 | #!/usr/bin/env python |
---|
2 | ######################################################### |
---|
3 | # |
---|
4 | # Main file for parallel mesh testing. |
---|
5 | # |
---|
6 | # This is a modification of the run_parallel_advection.py |
---|
7 | # file. |
---|
8 | # |
---|
9 | # |
---|
10 | # Authors: Linda Stals, Steve Roberts and Matthew Hardy, |
---|
11 | # June 2005 |
---|
12 | # |
---|
13 | # |
---|
14 | # |
---|
15 | ######################################################### |
---|
16 | |
---|
17 | import pypar # The Python-MPI interface |
---|
18 | import time |
---|
19 | |
---|
20 | from Numeric import array |
---|
21 | # pmesh |
---|
22 | |
---|
23 | from print_stats import print_test_stats, build_full_flag |
---|
24 | |
---|
25 | from anuga.shallow_water import Domain |
---|
26 | from parallel_shallow_water import Parallel_Domain |
---|
27 | |
---|
28 | |
---|
29 | # mesh partition routines |
---|
30 | from parallel_meshes import parallel_rectangle |
---|
31 | |
---|
32 | |
---|
33 | numprocs = pypar.size() |
---|
34 | myid = pypar.rank() |
---|
35 | processor_name = pypar.Get_processor_name() |
---|
36 | |
---|
37 | M = 50 |
---|
38 | N = M*numprocs |
---|
39 | |
---|
40 | if myid == 0: |
---|
41 | print 'N == %d' %N |
---|
42 | |
---|
43 | points, vertices, boundary, full_send_dict, ghost_recv_dict =\ |
---|
44 | parallel_rectangle(N, M, len1_g=1.0*numprocs, len2_g = 1.0) |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | domain = Parallel_Domain(points, vertices, boundary, |
---|
49 | full_send_dict = full_send_dict, |
---|
50 | ghost_recv_dict = ghost_recv_dict) |
---|
51 | |
---|
52 | # Make a notes of which triangles are full and which are ghost |
---|
53 | |
---|
54 | tri_full_flag = build_full_flag(domain, ghost_recv_dict) |
---|
55 | |
---|
56 | print 'number of triangles = ', domain.number_of_elements |
---|
57 | |
---|
58 | |
---|
59 | rect = [ 0.0, 0.0, 1.0*numprocs, 1.0] |
---|
60 | ## try: |
---|
61 | ## domain.initialise_visualiser(rect=rect) |
---|
62 | ## domain.visualiser.qcolor['stage'] = (0.0, 0.0, 0.8) |
---|
63 | ## domain.visualiser.scale_z['stage'] = 1.0 |
---|
64 | ## domain.visualiser.scale_z['elevation'] = 0.05 |
---|
65 | ## except: |
---|
66 | ## print 'No visualiser' |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | #Boundaries |
---|
75 | from parallel_shallow_water import Transmissive_boundary, Reflective_boundary |
---|
76 | |
---|
77 | T = Transmissive_boundary(domain) |
---|
78 | R = Reflective_boundary(domain) |
---|
79 | |
---|
80 | |
---|
81 | domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R, 'ghost': None} ) |
---|
82 | domain.check_integrity() |
---|
83 | |
---|
84 | class Set_Stage: |
---|
85 | """Set an initial condition with constant water height, for x<x0 |
---|
86 | """ |
---|
87 | |
---|
88 | def __init__(self, x0=0.25, x1=0.75, y0=0.0, y1=1.0, h=5.0, h0=0.0): |
---|
89 | self.x0 = x0 |
---|
90 | self.x1 = x1 |
---|
91 | self.y0 = y0 |
---|
92 | self.y1 = y1 |
---|
93 | self.h = h |
---|
94 | self.h0 = h0 |
---|
95 | |
---|
96 | def __call__(self, x, y): |
---|
97 | return self.h0 + self.h*((x>self.x0)&(x<self.x1)&(y>self.y0)&(y<self.y1)) |
---|
98 | |
---|
99 | domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 1.0, 0.00)) |
---|
100 | |
---|
101 | if myid == 0: |
---|
102 | import time |
---|
103 | t0 = time.time() |
---|
104 | |
---|
105 | |
---|
106 | # Turn on the visualisation |
---|
107 | |
---|
108 | rect = [0.0, 0.0, 1.0, 1.0] |
---|
109 | domain.initialise_visualiser() |
---|
110 | |
---|
111 | domain.default_order = 2 |
---|
112 | domain.beta_w = 1.0 |
---|
113 | domain.beta_w_dry = 0.2 |
---|
114 | domain.beta_uh = 1.0 |
---|
115 | domain.beta_uh_dry = 0.2 |
---|
116 | domain.beta_vh = 1.0 |
---|
117 | domain.beta_vh_dry = 0.2 |
---|
118 | |
---|
119 | domain.beta_w = 0.9 |
---|
120 | domain.beta_w_dry = 0.9 |
---|
121 | domain.beta_uh = 0.9 |
---|
122 | domain.beta_uh_dry = 0.9 |
---|
123 | domain.beta_vh = 0.9 |
---|
124 | domain.beta_vh_dry = 0.9 |
---|
125 | |
---|
126 | yieldstep = 0.005 |
---|
127 | finaltime = 1.0 |
---|
128 | |
---|
129 | #Check that the boundary value gets propagated to all elements |
---|
130 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
131 | if myid == 0: |
---|
132 | domain.write_time() |
---|
133 | #print_test_stats(domain, tri_full_flag) |
---|
134 | |
---|
135 | if myid == 0: |
---|
136 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
137 | print 'Communication time %.2f seconds'%domain.communication_time |
---|
138 | print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time |
---|
139 | print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time |
---|
140 | |
---|
141 | |
---|
142 | pypar.finalize() |
---|