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 | import sys |
---|
17 | import pypar # The Python-MPI interface |
---|
18 | import time |
---|
19 | |
---|
20 | |
---|
21 | from os import sep |
---|
22 | sys.path.append('..'+sep+'pyvolution') |
---|
23 | |
---|
24 | from Numeric import array |
---|
25 | # pmesh |
---|
26 | |
---|
27 | from print_stats import print_test_stats, build_full_flag |
---|
28 | |
---|
29 | from shallow_water import Domain |
---|
30 | from parallel_shallow_water import Parallel_Domain |
---|
31 | |
---|
32 | |
---|
33 | # mesh partition routines |
---|
34 | from parallel_meshes import parallel_rectangle |
---|
35 | |
---|
36 | |
---|
37 | from pmesh_divide import pmesh_divide, pmesh_divide_steve |
---|
38 | |
---|
39 | # read in the processor information |
---|
40 | |
---|
41 | numprocs = pypar.size() |
---|
42 | myid = pypar.rank() |
---|
43 | processor_name = pypar.Get_processor_name() |
---|
44 | |
---|
45 | M = 20 |
---|
46 | N = M*numprocs |
---|
47 | |
---|
48 | if myid == 0: |
---|
49 | print 'N == %d' %N |
---|
50 | |
---|
51 | points, vertices, boundary, full_send_dict, ghost_recv_dict = \ |
---|
52 | parallel_rectangle(N, M, len1_g=1.0*numprocs, len2_g = 1.0) |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | domain = Parallel_Domain(points, vertices, boundary, |
---|
57 | full_send_dict = full_send_dict, |
---|
58 | ghost_recv_dict = ghost_recv_dict) |
---|
59 | |
---|
60 | # Make a notes of which triangles are full and which are ghost |
---|
61 | |
---|
62 | tri_full_flag = build_full_flag(domain, ghost_recv_dict) |
---|
63 | |
---|
64 | print 'number of triangles = ', domain.number_of_elements |
---|
65 | |
---|
66 | |
---|
67 | rect = [ 0.0, 0.0, 1.0*numprocs, 1.0] |
---|
68 | try: |
---|
69 | domain.initialise_visualiser(rect=rect) |
---|
70 | domain.visualiser.qcolor['stage'] = (0.0, 0.0, 0.8) |
---|
71 | domain.visualiser.scale_z['stage'] = 1.0 |
---|
72 | domain.visualiser.scale_z['elevation'] = 0.05 |
---|
73 | except: |
---|
74 | print 'No visualiser' |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | domain.default_order = 2 |
---|
80 | |
---|
81 | #Boundaries |
---|
82 | from parallel_shallow_water import Transmissive_boundary, Reflective_boundary |
---|
83 | |
---|
84 | T = Transmissive_boundary(domain) |
---|
85 | R = Reflective_boundary(domain) |
---|
86 | |
---|
87 | |
---|
88 | domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R, 'ghost': None} ) |
---|
89 | domain.check_integrity() |
---|
90 | |
---|
91 | class Set_Stage: |
---|
92 | """Set an initial condition with constant water height, for x<x0 |
---|
93 | """ |
---|
94 | |
---|
95 | def __init__(self, x0=0.25, x1=0.5, y0=0.0, y1=1.0, h=1.0): |
---|
96 | self.x0 = x0 |
---|
97 | self.x1 = x1 |
---|
98 | self.y0 = y0 |
---|
99 | self.y1 = y1 |
---|
100 | self.h = h |
---|
101 | |
---|
102 | def __call__(self, x, y): |
---|
103 | return self.h*((x>self.x0)&(x<self.x1)&(y>self.y0)&(y<self.y1)) |
---|
104 | |
---|
105 | domain.set_quantity('stage', Set_Stage(0.2,0.4,0.25, 0.75, 1.0)) |
---|
106 | |
---|
107 | if myid == 0: |
---|
108 | import time |
---|
109 | t0 = time.time() |
---|
110 | |
---|
111 | yieldstep = 0.005 |
---|
112 | finaltime = 1.0 |
---|
113 | |
---|
114 | #Check that the boundary value gets propagated to all elements |
---|
115 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
116 | if myid == 0: |
---|
117 | domain.write_time() |
---|
118 | print_test_stats(domain, tri_full_flag) |
---|
119 | |
---|
120 | if myid == 0: |
---|
121 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
122 | print 'Communication time %.2f seconds'%domain.communication_time |
---|
123 | print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time |
---|
124 | print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time |
---|
125 | |
---|
126 | |
---|
127 | pypar.finalize() |
---|