1 | """ |
---|
2 | Main meribula script using new interface |
---|
3 | """ |
---|
4 | |
---|
5 | #------------------------------- |
---|
6 | # Module imports |
---|
7 | #------------------------------- |
---|
8 | import sys, os |
---|
9 | from pyvolution.shallow_water import Domain, Reflective_boundary,\ |
---|
10 | File_boundary, Transmissive_Momentum_Set_Stage_boundary,\ |
---|
11 | Wind_stress |
---|
12 | from pyvolution.util import file_function |
---|
13 | from pyvolution.mesh_factory import rectangular_cross |
---|
14 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
15 | from utilities.polygon import Polygon_function, read_polygon |
---|
16 | from Numeric import array, zeros, Float, allclose |
---|
17 | import project |
---|
18 | from caching import cache |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | #------------------------------- |
---|
24 | # Domain |
---|
25 | #------------------------------- |
---|
26 | print 'Creating domain from', project.mesh_filename |
---|
27 | |
---|
28 | domain = cache(pmesh_to_domain_instance, |
---|
29 | (project.mesh_filename, Domain), |
---|
30 | dependencies = [project.mesh_filename]) |
---|
31 | |
---|
32 | domain.check_integrity() |
---|
33 | print 'Number of triangles = ', len(domain) |
---|
34 | print 'The extent is ', domain.get_extent() |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | #------------------------------- |
---|
39 | # Initial Conditions |
---|
40 | #------------------------------- |
---|
41 | print 'Initial values' |
---|
42 | |
---|
43 | domain.set_quantity('elevation', |
---|
44 | filename = project.bathymetry_filename[:-4] + '.xya', |
---|
45 | alpha = 10.0, |
---|
46 | verbose = True, |
---|
47 | use_cache = True) |
---|
48 | |
---|
49 | domain.set_quantity('stage', 0.0) |
---|
50 | |
---|
51 | #------------------------------- |
---|
52 | # Setup Friction (due to weeds) |
---|
53 | #------------------------------- |
---|
54 | def image_points_to_northing_eastings(points): |
---|
55 | #print points |
---|
56 | n = len(points) |
---|
57 | #print n |
---|
58 | z = [] |
---|
59 | for i in range(n): |
---|
60 | #print i |
---|
61 | z.append([0,0]) |
---|
62 | z[i][0] = 755471.4 + (points[i][0] + 3250.)/1.125 |
---|
63 | z[i][1] = 5910260.0 + (points[i][1] + 1337.)/1.12 |
---|
64 | #print z |
---|
65 | return z |
---|
66 | |
---|
67 | #------------------------------------------ |
---|
68 | # Set friction for different bed types |
---|
69 | #------------------------------------------ |
---|
70 | # Sand bed |
---|
71 | w = 0.01 |
---|
72 | # Saltmarsh |
---|
73 | g = 0.060 |
---|
74 | # Paddle weed |
---|
75 | y = 0.025 |
---|
76 | # Eel grass |
---|
77 | r = 0.035 |
---|
78 | # Mangroves |
---|
79 | c = 0.065 |
---|
80 | # Strap weed |
---|
81 | b = 0.040 |
---|
82 | |
---|
83 | #----------------------------------------------- |
---|
84 | # Set the whole region to a constant value |
---|
85 | #----------------------------------------------- |
---|
86 | weed_zoneall = image_points_to_northing_eastings([[-2269,-1337],[1894,-1339],[1894,2946],[-2669,2946]]) |
---|
87 | |
---|
88 | #--------------------------------------- |
---|
89 | # Read friction polygon boundaries |
---|
90 | #--------------------------------------- |
---|
91 | weed_zone47 = image_points_to_northing_eastings(read_polygon('weed_zone.047',split=' ')) |
---|
92 | weed_zone2 = image_points_to_northing_eastings(read_polygon('weed_zone.002',split=' ')) |
---|
93 | weed_zone12 = image_points_to_northing_eastings(read_polygon('weed_zone.012',split=' ')) |
---|
94 | weed_zone35 = image_points_to_northing_eastings(read_polygon('weed_zone.035',split=' ')) |
---|
95 | weed_zone8 = image_points_to_northing_eastings(read_polygon('weed_zone.008',split=' ')) |
---|
96 | weed_zone10 = image_points_to_northing_eastings(read_polygon('weed_zone.010',split=' ')) |
---|
97 | weed_zone13 = image_points_to_northing_eastings(read_polygon('weed_zone.013',split=' ')) |
---|
98 | weed_zone15 = image_points_to_northing_eastings(read_polygon('weed_zone.015',split=' ')) |
---|
99 | weed_zone19 = image_points_to_northing_eastings(read_polygon('weed_zone.019',split=' ')) |
---|
100 | weed_zone18 = image_points_to_northing_eastings(read_polygon('weed_zone.018',split=' ')) |
---|
101 | weed_zone24 = image_points_to_northing_eastings(read_polygon('weed_zone.024',split=' ')) |
---|
102 | weed_zone26 = image_points_to_northing_eastings(read_polygon('weed_zone.026',split=' ')) |
---|
103 | weed_zone27 = image_points_to_northing_eastings(read_polygon('weed_zone.027',split=' ')) |
---|
104 | weed_zone32 = image_points_to_northing_eastings(read_polygon('weed_zone.032',split=' ')) |
---|
105 | weed_zone31 = image_points_to_northing_eastings(read_polygon('weed_zone.031',split=' ')) |
---|
106 | weed_zone33 = image_points_to_northing_eastings(read_polygon('weed_zone.033',split=' ')) |
---|
107 | weed_zone34 = image_points_to_northing_eastings(read_polygon('weed_zone.034',split=' ')) |
---|
108 | weed_zone36 = image_points_to_northing_eastings(read_polygon('weed_zone.036',split=' ')) |
---|
109 | weed_zone37 = image_points_to_northing_eastings(read_polygon('weed_zone.037',split=' ')) |
---|
110 | weed_zone38 = image_points_to_northing_eastings(read_polygon('weed_zone.038',split=' ')) |
---|
111 | weed_zone40 = image_points_to_northing_eastings(read_polygon('weed_zone.040',split=' ')) |
---|
112 | weed_zone41 = image_points_to_northing_eastings(read_polygon('weed_zone.041',split=' ')) |
---|
113 | weed_zone42 = image_points_to_northing_eastings(read_polygon('weed_zone.042',split=' ')) |
---|
114 | weed_zone43 = image_points_to_northing_eastings(read_polygon('weed_zone.043',split=' ')) |
---|
115 | weed_zone44 = image_points_to_northing_eastings(read_polygon('weed_zone.044',split=' ')) |
---|
116 | weed_zone45 = image_points_to_northing_eastings(read_polygon('weed_zone.045',split=' ')) |
---|
117 | weed_zone46 = image_points_to_northing_eastings(read_polygon('weed_zone.046',split=' ')) |
---|
118 | weed_zone1 = image_points_to_northing_eastings(read_polygon('weed_zone.001',split=' ')) |
---|
119 | weed_zone20 = image_points_to_northing_eastings(read_polygon('weed_zone.020',split=' ')) |
---|
120 | weed_zone21 = image_points_to_northing_eastings(read_polygon('weed_zone.021',split=' ')) |
---|
121 | weed_zone22 = image_points_to_northing_eastings(read_polygon('weed_zone.022',split=' ')) |
---|
122 | weed_zone23 = image_points_to_northing_eastings(read_polygon('weed_zone.023',split=' ')) |
---|
123 | weed_zone25 = image_points_to_northing_eastings(read_polygon('weed_zone.025',split=' ')) |
---|
124 | weed_zone16 = image_points_to_northing_eastings(read_polygon('weed_zone.016',split=' ')) |
---|
125 | weed_zone17 = image_points_to_northing_eastings(read_polygon('weed_zone.017',split=' ')) |
---|
126 | weed_zone3 = image_points_to_northing_eastings(read_polygon('weed_zone.003',split=' ')) |
---|
127 | weed_zone6 = image_points_to_northing_eastings(read_polygon('weed_zone.006',split=' ')) |
---|
128 | weed_zone7 = image_points_to_northing_eastings(read_polygon('weed_zone.007',split=' ')) |
---|
129 | weed_zone9 = image_points_to_northing_eastings(read_polygon('weed_zone.009',split=' ')) |
---|
130 | weed_zone4 = image_points_to_northing_eastings(read_polygon('weed_zone.004',split=' ')) |
---|
131 | weed_zone39 = image_points_to_northing_eastings(read_polygon('weed_zone.039',split=' ')) |
---|
132 | weed_zone28 = image_points_to_northing_eastings(read_polygon('weed_zone.028',split=' ')) |
---|
133 | weed_zone29 = image_points_to_northing_eastings(read_polygon('weed_zone.029',split=' ')) |
---|
134 | weed_zone30 = image_points_to_northing_eastings(read_polygon('weed_zone.030',split=' ')) |
---|
135 | weed_zone5 = image_points_to_northing_eastings(read_polygon('weed_zone.005',split=' ')) |
---|
136 | weed_zone11 = image_points_to_northing_eastings(read_polygon('weed_zone.011',split=' ')) |
---|
137 | weed_zone14 = image_points_to_northing_eastings(read_polygon('weed_zone.014',split=' ')) |
---|
138 | |
---|
139 | domain.set_quantity('friction',Polygon_function([ \ |
---|
140 | (weed_zone15, g), (weed_zone19, c), (weed_zone18, g), (weed_zone24, c), \ |
---|
141 | (weed_zone26, r), (weed_zone27, g), (weed_zone32, c), (weed_zone31, g), \ |
---|
142 | (weed_zone33, r), (weed_zone34, g), (weed_zone36, r), (weed_zone37, g), \ |
---|
143 | (weed_zone38, g), (weed_zone40, r), (weed_zone41, b), (weed_zone42, r), \ |
---|
144 | (weed_zone43, r), (weed_zone44, r), (weed_zone45, b), (weed_zone46, r), \ |
---|
145 | (weed_zone1, w), (weed_zone20, w), (weed_zone21, w), (weed_zone22, w), \ |
---|
146 | (weed_zone23, w), (weed_zone25, w), (weed_zone16, w), (weed_zone17, w), \ |
---|
147 | (weed_zone3, w), (weed_zone6, w), (weed_zone7, w), (weed_zone9, w), \ |
---|
148 | (weed_zone4, b), (weed_zone39, b), (weed_zone28, r), (weed_zone29, b), \ |
---|
149 | (weed_zone30, b), (weed_zone5, b), (weed_zone11, b), (weed_zone14, b) ])) |
---|
150 | |
---|
151 | |
---|
152 | #--------------------------------------------- |
---|
153 | # Wind field |
---|
154 | # Format is time [DD/MM/YY hh:mm:ss], speed [m/s] direction (degrees) |
---|
155 | # This method is linearly interpolating the bearings and so will lead to |
---|
156 | # close to bearing = 0 and 360! |
---|
157 | #--------------------------------------------- |
---|
158 | #filename = project.original_wind_filename[:-4]+'.tms' |
---|
159 | #print 'Wind field from ',filename |
---|
160 | #wind = file_function(filename, domain=domain, quantities=['speed','bearing']) |
---|
161 | #domain.forcing_terms.append(Wind_stress(wind)) |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | #------------------------------- |
---|
166 | # Boundary conditions |
---|
167 | #------------------------------- |
---|
168 | print 'Boundaries' |
---|
169 | |
---|
170 | # Tidal cycle recorded at Eden as open |
---|
171 | print 'Open sea boundary condition from ',project.boundary_filename |
---|
172 | from pyvolution.util import file_function |
---|
173 | tide_function = file_function(project.boundary_filename[:-4] + '.tms', domain, |
---|
174 | verbose = True) |
---|
175 | Bts = Transmissive_Momentum_Set_Stage_boundary(domain, tide_function) |
---|
176 | |
---|
177 | # All other boundaries are reflective |
---|
178 | Br = Reflective_boundary(domain) |
---|
179 | |
---|
180 | domain.set_boundary({'exterior': Br, 'open': Bts}) |
---|
181 | |
---|
182 | #------------------------------- |
---|
183 | # Setup domain runtime parameters |
---|
184 | #------------------------------- |
---|
185 | domain.visualise = False |
---|
186 | domain.visualise_color_stage = True |
---|
187 | |
---|
188 | base = os.path.basename(sys.argv[0]) |
---|
189 | domain.filename, _ = os.path.splitext(base) |
---|
190 | domain.default_order = 2 |
---|
191 | domain.store = True #Store for visualisation purposes |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | #------------------------------- |
---|
196 | # Evolve |
---|
197 | #------------------------------- |
---|
198 | import time |
---|
199 | t0 = time.time() |
---|
200 | yieldstep = 10 |
---|
201 | finaltime = 60 |
---|
202 | |
---|
203 | |
---|
204 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
205 | domain.write_time() |
---|
206 | print wind(t) |
---|
207 | |
---|
208 | print 'That took %.2f seconds' %(time.time()-t0) |
---|