1 | """Script for running a tsunami inundation scenario for Flagstaff pt, |
---|
2 | Wollongong harbour, NSW, Australia. |
---|
3 | |
---|
4 | Source data such as elevation and boundary data is assumed to be available in |
---|
5 | directories specified by project.py |
---|
6 | |
---|
7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
8 | the elevation data and a hypothetical boundary condition. |
---|
9 | |
---|
10 | Ole 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 |
---|
20 | import os, sys, time |
---|
21 | from os import sep |
---|
22 | from os.path import dirname, basename |
---|
23 | from Numeric import zeros, Float |
---|
24 | |
---|
25 | # Related major packages |
---|
26 | from anuga.shallow_water import Domain |
---|
27 | from anuga.shallow_water import Dirichlet_boundary |
---|
28 | from anuga.shallow_water import Time_boundary |
---|
29 | from anuga.shallow_water import Reflective_boundary |
---|
30 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
31 | from anuga.pmesh.mesh import importUngenerateFile, Segment |
---|
32 | |
---|
33 | # Parallelism |
---|
34 | import pypar # The Python-MPI interface |
---|
35 | from anuga_parallel.pmesh_divide import pmesh_divide_metis |
---|
36 | from anuga_parallel.build_submesh import build_submesh |
---|
37 | from anuga_parallel.build_local import build_local_mesh |
---|
38 | from anuga_parallel.build_commun import send_submesh, rec_submesh, extract_hostmesh |
---|
39 | from anuga_parallel.parallel_shallow_water import Parallel_Domain |
---|
40 | |
---|
41 | |
---|
42 | # Application specific imports |
---|
43 | import project |
---|
44 | |
---|
45 | |
---|
46 | #------------------------------------------------------------------------------ |
---|
47 | # Read in processor information |
---|
48 | #------------------------------------------------------------------------------ |
---|
49 | |
---|
50 | numprocs = pypar.size() |
---|
51 | myid = pypar.rank() |
---|
52 | processor_name = pypar.Get_processor_name() |
---|
53 | print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name) |
---|
54 | |
---|
55 | |
---|
56 | if myid == 0: |
---|
57 | |
---|
58 | #-------------------------------------------------------------------------- |
---|
59 | # Create the triangular mesh based on overall clipping polygon with a |
---|
60 | # tagged boundary and interior regions defined in project.py along with |
---|
61 | # resolutions (maximal area of per triangle) for each polygon |
---|
62 | #-------------------------------------------------------------------------- |
---|
63 | |
---|
64 | |
---|
65 | print 'Generate mesh' |
---|
66 | # Generate basic mesh |
---|
67 | max_area = project.base_resolution |
---|
68 | mesh = create_mesh_from_regions(project.bounding_polygon, |
---|
69 | boundary_tags=project.boundary_tags, |
---|
70 | maximum_triangle_area=max_area, |
---|
71 | interior_regions=project.interior_regions) |
---|
72 | |
---|
73 | # Add buildings that will bind to a Reflective boundary |
---|
74 | mesh.import_ungenerate_file(project.buildings_filename, tag='wall') |
---|
75 | |
---|
76 | # Generate and write mesh to file |
---|
77 | mesh.generate_mesh(maximum_triangle_area=max_area, |
---|
78 | verbose=True) |
---|
79 | |
---|
80 | mesh.export_mesh_file(project.mesh_filename) |
---|
81 | |
---|
82 | |
---|
83 | #-------------------------------------------------------------------------- |
---|
84 | # Setup computational domain |
---|
85 | #-------------------------------------------------------------------------- |
---|
86 | |
---|
87 | domain = Domain(project.mesh_filename, use_cache = False, verbose = True) |
---|
88 | print domain.statistics() |
---|
89 | |
---|
90 | domain.set_quantity('elevation', |
---|
91 | filename=project.demname + '.pts', |
---|
92 | use_cache=True, |
---|
93 | verbose=True) |
---|
94 | |
---|
95 | |
---|
96 | # Subdivide the mesh |
---|
97 | print 'Subdivide mesh' |
---|
98 | nodes, triangles, boundary, triangles_per_proc, quantities = \ |
---|
99 | pmesh_divide_metis(domain, numprocs) |
---|
100 | |
---|
101 | # Build the mesh that should be assigned to each processor, |
---|
102 | # this includes ghost nodes and the communicaiton pattern |
---|
103 | print 'Build submeshes' |
---|
104 | submesh = build_submesh(nodes, triangles, boundary,\ |
---|
105 | quantities, triangles_per_proc) |
---|
106 | |
---|
107 | # Send the mesh partition to the appropriate processor |
---|
108 | print 'Distribute submeshes' |
---|
109 | for p in range(1, numprocs): |
---|
110 | send_submesh(submesh, triangles_per_proc, p) |
---|
111 | |
---|
112 | # Build the local mesh for processor 0 |
---|
113 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \ |
---|
114 | extract_hostmesh(submesh, triangles_per_proc) |
---|
115 | |
---|
116 | print 'Communication done' |
---|
117 | |
---|
118 | else: |
---|
119 | # Read in the mesh partition that belongs to this |
---|
120 | # processor (note that the information is in the |
---|
121 | # correct form for the GA data structure) |
---|
122 | |
---|
123 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict \ |
---|
124 | = rec_submesh(0) |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | #------------------------------------------------------------------------------ |
---|
130 | # Start the computations on each subpartion |
---|
131 | #------------------------------------------------------------------------------ |
---|
132 | |
---|
133 | |
---|
134 | # Build the domain for this processor |
---|
135 | domain = Parallel_Domain(points, vertices, boundary, |
---|
136 | full_send_dict = full_send_dict, |
---|
137 | ghost_recv_dict = ghost_recv_dict) |
---|
138 | |
---|
139 | # Name etc currently has to be set here as they are not transferred from the |
---|
140 | # original domain |
---|
141 | domain.set_name(project.basename) |
---|
142 | domain.set_datadir(project.outputdir) |
---|
143 | |
---|
144 | |
---|
145 | #------------------------------------------------------------------------------ |
---|
146 | # Setup initial conditions |
---|
147 | #------------------------------------------------------------------------------ |
---|
148 | |
---|
149 | |
---|
150 | domain.set_quantity('elevation', quantities['elevation']) # Distribute elevation |
---|
151 | domain.set_quantity('stage', project.initial_sealevel) |
---|
152 | domain.set_quantity('friction', 0.03) |
---|
153 | |
---|
154 | # |
---|
155 | # FIXME (Ole): This one segfaults which is bad, because set_quantity is |
---|
156 | # time consuming and should be done here rather than on processor 0 |
---|
157 | # It did not segfault today 2 Aug 2006 !!! |
---|
158 | # But values are zero ??.... |
---|
159 | # |
---|
160 | #domain.set_quantity('elevation', |
---|
161 | # filename=project.demname + '.pts', |
---|
162 | # use_cache=False, |
---|
163 | # verbose=True) |
---|
164 | |
---|
165 | |
---|
166 | #------------------------------------------------------------------------------ |
---|
167 | # Setup boundary conditions |
---|
168 | #------------------------------------------------------------------------------ |
---|
169 | |
---|
170 | D = Dirichlet_boundary([project.initial_sealevel, 0, 0]) |
---|
171 | R = Reflective_boundary(domain) |
---|
172 | W = Time_boundary(domain = domain, |
---|
173 | f=lambda t: [project.initial_sealevel + (60<t<480)*6, 0, 0]) |
---|
174 | |
---|
175 | domain.set_boundary({'exterior': D, |
---|
176 | 'side': D, |
---|
177 | 'wall': R, |
---|
178 | 'ocean': W, |
---|
179 | 'ghost': None}) |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | print 'P%d: Ready to evolve. Value of store is %s' %(myid, str(domain.store)) |
---|
184 | |
---|
185 | |
---|
186 | #------------------------------------------------------------------------------ |
---|
187 | # Evolve system through time |
---|
188 | #------------------------------------------------------------------------------ |
---|
189 | |
---|
190 | t0 = time.time() |
---|
191 | for t in domain.evolve(yieldstep = 1, finaltime = 1200): |
---|
192 | if myid == 0: |
---|
193 | domain.write_time() |
---|
194 | #domain.write_boundary_statistics(tags = 'ocean') |
---|
195 | |
---|
196 | |
---|
197 | if myid == 0: |
---|
198 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
199 | print 'Communication time %.2f seconds'%domain.communication_time |
---|
200 | print 'Reduction Communication time %.2f seconds'\ |
---|
201 | %domain.communication_reduce_time |
---|
202 | print 'Broadcast time %.2f seconds'\ |
---|
203 | %domain.communication_broadcast_time |
---|
204 | |
---|
205 | pypar.finalize() |
---|