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
RevLine 
[8311]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
[8326]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
[8311]15"""
16
17#------------------------------------------------------------------------------
18# Import necessary modules
19#------------------------------------------------------------------------------
20# Standard modules
21import os
22import time
[8326]23import sys
[8311]24import anuga
[8326]25from anuga_parallel import distribute, myid, numprocs
26from anuga.abstract_2d_finite_volumes.util import add_directories
27from anuga.utilities import log
[8311]28
[8326]29
[8311]30# Application specific imports
31import project                 # Definition of file names and polygons
32
33
[8326]34# set up variables for the correct output directories
35home = os.getenv('INUNDATIONHOME')
36scenariodir = add_directories(home, ["data", "mem_time_test", "parallel", "cairns"])
[8311]37h = 'CAIRNS.msh'
[8326]38file_pathh = os.path.join(scenariodir, h)
[8311]39store ='store.txt'
[8326]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
[8311]45
46
[8326]47log.resource_usage_timing(prefix = 'BeforeSimulation')#get memory statistics at this point
[8311]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
[8326]53anuga.asc2dem(os.path.join(scenariodir, 'cairns.asc'), use_cache=True, verbose=True)
[8311]54
55# Create pts file for onshore DEM
[8326]56anuga.dem2pts(os.path.join(scenariodir,'cairns.dem'), use_cache=True, verbose=True)
[8311]57
58#------------------------------------------------------------------------------
59# Create the triangular mesh and domain based on
60# overall clipping polygon with a tagged
[8326]61# boundary and interior regions as defined in project.py
62# (in serial, so the set up only runs once)
[8311]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
[8326]82
83log.resource_usage_timing(prefix = 'AfterMesh')#get memory statistics at this point
[8311]84     
[8326]85#parallel
[8311]86domain = distribute(domain)
87                               
88#------------------------------------------------------------------------------
89# Setup parameters of computational domain
90#------------------------------------------------------------------------------
91domain.set_name('cairns_' + project.scenario) # Name of sww file
[8326]92domain.set_datadir(scenariodirV)                       # Store sww output here
[8311]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', 
[8326]103                    filename=os.path.join(scenariodir, 'cairns.pts'),
[8311]104                    use_cache=True,
105                    verbose=True,
106                    alpha=0.1)
[8326]107log.resource_usage_timing(prefix='afterinitialconditions') #get memory statistics at this point
[8311]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)
[8326]123
[8311]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})
[8326]147log.resource_usage_timing(prefix='afterboundary') #get memory statistics at this point
[8311]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           
[8326]184
[8311]185print 'That took %.2f seconds' %(time.time()-t0)
186
[8326]187log.resource_usage_timing(prefix='aftersimulation') #get memory statistics at this point
Note: See TracBrowser for help on using the repository browser.