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

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

update for the new experiments

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