source: inundation/parallel/run_parallel_merimbula.py @ 2197

Last change on this file since 2197 was 2152, checked in by linda, 19 years ago

Added caching to the sw_merimbula files. Also updated some of the comments

  • Property svn:executable set to *
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#
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 pmesh2domain import pmesh_to_domain_instance
50from advection import Domain as Advection_Domain
51from parallel_advection import Parallel_Domain
52
53from generic_boundary_conditions import Transmissive_boundary
54# mesh partition routines
55
56from pmesh_divide  import pmesh_divide
57from build_submesh import build_submesh, extract_hostmesh
58from build_local   import build_local_mesh
59from build_commun  import send_submesh, rec_submesh
60
61
62class Set_Stage:
63    """Set an initial condition with constant water height, for x<x0
64    """
65
66    def __init__(self, x0=0.25, x1=0.5, h=1.0):
67        self.x0 = x0
68        self.x1 = x1
69        self.= h
70
71    def __call__(self, x, y):
72        return self.h*((x>self.x0)&(x<self.x1))
73
74# read in the processor information
75
76numprocs = pypar.size()
77myid = pypar.rank()
78processor_name = pypar.Get_processor_name()
79
80
81#-------
82# Domain
83rect = zeros( 4, Float) # Buffer for results
84
85if myid == 0:
86
87    # read in the test files
88
89    filename = 'test-100.tsh'
90#    filename = 'merimbula_10785.tsh'
91    nx = numprocs
92    ny = 1
93    if nx*ny != numprocs:
94        print "WARNING: number of subboxes is not equal to the number of proc"
95
96    domain_full = pmesh_to_domain_instance(filename, Advection_Domain)
97    domain_full.set_quantity('stage', Set_Stage(200.0,300.0,1.0))
98#    domain.set_quantity('stage', Set_Stage(756000.0,756500.0,4.0))
99
100    nodes, triangles, boundary, triangles_per_proc, quantities  =\
101            pmesh_divide(domain_full, nx, ny)
102
103    # subdivide the mesh
104    rect = array(domain_full.xy_extent, Float)
105
106    print rect
107
108    rect = array(rect, Float)
109
110    submesh = build_submesh(nodes, triangles, boundary, quantities, \
111                            triangles_per_proc)
112
113    # send the mesh partition to the appropriate processor
114
115    for p in range(1, numprocs):
116      send_submesh(submesh, triangles_per_proc, p)
117
118    hostmesh = extract_hostmesh(submesh)
119    [points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict] = \
120             build_local_mesh(hostmesh, 0, triangles_per_proc[0], numprocs)
121
122# read in the mesh partition that belongs to this
123# processor (note that the information is in the
124# correct form for the GA data structure
125
126else:
127    [points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict] = \
128             rec_submesh(0)
129
130#if myid == 0:
131#    print 'ghost'
132#    print ghost_recv_dict
133#
134#if myid == 0:
135#    print 'full'
136#    print full_send_dict
137
138
139pypar.broadcast(rect,0)
140print rect
141
142domain = Parallel_Domain(points, vertices, boundary,
143                                   full_send_dict  = full_send_dict,
144                                   ghost_recv_dict = ghost_recv_dict,
145                                   velocity = [0.1,0.0])
146
147#domain.initialise_visualiser(rect=rect)
148
149#Boundaries
150
151T = Transmissive_boundary(domain)
152R = Reflective_boundary(domain)
153domain.set_boundary( {'outflow': R, 'inflow': R, 'inner':R, 'exterior': R, 'open':R} )
154
155
156
157domain.set_quantity('stage', quantities['stage'])
158
159#---------
160# Evolution
161t0 = time.time()
162
163
164try:
165    domain.initialise_visualiser(rect=rect)
166    #domain.visualiser.coloring['stage'] = True
167    #domain.visualiser.scale_z['stage'] = 0.2
168except:
169    print 'No visualiser'
170
171
172
173#yieldstep = 1
174yieldstep = 1000
175finaltime = 50000
176# finaltime = 4000
177for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
178    if myid == 0:
179        domain.write_time()
180
181if myid == 0:
182    print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracBrowser for help on using the repository browser.