1 | """Script for running a tsunami inundation scenario for Cairns, QLD Australia. |
---|
2 | |
---|
3 | Source data such as elevation and boundary data is assumed to be available in |
---|
4 | directories specified by project.py |
---|
5 | The output sww file is stored in directory named after the scenario, i.e |
---|
6 | slide or fixed_wave. |
---|
7 | |
---|
8 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
9 | the elevation data and a tsunami wave generated by a submarine mass failure. |
---|
10 | |
---|
11 | Geoscience Australia, 2004-present |
---|
12 | """ |
---|
13 | |
---|
14 | #------------------------------------------------------------------------------ |
---|
15 | # Import necessary modules |
---|
16 | #------------------------------------------------------------------------------ |
---|
17 | # Standard modules |
---|
18 | import os |
---|
19 | import time |
---|
20 | import sys |
---|
21 | import liststore |
---|
22 | |
---|
23 | # Related major packages |
---|
24 | import anuga |
---|
25 | from anuga_parallel import distribute, myid |
---|
26 | from anuga.abstract_2d_finite_volumes.util import add_directories |
---|
27 | from anuga.utilities import system_tools, log |
---|
28 | |
---|
29 | |
---|
30 | home2 = os.getenv('INUNDATIONHOME') |
---|
31 | |
---|
32 | scenariodir2 = add_directories(home2, ["data", "mem_time_test", "triangles", "logarea"]) |
---|
33 | |
---|
34 | h = 'CAIRNS.msh' |
---|
35 | file_pathh = os.path.join(scenariodir2, h) |
---|
36 | store ='store.txt' |
---|
37 | file_path_store = os.path.join(scenariodir2, store) |
---|
38 | storen ='storen.txt' |
---|
39 | file_path_storen = os.path.join(scenariodir2, storen) |
---|
40 | storel = 'storel.txt' |
---|
41 | file_path_storel = os.path.join(scenariodir2, storel) |
---|
42 | storea = 'storea.txt' |
---|
43 | file_path_storea = os.path.join(scenariodir2, storea) |
---|
44 | |
---|
45 | f = open(file_path_storel,'r+') # SQRT extent this is set |
---|
46 | length = float(f.readline()) |
---|
47 | f.close() |
---|
48 | |
---|
49 | f = open(file_path_storea,'r+') #maxarea this is set |
---|
50 | area = float(f.readline()) |
---|
51 | f.close() |
---|
52 | |
---|
53 | scenariodirV = add_directories(home2, ["data","mem_time_test", "triangles", |
---|
54 | "logarea", "triangles-" + str(area) +"-"+ str(length)]) |
---|
55 | |
---|
56 | h = 'CAIRNS.msh' |
---|
57 | file_pathh = os.path.join(scenariodirV, h) |
---|
58 | |
---|
59 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
60 | log._setup = False |
---|
61 | |
---|
62 | log.resource_usage_timing(prefix = 'BeforeSimulation') |
---|
63 | #------------------------------------------------------------------------------ |
---|
64 | # Create the triangular mesh and domain based on |
---|
65 | # overall clipping polygon with a tagged |
---|
66 | # boundary and interior regions as defined in project.py |
---|
67 | #------------------------------------------------------------------------------ |
---|
68 | if myid == 0: |
---|
69 | domain = anuga.create_domain_from_regions([(0.0,0.0),(length,length),(0.0,length),(length,0.0)], |
---|
70 | boundary_tags={'top': [0], |
---|
71 | 'right': [1], |
---|
72 | 'bottom': [2], |
---|
73 | 'left': [3]}, |
---|
74 | maximum_triangle_area=area, |
---|
75 | mesh_filename=file_pathh |
---|
76 | #,interior_regions=INTERIORREGIONS#, |
---|
77 | #use_cache=True, |
---|
78 | #verbose=True) |
---|
79 | ) |
---|
80 | |
---|
81 | n = len(domain) |
---|
82 | else: |
---|
83 | domain = None |
---|
84 | |
---|
85 | log.resource_usage_timing(prefix = 'AfterMesh') |
---|
86 | domain = distribute(domain) |
---|
87 | |
---|
88 | #------------------------------------------------------------------------------ |
---|
89 | # Setup parameters of computational domain |
---|
90 | #------------------------------------------------------------------------------ |
---|
91 | domain.set_name('CAIRNS.sww') # Name of sww file |
---|
92 | domain.set_datadir(scenariodirV) # Store sww output here |
---|
93 | |
---|
94 | #------------------------------------------------------------------------------ |
---|
95 | # Setup initial conditions |
---|
96 | #------------------------------------------------------------------------------ |
---|
97 | |
---|
98 | def topography(x,y): |
---|
99 | return 0.0 |
---|
100 | log.resource_usage_timing(prefix='beforeinitialconditions') |
---|
101 | tide = 100.0 |
---|
102 | friction = 0.0 |
---|
103 | domain.set_quantity('stage', tide) |
---|
104 | domain.set_quantity('friction', friction) |
---|
105 | domain.set_quantity('elevation',topography,alpha=0.1) |
---|
106 | log.resource_usage_timing(prefix='afterinitialconditions') |
---|
107 | |
---|
108 | |
---|
109 | #------------------------------------------------------------------------------ |
---|
110 | # Setup boundary conditions |
---|
111 | #------------------------------------------------------------------------------ |
---|
112 | |
---|
113 | Bi = anuga.Dirichlet_boundary([tide, 0, 0]) # inflow |
---|
114 | Bo = anuga.Dirichlet_boundary([-tide,0, 0]) # inflow |
---|
115 | Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary |
---|
116 | Br = anuga.Reflective_boundary(domain) |
---|
117 | #Bw = anuga.Time_boundary(domain=domain,function=lambda t: [(60<t<3660)*50, 0, 0]) |
---|
118 | domain.set_boundary({'right': Bo, |
---|
119 | 'bottom': Br, |
---|
120 | 'left': Bi, |
---|
121 | 'top': Br}) |
---|
122 | |
---|
123 | log.resource_usage_timing(prefix='afterboundary') |
---|
124 | #------------------------------------------------------------------------------ |
---|
125 | # Evolve system through time |
---|
126 | #------------------------------------------------------------------------------ |
---|
127 | |
---|
128 | # Save every two mins leading up to wave approaching land |
---|
129 | #for t in domain.evolve(yieldstep=500, finaltime=2000): |
---|
130 | # print domain.timestepping_statistics() |
---|
131 | |
---|
132 | |
---|
133 | #liststore.store[myid] = system_tools.MemoryUpdate()[0] |
---|
134 | #a = sum(liststore.store) |
---|
135 | |
---|
136 | a = 1 |
---|
137 | v = open(file_path_store, 'r+') |
---|
138 | v.write(str(a)) |
---|
139 | |
---|
140 | i = open(file_path_storen, 'r+') |
---|
141 | i.write(str(n)) |
---|
142 | |
---|
143 | |
---|