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 | # This is a modification of the run_parallel_advection.py |
---|
8 | # file |
---|
9 | # |
---|
10 | # |
---|
11 | # *) The (new) files that have been added to manage the |
---|
12 | # grid partitioning are |
---|
13 | # +) pmesh_divide_metis.py: subdivide a pmesh |
---|
14 | # +) build_submesh.py: build the submeshes on the host |
---|
15 | # processor. |
---|
16 | # +) build_local.py: build the GA mesh datastructure |
---|
17 | # on each processor. |
---|
18 | # +) build_commun.py: handle the communication between |
---|
19 | # the host and processors |
---|
20 | # |
---|
21 | # Authors: Linda Stals, Steve Roberts and Matthew Hardy, |
---|
22 | # June 2005 |
---|
23 | # |
---|
24 | # |
---|
25 | # |
---|
26 | ######################################################### |
---|
27 | import sys |
---|
28 | import pypar # The Python-MPI interface |
---|
29 | import time |
---|
30 | |
---|
31 | |
---|
32 | from os import sep |
---|
33 | sys.path.append('..'+sep+'pyvolution') |
---|
34 | |
---|
35 | # Numeric arrays |
---|
36 | |
---|
37 | from Numeric import array, zeros, Float |
---|
38 | # pmesh |
---|
39 | |
---|
40 | #from shallow_water import Domain |
---|
41 | |
---|
42 | from print_stats import print_test_stats, build_full_flag |
---|
43 | |
---|
44 | from pmesh2domain import pmesh_to_domain_instance |
---|
45 | from advection import Domain as Advection_Domain |
---|
46 | from parallel_advection import Parallel_Domain |
---|
47 | |
---|
48 | from generic_boundary_conditions import Transmissive_boundary |
---|
49 | |
---|
50 | # mesh partition routines |
---|
51 | |
---|
52 | from pmesh_divide import pmesh_divide_metis |
---|
53 | from build_submesh import build_submesh |
---|
54 | from build_local import build_local_mesh |
---|
55 | from build_commun import send_submesh, rec_submesh, extract_hostmesh |
---|
56 | |
---|
57 | |
---|
58 | class Set_Stage: |
---|
59 | """Set an initial condition with constant water height, for x<x0 |
---|
60 | """ |
---|
61 | |
---|
62 | def __init__(self, x0=0.25, x1=0.5, h=1.0): |
---|
63 | self.x0 = x0 |
---|
64 | self.x1 = x1 |
---|
65 | self.h = h |
---|
66 | |
---|
67 | def __call__(self, x, y): |
---|
68 | return self.h*((x>self.x0)&(x<self.x1)) |
---|
69 | |
---|
70 | # read in the processor information |
---|
71 | |
---|
72 | numprocs = pypar.size() |
---|
73 | myid = pypar.rank() |
---|
74 | processor_name = pypar.Get_processor_name() |
---|
75 | |
---|
76 | |
---|
77 | #------- |
---|
78 | # Domain |
---|
79 | rect = zeros( 4, Float) # Buffer for results |
---|
80 | |
---|
81 | if myid == 0: |
---|
82 | |
---|
83 | # read in the test files |
---|
84 | |
---|
85 | # filename = 'test-100.tsh' |
---|
86 | filename = 'merimbula_10785.tsh' |
---|
87 | nx = numprocs |
---|
88 | ny = 1 |
---|
89 | if nx*ny != numprocs: |
---|
90 | print "WARNING: number of subboxes is not equal to the number of proc" |
---|
91 | |
---|
92 | domain_full = pmesh_to_domain_instance(filename, Advection_Domain) |
---|
93 | # domain_full.set_quantity('stage', Set_Stage(200.0,300.0,1.0)) |
---|
94 | domain_full.set_quantity('stage', Set_Stage(756000.0,756500.0,4.0)) |
---|
95 | |
---|
96 | nodes, triangles, boundary, triangles_per_proc, quantities =\ |
---|
97 | pmesh_divide_metis(domain_full, numprocs) |
---|
98 | |
---|
99 | # subdivide the mesh |
---|
100 | rect = array(domain_full.xy_extent, Float) |
---|
101 | # rect = array(rect, Float) |
---|
102 | |
---|
103 | submesh = build_submesh(nodes, triangles, boundary, quantities, \ |
---|
104 | triangles_per_proc) |
---|
105 | |
---|
106 | # send the mesh partition to the appropriate processor |
---|
107 | |
---|
108 | for p in range(1, numprocs): |
---|
109 | send_submesh(submesh, triangles_per_proc, p) |
---|
110 | |
---|
111 | # Build the local mesh for processor 0 |
---|
112 | |
---|
113 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \ |
---|
114 | extract_hostmesh(submesh, triangles_per_proc) |
---|
115 | |
---|
116 | # read in the mesh partition that belongs to this |
---|
117 | # processor (note that the information is in the |
---|
118 | # correct form for the GA data structure |
---|
119 | |
---|
120 | else: |
---|
121 | [points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict] = \ |
---|
122 | rec_submesh(0) |
---|
123 | |
---|
124 | pypar.broadcast(rect,0) |
---|
125 | |
---|
126 | domain = Parallel_Domain(points, vertices, boundary, |
---|
127 | full_send_dict = full_send_dict, |
---|
128 | ghost_recv_dict = ghost_recv_dict, |
---|
129 | velocity = [0.1,0.0]) |
---|
130 | |
---|
131 | # Make a notes of which triangles are full and which are ghost |
---|
132 | |
---|
133 | tri_full_flag = build_full_flag(domain, ghost_recv_dict) |
---|
134 | |
---|
135 | #domain.initialise_visualiser(rect=rect) |
---|
136 | |
---|
137 | #Boundaries |
---|
138 | |
---|
139 | T = Transmissive_boundary(domain) |
---|
140 | #R = Reflective_boundary(domain) |
---|
141 | domain.set_boundary( {'outflow': T, 'inflow': T, 'inner':T, 'exterior': T, 'open':T, 'ghost':None} ) |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | domain.set_quantity('stage', quantities['stage']) |
---|
146 | |
---|
147 | #--------- |
---|
148 | # Evolution |
---|
149 | t0 = time.time() |
---|
150 | |
---|
151 | |
---|
152 | try: |
---|
153 | domain.initialise_visualiser(rect=rect) |
---|
154 | #domain.visualiser.coloring['stage'] = True |
---|
155 | #domain.visualiser.scale_z['stage'] = 0.2 |
---|
156 | except: |
---|
157 | print 'No visualiser' |
---|
158 | |
---|
159 | |
---|
160 | from norms import linf_norm |
---|
161 | |
---|
162 | #yieldstep = 1 |
---|
163 | #finaltime = 4000 |
---|
164 | |
---|
165 | yieldstep = 1000 |
---|
166 | finaltime = 50000 |
---|
167 | |
---|
168 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
169 | if myid == 0: |
---|
170 | domain.write_time() |
---|
171 | print_test_stats(domain, tri_full_flag) |
---|
172 | |
---|
173 | if myid == 0: |
---|
174 | print 'That took %.2f seconds' %(time.time()-t0) |
---|