1 | """ |
---|
2 | Source data such as elevation and boundary data is assumed to be available in |
---|
3 | directories specified by project.py |
---|
4 | The output sww file is stored in project.outputdir |
---|
5 | |
---|
6 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
7 | the elevation data and boundary data obtained from a tsunami simulation done with MOST. |
---|
8 | |
---|
9 | Duncan Gray, Ole Neilsen, GA - 2005 |
---|
10 | """ |
---|
11 | |
---|
12 | |
---|
13 | import os |
---|
14 | import time |
---|
15 | |
---|
16 | |
---|
17 | from pyvolution.shallow_water import Domain, Reflective_boundary, \ |
---|
18 | File_boundary,\ |
---|
19 | Dirichlet_boundary, Time_boundary, Transmissive_boundary |
---|
20 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf,\ |
---|
21 | dem2pts, asc_csiro2sww |
---|
22 | #from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
23 | from pyvolution.pmesh2domain import pmesh_instance_to_domain_instance |
---|
24 | from caching import cache |
---|
25 | import project |
---|
26 | from create_mesh import create_mesh |
---|
27 | |
---|
28 | #Data preparation |
---|
29 | #Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
30 | demname = project.demname |
---|
31 | demname = project.datadir + 'lakes_100' |
---|
32 | # just interested in the boundary/ mesh intereaction first off. |
---|
33 | #cache(convert_dem_from_ascii2netcdf, demname, {'verbose': True}, |
---|
34 | # dependencies = [demname + '.asc'], |
---|
35 | # verbose = True) |
---|
36 | # #evaluate = True) |
---|
37 | |
---|
38 | cache(dem2pts, demname, {'verbose': True}, |
---|
39 | dependencies = [demname + '.dem'], |
---|
40 | verbose = True) |
---|
41 | |
---|
42 | |
---|
43 | # Convert CSIRO boundary |
---|
44 | # NOTE: This function is dependent on a lot of files, and I haven't listed |
---|
45 | # them, since there is so many and I don't think they will be changing. |
---|
46 | cache(asc_csiro2sww, |
---|
47 | (project.bath_dir, |
---|
48 | project.elevation_dir, |
---|
49 | project.ucur_dir, |
---|
50 | project.vcur_dir, |
---|
51 | project.boundaryname + '.sww'), |
---|
52 | {'verbose': True, |
---|
53 | 'minlat': -38.25, |
---|
54 | 'maxlat': -37.7, |
---|
55 | 'minlon': 147.0, |
---|
56 | 'maxlon': 148.25, |
---|
57 | 'mean_stage': project.tide, |
---|
58 | 'zscale': 1, #Enhance tsunami |
---|
59 | 'fail_on_NaN': False}, |
---|
60 | #evaluate = True, |
---|
61 | verbose = True) |
---|
62 | |
---|
63 | |
---|
64 | #Create the mesh .. |
---|
65 | |
---|
66 | #cache this, with dependancy on create_mesh.py |
---|
67 | mesh, triagle_count = create_mesh(10000000) |
---|
68 | |
---|
69 | |
---|
70 | #meshname = project.meshname + '_%d.msh' %resolution |
---|
71 | #meshname = project.meshdir + 'lakes_small_100.msh' |
---|
72 | |
---|
73 | |
---|
74 | #Setup domain |
---|
75 | |
---|
76 | domain = cache(pmesh_instance_to_domain_instance, (mesh, Domain), |
---|
77 | #dependencies = [meshname], |
---|
78 | verbose = True) |
---|
79 | |
---|
80 | |
---|
81 | domain.set_name(project.basename) # + '_%d' %resolution) |
---|
82 | domain.set_datadir(project.outputdir) |
---|
83 | domain.store = True |
---|
84 | #domain.smooth = False |
---|
85 | |
---|
86 | |
---|
87 | #domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
88 | domain.quantities_to_be_stored = ['stage'] |
---|
89 | |
---|
90 | print 'Number of triangles = ', len(domain) |
---|
91 | print 'The extent is ', domain.get_extent() |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | #Setup Initial Conditions |
---|
96 | domain.set_quantity('friction', 0) |
---|
97 | domain.set_quantity('stage', project.tide) |
---|
98 | domain.set_quantity('elevation', |
---|
99 | filename = demname + '.pts', |
---|
100 | use_cache = True, |
---|
101 | verbose = True) |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | #Setup Boundary Conditions |
---|
106 | print domain.get_boundary_tags() |
---|
107 | |
---|
108 | Bf = File_boundary(project.boundary_basename + '.sww', domain, verbose = True) |
---|
109 | #domain.starttime = 3000 #Obtained from MOST |
---|
110 | domain.starttime = 0 #Obtained from MOST |
---|
111 | |
---|
112 | Br = Reflective_boundary(domain) |
---|
113 | Bt = Transmissive_boundary(domain) |
---|
114 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
115 | Bw = Time_boundary(domain=domain, |
---|
116 | f=lambda t: [(60<t<660)*4, 0, 0]) |
---|
117 | |
---|
118 | |
---|
119 | domain.set_boundary( {'back': Br,'side': Bd, 'ocean': Bf} ) #MOST tsunami |
---|
120 | |
---|
121 | #domain.set_boundary( {'back': Bd,'side': Bd, 'ocean': Bd} ) #Nothing |
---|
122 | |
---|
123 | |
---|
124 | #Evolve |
---|
125 | import time |
---|
126 | t0 = time.time() |
---|
127 | |
---|
128 | for t in domain.evolve(yieldstep = 60, finaltime = 40000): |
---|
129 | # skip_initial_step = True): |
---|
130 | domain.write_time() |
---|
131 | domain.write_boundary_statistics(tags = 'ocean') #quantities = 'stage') |
---|
132 | |
---|
133 | print 'That took %.2f seconds' %(time.time()-t0) |
---|