1 | |
---|
2 | #Convention for strings representing files |
---|
3 | # #_file has the extention |
---|
4 | # #name does not have the extension |
---|
5 | |
---|
6 | import time |
---|
7 | |
---|
8 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf,\ |
---|
9 | dem2pts, asc_csiro2sww |
---|
10 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
11 | from caching import cache |
---|
12 | from create_mesh2 import create_mesh |
---|
13 | from pyvolution.shallow_water import Domain, Reflective_boundary,\ |
---|
14 | File_boundary, Dirichlet_boundary, Time_boundary, Transmissive_boundary |
---|
15 | from pyvolution.least_squares import fit_to_mesh_file, DEFAULT_ALPHA |
---|
16 | |
---|
17 | # Import this last! It stuffs up the loading of c extensions otherwise. |
---|
18 | import project |
---|
19 | |
---|
20 | #Data preparation |
---|
21 | #Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
22 | # just interested in the boundary/ mesh intereaction first off. |
---|
23 | #cache(convert_dem_from_ascii2netcdf, demname, {'verbose': True}, |
---|
24 | # dependencies = [demname + '.asc'], |
---|
25 | # verbose = True) |
---|
26 | # #evaluate = True) |
---|
27 | |
---|
28 | cache(dem2pts, project.demname[:-4], {'verbose': True}, |
---|
29 | dependencies = [project.demname] |
---|
30 | ,verbose = False |
---|
31 | ) |
---|
32 | |
---|
33 | |
---|
34 | # Convert CSIRO boundary |
---|
35 | # NOTE: This function is dependent on a lot of files, and I haven't listed |
---|
36 | # them, since there is so many and I don't think they will be changing. |
---|
37 | cache(asc_csiro2sww, |
---|
38 | (project.bath_dir, |
---|
39 | project.elevation_dir, |
---|
40 | project.ucur_dir, |
---|
41 | project.vcur_dir, |
---|
42 | project.boundaryname), |
---|
43 | {'verbose': True, |
---|
44 | 'minlat': -38.25, |
---|
45 | 'maxlat': -37.7, |
---|
46 | 'minlon': 147.0, |
---|
47 | 'maxlon': 148.25, |
---|
48 | 'mean_stage': project.tide, |
---|
49 | 'zscale': 1, #Enhance storm surge |
---|
50 | 'fail_on_NaN': False} |
---|
51 | #,evaluate = True |
---|
52 | ,verbose = False |
---|
53 | ) |
---|
54 | |
---|
55 | meshname = project.meshname |
---|
56 | pointname = project.pointname |
---|
57 | mesh_elevname = project.mesh_elevname |
---|
58 | outputname = project.outputname |
---|
59 | |
---|
60 | t0 = time.time() |
---|
61 | #Create the mesh without elevation data |
---|
62 | # 100000 very course - 16,827 triangle mesh |
---|
63 | |
---|
64 | meshname, triagle_count = cache(create_mesh,(5000000), |
---|
65 | {'factor':1000, |
---|
66 | 'mesh_file':meshname, |
---|
67 | 'triangles_in_name':True} |
---|
68 | ,dependencies = ['create_mesh2.py'] |
---|
69 | #,evaluate = True |
---|
70 | ) |
---|
71 | |
---|
72 | mesh_elevname = mesh_elevname[:-9] + '_' + str(triagle_count) + \ |
---|
73 | mesh_elevname[-9:] |
---|
74 | outputname = outputname[:-4] + '_' + str(triagle_count) + outputname[-4:] |
---|
75 | |
---|
76 | |
---|
77 | #Add elevation data to the mesh |
---|
78 | #fit_to_mesh_file(mesh_file, point_file, mesh_output_file, DEFAULT_ALPHA, |
---|
79 | # verbose=True, expand_search=True, precrop=True) |
---|
80 | cache(fit_to_mesh_file,(meshname, |
---|
81 | pointname, |
---|
82 | mesh_elevname, |
---|
83 | DEFAULT_ALPHA), |
---|
84 | {'verbose': True, |
---|
85 | 'expand_search': True, |
---|
86 | 'precrop': True} |
---|
87 | ,dependencies = [meshname, pointname] |
---|
88 | #,evaluate = True |
---|
89 | ,verbose = False |
---|
90 | ) |
---|
91 | |
---|
92 | print 'Initialising the mesh took %.2f seconds' %(time.time()-t0) |
---|
93 | |
---|
94 | #Setup domain |
---|
95 | domain = cache(pmesh_to_domain_instance, (mesh_elevname, Domain), |
---|
96 | dependencies = [mesh_elevname] |
---|
97 | ,verbose = False |
---|
98 | ) |
---|
99 | |
---|
100 | |
---|
101 | domain.set_name(project.basename + '_%d' %triagle_count) |
---|
102 | domain.set_datadir(project.outputdir) |
---|
103 | domain.store = True |
---|
104 | domain.quantities_to_be_stored = ['stage'] |
---|
105 | |
---|
106 | print 'Number of triangles = ', len(domain) |
---|
107 | print 'The extent is ', domain.get_extent() |
---|
108 | |
---|
109 | #Setup Initial Conditions |
---|
110 | domain.set_quantity('friction', 0) |
---|
111 | domain.set_quantity('stage', project.tide) |
---|
112 | |
---|
113 | |
---|
114 | #Setup Boundary Conditions |
---|
115 | print domain.get_boundary_tags() |
---|
116 | |
---|
117 | print "****** run ****" |
---|
118 | print "project.boundaryname",project.boundaryname |
---|
119 | print "**********" |
---|
120 | |
---|
121 | Bf = File_boundary(project.boundaryname, domain, verbose = True) |
---|
122 | #domain.starttime = 3000 #Obtained from MOST |
---|
123 | domain.starttime = 0 #Obtained from MOST |
---|
124 | |
---|
125 | Br = Reflective_boundary(domain) |
---|
126 | Bt = Transmissive_boundary(domain) |
---|
127 | Bd = Dirichlet_boundary([project.tide,0,0]) |
---|
128 | #Bw = Time_boundary(domain=domain, |
---|
129 | # f=lambda t: [(60<t<660)*4, 0, 0]) |
---|
130 | |
---|
131 | domain.set_boundary( {'back': Br,'side': Br, 'ocean': Bf} ) #CSIRO storm surge |
---|
132 | |
---|
133 | #Evolve |
---|
134 | t0 = time.time() |
---|
135 | |
---|
136 | for t in domain.evolve(yieldstep = 300, finaltime = 432000): |
---|
137 | #for t in domain.evolve(yieldstep = 10, finaltime = 30): |
---|
138 | # skip_initial_step = True): |
---|
139 | domain.write_time() |
---|
140 | domain.write_boundary_statistics(tags = 'ocean') #quantities = 'stage') |
---|
141 | |
---|
142 | print 'That took %.2f seconds' %(time.time()-t0) |
---|