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 | # 50000 seems to be a show stopper - 333,756 triangle mesh |
---|
64 | meshname, triagle_count = cache(create_mesh,(100002), |
---|
65 | {'mesh_file':meshname, |
---|
66 | 'triangles_in_name':True} |
---|
67 | ,dependencies = ['create_mesh2.py'] |
---|
68 | #,evaluate = True |
---|
69 | ) |
---|
70 | |
---|
71 | mesh_elevname = mesh_elevname[:-9] + '_' + str(triagle_count) + \ |
---|
72 | mesh_elevname[-9:] |
---|
73 | outputname = outputname[:-4] + '_' + str(triagle_count) + outputname[-4:] |
---|
74 | |
---|
75 | |
---|
76 | #Add elevation data to the mesh |
---|
77 | #fit_to_mesh_file(mesh_file, point_file, mesh_output_file, DEFAULT_ALPHA, |
---|
78 | # verbose=True, expand_search=True, precrop=True) |
---|
79 | cache(fit_to_mesh_file,(meshname, |
---|
80 | pointname, |
---|
81 | mesh_elevname, |
---|
82 | DEFAULT_ALPHA), |
---|
83 | {'verbose': True, |
---|
84 | 'expand_search': True, |
---|
85 | 'precrop': True} |
---|
86 | ,dependencies = [meshname, pointname] |
---|
87 | #,evaluate = True |
---|
88 | ,verbose = False |
---|
89 | ) |
---|
90 | |
---|
91 | print 'Initialising the mesh took %.2f seconds' %(time.time()-t0) |
---|
92 | |
---|
93 | #Setup domain |
---|
94 | domain = cache(pmesh_to_domain_instance, (mesh_elevname, Domain), |
---|
95 | dependencies = [mesh_elevname] |
---|
96 | ,verbose = False |
---|
97 | ) |
---|
98 | |
---|
99 | |
---|
100 | domain.set_name(project.basename + '_%d' %triagle_count) |
---|
101 | domain.set_datadir(project.outputdir) |
---|
102 | domain.store = True |
---|
103 | domain.quantities_to_be_stored = ['stage'] |
---|
104 | |
---|
105 | print 'Number of triangles = ', len(domain) |
---|
106 | print 'The extent is ', domain.get_extent() |
---|
107 | |
---|
108 | #Setup Initial Conditions |
---|
109 | domain.set_quantity('friction', 0) |
---|
110 | domain.set_quantity('stage', project.tide) |
---|
111 | |
---|
112 | |
---|
113 | #Setup Boundary Conditions |
---|
114 | print domain.get_boundary_tags() |
---|
115 | |
---|
116 | print "****** run ****" |
---|
117 | print "project.boundaryname",project.boundaryname |
---|
118 | print "**********" |
---|
119 | |
---|
120 | Bf = File_boundary(project.boundaryname, domain, verbose = True) |
---|
121 | #domain.starttime = 3000 #Obtained from MOST |
---|
122 | domain.starttime = 0 #Obtained from MOST |
---|
123 | |
---|
124 | Br = Reflective_boundary(domain) |
---|
125 | Bt = Transmissive_boundary(domain) |
---|
126 | Bd = Dirichlet_boundary([project.tide,0,0]) |
---|
127 | #Bw = Time_boundary(domain=domain, |
---|
128 | # f=lambda t: [(60<t<660)*4, 0, 0]) |
---|
129 | |
---|
130 | domain.set_boundary( {'back': Br,'side': Bf, 'ocean': Bf} ) #CSIRO storm surge |
---|
131 | |
---|
132 | #Evolve |
---|
133 | t0 = time.time() |
---|
134 | |
---|
135 | #for t in domain.evolve(yieldstep = 60, finaltime = 30000): |
---|
136 | for t in domain.evolve(yieldstep = 10, finaltime = 30): |
---|
137 | # skip_initial_step = True): |
---|
138 | domain.write_time() |
---|
139 | domain.write_boundary_statistics(tags = 'ocean') #quantities = 'stage') |
---|
140 | |
---|
141 | print 'That took %.2f seconds' %(time.time()-t0) |
---|