source: anuga_work/production/wollongong_2006/run_flagstaff_parallel_api.py @ 3585

Last change on this file since 3585 was 3585, checked in by ole, 18 years ago

Work on parallel API

File size: 6.3 KB
Line 
1"""Script for running a tsunami inundation scenario for Flagstaff pt,
2Wollongong harbour, NSW, Australia.
3
4Source data such as elevation and boundary data is assumed to be available in
5directories specified by project.py
6
7The scenario is defined by a triangular mesh created from project.polygon,
8the elevation data and a hypothetical boundary condition.
9
10Ole Nielsen and Duncan Gray, GA - 2005, Nick Bartzis and Jane Sexton, GA - 2006
11"""
12
13
14#------------------------------------------------------------------------------
15# Import necessary modules
16#------------------------------------------------------------------------------
17
18
19# Standard modules
20import os, sys, time 
21from os import sep
22from os.path import dirname, basename
23from Numeric import zeros, Float
24
25# Related major packages
26from anuga.shallow_water import Domain
27from anuga.shallow_water import Dirichlet_boundary
28from anuga.shallow_water import Time_boundary
29from anuga.shallow_water import Reflective_boundary
30from anuga.pmesh.mesh_interface import create_mesh_from_regions
31from anuga.pmesh.mesh import importUngenerateFile, Segment
32
33from anuga.caching import cache
34
35# Parallelism
36from parallel_api import *
37
38# Application specific imports
39import project
40
41# Sequential part
42if myid == 0:
43   
44    #--------------------------------------------------------------------------
45    # Create the triangular mesh based on overall clipping polygon with a
46    # tagged boundary and interior regions defined in project.py along with
47    # resolutions (maximal area of per triangle) for each polygon
48    #--------------------------------------------------------------------------
49
50    print 'Generate mesh'
51    # Generate basic mesh
52    max_area = project.base_resolution
53
54   
55    mesh = cache(create_mesh_from_regions,
56                 project.bounding_polygon,
57                 {'boundary_tags': project.boundary_tags,
58                  'maximum_triangle_area':max_area,
59                  'interior_regions': project.interior_regions},
60                 verbose=True)
61   
62    # Add buildings that will bind to a Reflective boundary
63    mesh.import_ungenerate_file(project.buildings_filename, tag='wall')
64
65    # Generate and write mesh to file
66    mesh.generate_mesh(maximum_triangle_area=max_area,
67                       verbose=True)
68   
69    mesh.export_mesh_file(project.mesh_filename)
70
71
72    #--------------------------------------------------------------------------
73    # Setup computational domain
74    #--------------------------------------------------------------------------
75
76    domain = Domain(project.mesh_filename, use_cache = False, verbose = True)
77    print domain.statistics()
78
79    domain.set_name(project.basename)
80    domain.set_datadir(project.outputdir)   
81
82
83    #------------------------------------------------------------------------------
84    # Setup initial conditions
85    #------------------------------------------------------------------------------
86    domain.set_quantity('stage', project.initial_sealevel)
87    domain.set_quantity('friction', 0.03)   
88    domain.set_quantity('elevation', 
89                        filename=project.demname + '.pts',
90                        use_cache=True,
91                        verbose=True)
92
93
94
95
96#---------------
97# Parallel stuff
98#---------------
99
100if myid == 0:
101    # Distribute the domain
102    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict,\
103            = distribute_mesh(domain)
104
105
106    domain_name = domain.get_name()
107    domain_dir = domain.get_datadir()
108
109    for p in range(pypar.size()):
110        pypar.send((domain_name, domain_dir), p) 
111   
112    print 'Communication done'       
113   
114else:
115    # Read in the mesh partition that belongs to this
116    # processor (note that the information is in the
117    # correct form for the GA data structure)
118
119    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict, \
120            = rec_submesh(0)
121
122    print 'P %d receiving names' %myid
123    X = pypar.receive(0)
124    print X
125    (domain_name, domain_dir) = X
126
127
128
129#------------------------------------------------------------------------------
130# Start the computations on each subpartion
131#------------------------------------------------------------------------------
132
133
134
135# Build the domain for this processor
136domain = Parallel_Domain(points, vertices, boundary,
137                         full_send_dict  = full_send_dict,
138                         ghost_recv_dict = ghost_recv_dict)
139
140# Name and dir, etc currently has to be set here as they are not transferred from the
141# original domain
142domain.set_name(domain_name)
143domain.set_datadir(domain_dir)
144
145
146#------------------------------------------------------------------------------
147# Setup initial conditions
148#------------------------------------------------------------------------------
149for q in quantities:
150    domain.set_quantity(q, quantities[q]) # Distribute elevation   
151
152
153#domain.set_quantity('elevation', quantities['elevation']) # Distribute elevation
154#domain.set_quantity('stage', project.initial_sealevel)
155#domain.set_quantity('friction', 0.03)
156
157
158#------------------------------------------------------------------------------
159# Setup boundary conditions
160#------------------------------------------------------------------------------
161
162D = Dirichlet_boundary([project.initial_sealevel, 0, 0])
163R = Reflective_boundary(domain)
164W = Time_boundary(domain = domain,
165                  f=lambda t: [project.initial_sealevel + (60<t<480)*6, 0, 0])
166
167domain.set_boundary({'exterior': D,
168                     'side': D,
169                     'wall': R,
170                     'ocean': W,
171                     'ghost': None})
172
173
174
175print 'P%d: Ready to evolve. Value of store is %s' %(myid, str(domain.store))
176
177
178#------------------------------------------------------------------------------
179# Evolve system through time
180#------------------------------------------------------------------------------
181
182t0 = time.time()
183for t in domain.evolve(yieldstep = 1, finaltime = 1200):
184    if myid == 0:
185        domain.write_time()
186        #domain.write_boundary_statistics(tags = 'ocean')     
187 
188
189if myid == 0:
190    print 'That took %.2f seconds' %(time.time()-t0)
191    print 'Communication time %.2f seconds'%domain.communication_time
192    print 'Reduction Communication time %.2f seconds'\
193          %domain.communication_reduce_time
194    print 'Broadcast time %.2f seconds'\
195          %domain.communication_broadcast_time
196
197pypar.finalize()
Note: See TracBrowser for help on using the repository browser.