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 shallow_water import Domain |
---|
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 | #N = M = 250 |
---|
49 | |
---|
50 | if myid == 0: |
---|
51 | print 'N == %d' %N |
---|
52 | |
---|
53 | points, vertices, boundary, full_send_dict, ghost_recv_dict = \ |
---|
54 | parallel_rectangle(N, M, len1_g=1.0*numprocs, len2_g=1.0) |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | domain = Parallel_Domain(points, vertices, boundary, |
---|
59 | full_send_dict = full_send_dict, |
---|
60 | ghost_recv_dict = ghost_recv_dict) |
---|
61 | |
---|
62 | print 'number of triangles = ', domain.number_of_elements |
---|
63 | |
---|
64 | |
---|
65 | rect = [ 0.0, 0.0, 1.0*numprocs, 1.0] |
---|
66 | try: |
---|
67 | domain.initialise_visualiser(rect=rect) |
---|
68 | domain.visualiser.coloring['stage'] = True |
---|
69 | domain.visualiser.qcolor['stage'] = (0.0, 0.0, 0.8) |
---|
70 | domain.visualiser.scale_z['stage'] = 1.0 |
---|
71 | domain.visualiser.scale_z['elevation'] = 0.05 |
---|
72 | except: |
---|
73 | print 'No visualiser' |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | domain.default_order = 2 |
---|
79 | |
---|
80 | #Boundaries |
---|
81 | from parallel_shallow_water import Transmissive_boundary, Reflective_boundary |
---|
82 | |
---|
83 | T = Transmissive_boundary(domain) |
---|
84 | R = Reflective_boundary(domain) |
---|
85 | |
---|
86 | |
---|
87 | domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R} ) |
---|
88 | domain.check_integrity() |
---|
89 | |
---|
90 | class Set_Stage: |
---|
91 | """Set an initial condition with constant water height, for x<x0 |
---|
92 | """ |
---|
93 | |
---|
94 | def __init__(self, x0=0.25, x1=0.5, y0=0.0, y1=1.0, h=1.0): |
---|
95 | self.x0 = x0 |
---|
96 | self.x1 = x1 |
---|
97 | self.y0 = y0 |
---|
98 | self.y1 = y1 |
---|
99 | self.h = h |
---|
100 | |
---|
101 | def __call__(self, x, y): |
---|
102 | return self.h*((x>self.x0)&(x<self.x1)&(y>self.y0)&(y<self.y1)) |
---|
103 | |
---|
104 | domain.set_quantity('stage', Set_Stage(0.2,0.4,0.25, 0.75, 1.0)) |
---|
105 | |
---|
106 | if myid == 0: |
---|
107 | import time |
---|
108 | t0 = time.time() |
---|
109 | |
---|
110 | yieldstep = 0.005 |
---|
111 | finaltime = 1.0 |
---|
112 | |
---|
113 | #Check that the boundary value gets propagated to all elements |
---|
114 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
115 | if myid == 0: |
---|
116 | domain.write_time() |
---|
117 | |
---|
118 | if myid == 0: |
---|
119 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
120 | print 'Communication time %.2f seconds'%domain.communication_time |
---|
121 | print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time |
---|
122 | print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time |
---|
123 | |
---|
124 | |
---|
125 | pypar.finalize() |
---|