source: inundation/parallel/run_parallel_merimbula.py @ 2697

Last change on this file since 2697 was 2654, checked in by linda, 19 years ago

Added routines to print domain stats in parallel

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