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

Last change on this file since 8427 was 8427, checked in by davies, 13 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

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