source: trunk/anuga_work/development/mem_time_tests/hardware/cairns/runcairns.py @ 8311

Last change on this file since 8311 was 8311, checked in by pittj, 12 years ago

updating the python script files

  • Property svn:executable set to *
File size: 7.4 KB
Line 
1"""Script for running a tsunami inundation scenario for Cairns, QLD Australia.
2
3Source data such as elevation and boundary data is assumed to be available in
4directories specified by project.py
5The output sww file is stored in directory named after the scenario, i.e
6slide or fixed_wave.
7
8The scenario is defined by a triangular mesh created from project.polygon,
9the elevation data and a tsunami wave generated by a submarine mass failure.
10
11Geoscience Australia, 2004-present
12"""
13
14#------------------------------------------------------------------------------
15# Import necessary modules
16#------------------------------------------------------------------------------
17# Standard modules
18import os
19import time
20import sys
21
22# Related major packages
23import anuga
24import liststore
25
26# Application specific imports
27import project                 # Definition of file names and polygons
28
29from anuga_parallel import distribute, myid, numprocs, finalize, barrier
30from anuga.abstract_2d_finite_volumes.util import add_directories
31from anuga.utilities import system_tools, log
32
33
34home2 = os.getenv('INUNDATIONHOME')
35
36scenariodir2 = add_directories(home2, ["data", "mem_time_test", "parallel", "cairns"])
37
38h = 'CAIRNS.msh'
39file_pathh = os.path.join(scenariodir2, h)
40store ='store.txt'
41file_path_store = os.path.join(scenariodir2, store)
42
43
44system_tools.MemoryUpdate()
45
46#------------------------------------------------------------------------------
47# Preparation of topographic data
48# Convert ASC 2 DEM 2 PTS using source data and store result in source data
49#------------------------------------------------------------------------------
50# Create DEM from asc data
51anuga.asc2dem(os.path.join(scenariodir2, 'cairns.asc'), use_cache=True, verbose=True)
52
53# Create pts file for onshore DEM
54anuga.dem2pts(os.path.join(scenariodir2,'cairns.dem'), use_cache=True, verbose=True)
55
56#------------------------------------------------------------------------------
57# Create the triangular mesh and domain based on
58# overall clipping polygon with a tagged
59# boundary and interior regions as defined in project.py
60#------------------------------------------------------------------------------
61if myid == 0:
62    domain = anuga.create_domain_from_regions(project.bounding_polygon,
63                                    boundary_tags={'top': [0],
64                                                   'ocean_east': [1],
65                                                   'bottom': [2],
66                                                   'onshore': [3]},
67                                    maximum_triangle_area=project.default_res,
68                                    mesh_filename=file_pathh,
69                                    interior_regions=project.interior_regions,
70                                    use_cache=True,
71                                    verbose=True)
72
73    # Print some stats about mesh and domain
74    print 'Number of triangles = ', len(domain)
75    print 'The extent is ', domain.get_extent()
76    print domain.statistics()
77else:
78    domain = None
79     
80domain = distribute(domain)
81                               
82#------------------------------------------------------------------------------
83# Setup parameters of computational domain
84#------------------------------------------------------------------------------
85domain.set_name('cairns_' + project.scenario) # Name of sww file
86domain.set_datadir(scenariodir2)                       # Store sww output here
87domain.set_minimum_storable_height(0.01)      # Store only depth > 1cm
88
89#------------------------------------------------------------------------------
90# Setup initial conditions
91#------------------------------------------------------------------------------
92
93tide = 0.0
94domain.set_quantity('stage', tide)
95domain.set_quantity('friction', 0.0) 
96domain.set_quantity('elevation', 
97                    filename=os.path.join(scenariodir2, 'cairns.pts'),
98                    use_cache=True,
99                    verbose=True,
100                    alpha=0.1)
101
102#------------------------------------------------------------------------------
103# Setup information for slide scenario (to be applied 1 min into simulation
104#------------------------------------------------------------------------------
105if project.scenario == 'slide':
106    # Function for submarine slide
107    tsunami_source = anuga.slide_tsunami(length=35000.0,
108                                   depth=project.slide_depth,
109                                   slope=6.0,
110                                   thickness=500.0, 
111                                   x0=project.slide_origin[0], 
112                                   y0=project.slide_origin[1], 
113                                   alpha=0.0, 
114                                   domain=domain,
115                                   verbose=True)
116
117#------------------------------------------------------------------------------
118# Setup boundary conditions
119#------------------------------------------------------------------------------
120print 'Available boundary tags', domain.get_boundary_tags()
121
122Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level
123Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary
124
125if project.scenario == 'fixed_wave':
126    # Huge 50m wave starting after 60 seconds and lasting 1 hour.
127    Bw = anuga.Time_boundary(domain=domain,
128                       function=lambda t: [(60<t<3660)*50, 0, 0])
129    domain.set_boundary({'ocean_east': Bw,
130                         'bottom': Bs,
131                         'onshore': Bd,
132                         'top': Bs})
133
134if project.scenario == 'slide':
135    # Boundary conditions for slide scenario
136    domain.set_boundary({'ocean_east': Bd,
137                         'bottom': Bd,
138                         'onshore': Bd,
139                         'top': Bd})
140
141#------------------------------------------------------------------------------
142# Evolve system through time
143#------------------------------------------------------------------------------
144import time
145t0 = time.time()
146
147from numpy import allclose
148
149if project.scenario == 'slide':
150    # Initial run without any event
151    for t in domain.evolve(yieldstep=10, finaltime=60): 
152        print domain.timestepping_statistics()
153        print domain.boundary_statistics(tags='ocean_east')       
154       
155    # Add slide to water surface
156    if allclose(t, 60):
157        domain.add_quantity('stage', tsunami_source)   
158
159    # Continue propagating wave
160    for t in domain.evolve(yieldstep=10, finaltime=5000, 
161                           skip_initial_step=True):
162        print domain.timestepping_statistics()
163        print domain.boundary_statistics(tags='ocean_east')   
164
165if project.scenario == 'fixed_wave':
166    # Save every two mins leading up to wave approaching land
167    for t in domain.evolve(yieldstep=120, finaltime=2000): 
168        print domain.timestepping_statistics()
169        print domain.boundary_statistics(tags='ocean_east')   
170
171    # Save every 30 secs as wave starts inundating ashore
172    for t in domain.evolve(yieldstep=10, finaltime=100, 
173                           skip_initial_step=True):
174        print domain.timestepping_statistics()
175        print domain.boundary_statistics(tags='ocean_east')
176           
177print 'That took %.2f seconds' %(time.time()-t0)
178
179liststore.spacelist[myid] = system_tools.MemoryUpdate()[0]
180a = sum(liststore.spacelist)
181
182f = open(file_path_store, 'r+')
183f.write(str(a))
184
Note: See TracBrowser for help on using the repository browser.