1 | #!/usr/bin/env python |
---|
2 | ######################################################### |
---|
3 | # |
---|
4 | # Main file for parallel mesh testing. Runs an advection |
---|
5 | # flow simulation using a rectangular mesh |
---|
6 | # |
---|
7 | # |
---|
8 | # Authors: Steve Roberts June 2005 |
---|
9 | # Modified by Linda Stals April 2006 |
---|
10 | # |
---|
11 | # |
---|
12 | ######################################################### |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | # Parallel communication routines |
---|
17 | |
---|
18 | import pypar |
---|
19 | |
---|
20 | # Mesh partition routines |
---|
21 | |
---|
22 | from parallel_meshes import parallel_rectangle |
---|
23 | |
---|
24 | # Parallel Domain |
---|
25 | |
---|
26 | from parallel_advection import Parallel_Domain |
---|
27 | from parallel_advection import Transmissive_boundary |
---|
28 | |
---|
29 | ############################ |
---|
30 | # Set the initial conditions |
---|
31 | ############################ |
---|
32 | class Set_Stage: |
---|
33 | """Set an initial condition with constant water height, for x<x0 |
---|
34 | """ |
---|
35 | |
---|
36 | def __init__(self, x0=0.25, x1=0.5, h=1.0): |
---|
37 | self.x0 = x0 |
---|
38 | self.x1 = x1 |
---|
39 | self.h = h |
---|
40 | |
---|
41 | def __call__(self, x, y): |
---|
42 | return self.h*((x>self.x0)&(x<self.x1)) |
---|
43 | |
---|
44 | ############################### |
---|
45 | # Read in processor information |
---|
46 | ############################### |
---|
47 | |
---|
48 | numprocs = pypar.size() |
---|
49 | myid = pypar.rank() |
---|
50 | processor_name = pypar.Get_processor_name() |
---|
51 | |
---|
52 | N = 5 |
---|
53 | M = 2 |
---|
54 | |
---|
55 | ####################### |
---|
56 | # Partition the mesh |
---|
57 | ####################### |
---|
58 | |
---|
59 | # Build a unit mesh, subdivide it over numproces processors with each |
---|
60 | # submesh containing M*N nodes |
---|
61 | |
---|
62 | points, vertices, boundary, full_send_dict, ghost_recv_dict = \ |
---|
63 | parallel_rectangle(N, M, len1_g=1.0) |
---|
64 | |
---|
65 | #print 'ghost ',ghost_recv_dict |
---|
66 | #print 'full ',full_send_dict |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | print "Myid = ", myid, "no points = ", len(points), \ |
---|
71 | "no vertices = ", len(vertices), "no boundaries = ", len(boundary) |
---|
72 | |
---|
73 | ########################################### |
---|
74 | # Start the computations on each subpartion |
---|
75 | ########################################### |
---|
76 | |
---|
77 | # Create advection domain with direction (1,-1) |
---|
78 | # Initial condition is zero by default |
---|
79 | |
---|
80 | domain = Parallel_Domain(points, vertices, boundary, |
---|
81 | full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0]) |
---|
82 | |
---|
83 | #print 'ghost ',ghost_recv_dict |
---|
84 | #print 'full ',full_send_dict |
---|
85 | |
---|
86 | |
---|
87 | # Boundaries |
---|
88 | |
---|
89 | T = Transmissive_boundary(domain) |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T, \ |
---|
95 | 'ghost': None} ) |
---|
96 | |
---|
97 | |
---|
98 | # Set Evolve parameters |
---|
99 | domain.set_default_order(2) |
---|
100 | domain.set_timestepping_method('rk2') |
---|
101 | |
---|
102 | print domain.get_timestepping_method() |
---|
103 | |
---|
104 | #domain.use_edge_limiter = True |
---|
105 | #domain.tight_slope_limiters = True |
---|
106 | #domain.use_centroid_velocities = False |
---|
107 | |
---|
108 | domain.CFL = 1.0 |
---|
109 | |
---|
110 | domain.set_beta(0.8) |
---|
111 | |
---|
112 | |
---|
113 | # Ensure that the domain definitions make sense |
---|
114 | |
---|
115 | domain.check_integrity() |
---|
116 | |
---|
117 | # Set the inititial conditions |
---|
118 | |
---|
119 | domain.set_quantity('stage', Set_Stage(0.2,0.4,1.0)) |
---|
120 | |
---|
121 | # Let processor 0 output some timing information |
---|
122 | |
---|
123 | visualise = True |
---|
124 | if visualise: |
---|
125 | from anuga.visualiser import RealtimeVisualiser |
---|
126 | vis = RealtimeVisualiser(domain) |
---|
127 | vis.render_quantity_height("stage", zScale = 5.0, dynamic=True) |
---|
128 | vis.colour_height_quantity('stage', (0.2, 0.2, 0.8)) |
---|
129 | vis.start() |
---|
130 | import time |
---|
131 | time.sleep(2.0) |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | if myid == 0: |
---|
136 | import time |
---|
137 | t0 = time.time() |
---|
138 | |
---|
139 | for t in domain.evolve(yieldstep = 0.1, finaltime = 3.0): |
---|
140 | if myid == 0: |
---|
141 | domain.write_time() |
---|
142 | |
---|
143 | if visualise: |
---|
144 | vis.update() |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | if visualise: vis.evolveFinished() |
---|
149 | |
---|
150 | |
---|
151 | # Output some computation statistics |
---|
152 | |
---|
153 | if myid == 0: |
---|
154 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
155 | print 'Communication time %.2f seconds'\ |
---|
156 | %domain.communication_time |
---|
157 | print 'Reduction Communication time %.2f seconds'\ |
---|
158 | %domain.communication_reduce_time |
---|
159 | |
---|
160 | |
---|
161 | if visualise: vis.join() |
---|