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 = 80 |
---|
53 | M = 80 |
---|
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 "Myid = ", myid, "no points = ", len(points), \ |
---|
66 | "no vertices = ", len(vertices), "no boundaries = ", len(boundary) |
---|
67 | |
---|
68 | ########################################### |
---|
69 | # Start the computations on each subpartion |
---|
70 | ########################################### |
---|
71 | |
---|
72 | # Create advection domain with direction (1,-1) |
---|
73 | # Initial condition is zero by default |
---|
74 | |
---|
75 | domain = Parallel_Domain(points, vertices, boundary, |
---|
76 | full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0]) |
---|
77 | |
---|
78 | # Turn on the visualisation |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | # rect = [0.0, 0.0, 1.0, 1.0] |
---|
84 | # domain.initialise_visualiser(rect=rect) |
---|
85 | |
---|
86 | # Boundaries |
---|
87 | |
---|
88 | T = Transmissive_boundary(domain) |
---|
89 | domain.default_order = 2 |
---|
90 | domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T, \ |
---|
91 | 'ghost': None} ) |
---|
92 | |
---|
93 | # Ensure that the domain definitions make sense |
---|
94 | |
---|
95 | domain.check_integrity() |
---|
96 | |
---|
97 | # Set the inititial conditions |
---|
98 | |
---|
99 | domain.set_quantity('stage', Set_Stage(0.2,0.4,1.0)) |
---|
100 | |
---|
101 | # Let processor 0 output some timing information |
---|
102 | |
---|
103 | visualise = True |
---|
104 | if visualise: |
---|
105 | from anuga.visualiser import RealtimeVisualiser |
---|
106 | vis = RealtimeVisualiser(domain) |
---|
107 | vis.render_quantity_height("elevation", offset=0.01, dynamic=False) |
---|
108 | vis.render_quantity_height("stage", dynamic=True) |
---|
109 | vis.colour_height_quantity('stage', (0.2, 0.2, 0.8)) |
---|
110 | vis.start() |
---|
111 | import time |
---|
112 | time.sleep(2.0) |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | if myid == 0: |
---|
117 | import time |
---|
118 | t0 = time.time() |
---|
119 | |
---|
120 | for t in domain.evolve(yieldstep = 0.1, finaltime = 3.0): |
---|
121 | if myid == 0: |
---|
122 | domain.write_time() |
---|
123 | |
---|
124 | if visualise: |
---|
125 | vis.update() |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | if visualise: vis.evolveFinished() |
---|
130 | |
---|
131 | |
---|
132 | # Output some computation statistics |
---|
133 | |
---|
134 | if myid == 0: |
---|
135 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
136 | print 'Communication time %.2f seconds'\ |
---|
137 | %domain.communication_time |
---|
138 | print 'Reduction Communication time %.2f seconds'\ |
---|
139 | %domain.communication_reduce_time |
---|
140 | |
---|
141 | |
---|
142 | vis.join() |
---|