source: inundation/ga/storm_surge/parallel/run_parallel_sw_merimbula.py @ 1563

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