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

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

formatted the experiment scripts

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