[3040] | 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 |
---|
[3105] | 23 | from Numeric import zeros, Float |
---|
[3040] | 24 | |
---|
| 25 | # Related major packages |
---|
[3584] | 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 |
---|
[3535] | 30 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 31 | from anuga.pmesh.mesh import importUngenerateFile, Segment |
---|
[3040] | 32 | |
---|
[3105] | 33 | # Parallelism |
---|
[3438] | 34 | import pypar # The Python-MPI interface |
---|
[3584] | 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 |
---|
[3105] | 40 | |
---|
| 41 | |
---|
[3040] | 42 | # Application specific imports |
---|
| 43 | import project |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | #------------------------------------------------------------------------------ |
---|
[3105] | 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: |
---|
[3118] | 57 | |
---|
[3105] | 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 | #-------------------------------------------------------------------------- |
---|
[3040] | 63 | |
---|
| 64 | |
---|
[3430] | 65 | print 'Generate mesh' |
---|
[3584] | 66 | # Generate basic mesh |
---|
[3585] | 67 | max_area = project.base_resolution |
---|
[3105] | 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 | |
---|
[3584] | 73 | # Add buildings that will bind to a Reflective boundary |
---|
[3105] | 74 | mesh.import_ungenerate_file(project.buildings_filename, tag='wall') |
---|
[3040] | 75 | |
---|
[3105] | 76 | # Generate and write mesh to file |
---|
| 77 | mesh.generate_mesh(maximum_triangle_area=max_area, |
---|
| 78 | verbose=True) |
---|
[3584] | 79 | |
---|
[3105] | 80 | mesh.export_mesh_file(project.mesh_filename) |
---|
[3043] | 81 | |
---|
[3105] | 82 | |
---|
| 83 | #-------------------------------------------------------------------------- |
---|
| 84 | # Setup computational domain |
---|
| 85 | #-------------------------------------------------------------------------- |
---|
| 86 | |
---|
| 87 | domain = Domain(project.mesh_filename, use_cache = False, verbose = True) |
---|
| 88 | print domain.statistics() |
---|
| 89 | |
---|
[3115] | 90 | domain.set_quantity('elevation', |
---|
| 91 | filename=project.demname + '.pts', |
---|
| 92 | use_cache=True, |
---|
| 93 | verbose=True) |
---|
[3105] | 94 | |
---|
[3115] | 95 | |
---|
[3105] | 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 | |
---|
[3040] | 129 | #------------------------------------------------------------------------------ |
---|
[3105] | 130 | # Start the computations on each subpartion |
---|
[3040] | 131 | #------------------------------------------------------------------------------ |
---|
| 132 | |
---|
| 133 | |
---|
[3105] | 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) |
---|
[3040] | 138 | |
---|
[3519] | 139 | # Name etc currently has to be set here as they are not transferred from the |
---|
| 140 | # original domain |
---|
[3115] | 141 | domain.set_name(project.basename) |
---|
[3123] | 142 | domain.set_datadir(project.outputdir) |
---|
[3105] | 143 | |
---|
[3519] | 144 | |
---|
[3040] | 145 | #------------------------------------------------------------------------------ |
---|
| 146 | # Setup initial conditions |
---|
| 147 | #------------------------------------------------------------------------------ |
---|
| 148 | |
---|
[3438] | 149 | |
---|
[3519] | 150 | domain.set_quantity('elevation', quantities['elevation']) # Distribute elevation |
---|
[3040] | 151 | domain.set_quantity('stage', project.initial_sealevel) |
---|
[3046] | 152 | domain.set_quantity('friction', 0.03) |
---|
[3040] | 153 | |
---|
[3115] | 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 |
---|
[3519] | 157 | # It did not segfault today 2 Aug 2006 !!! |
---|
| 158 | # But values are zero ??.... |
---|
[3115] | 159 | # |
---|
| 160 | #domain.set_quantity('elevation', |
---|
| 161 | # filename=project.demname + '.pts', |
---|
[3519] | 162 | # use_cache=False, |
---|
[3115] | 163 | # verbose=True) |
---|
[3040] | 164 | |
---|
[3115] | 165 | |
---|
[3040] | 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, |
---|
[3046] | 173 | f=lambda t: [project.initial_sealevel + (60<t<480)*6, 0, 0]) |
---|
[3040] | 174 | |
---|
| 175 | domain.set_boundary({'exterior': D, |
---|
| 176 | 'side': D, |
---|
[3043] | 177 | 'wall': R, |
---|
[3105] | 178 | 'ocean': W, |
---|
| 179 | 'ghost': None}) |
---|
[3040] | 180 | |
---|
[3115] | 181 | |
---|
| 182 | |
---|
| 183 | print 'P%d: Ready to evolve. Value of store is %s' %(myid, str(domain.store)) |
---|
| 184 | |
---|
| 185 | |
---|
[3040] | 186 | #------------------------------------------------------------------------------ |
---|
| 187 | # Evolve system through time |
---|
| 188 | #------------------------------------------------------------------------------ |
---|
| 189 | |
---|
| 190 | t0 = time.time() |
---|
[3105] | 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') |
---|
[3040] | 195 | |
---|
[3105] | 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() |
---|