1 | """Create mesh and time boundary for the Okushiri island validation |
---|
2 | """ |
---|
3 | |
---|
4 | from Numeric import array, zeros, Float, allclose |
---|
5 | |
---|
6 | from anuga.pmesh.mesh import * |
---|
7 | from anuga.coordinate_transforms.geo_reference import Geo_reference |
---|
8 | |
---|
9 | import project |
---|
10 | |
---|
11 | |
---|
12 | def prepare_timeboundary(filename): |
---|
13 | """Converting benchmark 2 time series to NetCDF tms file. |
---|
14 | This is a 'throw-away' code taylor made for files like |
---|
15 | 'Benchmark_2_input.txt' from the LWRU2 benchmark |
---|
16 | """ |
---|
17 | |
---|
18 | textversion = filename[:-4] + '.txt' |
---|
19 | |
---|
20 | print 'Preparing time boundary from %s' %textversion |
---|
21 | from Numeric import array |
---|
22 | |
---|
23 | fid = open(textversion) |
---|
24 | |
---|
25 | #Skip first line |
---|
26 | line = fid.readline() |
---|
27 | |
---|
28 | #Read remaining lines |
---|
29 | lines = fid.readlines() |
---|
30 | fid.close() |
---|
31 | |
---|
32 | |
---|
33 | N = len(lines) |
---|
34 | T = zeros(N, Float) #Time |
---|
35 | Q = zeros(N, Float) #Values |
---|
36 | |
---|
37 | for i, line in enumerate(lines): |
---|
38 | fields = line.split() |
---|
39 | |
---|
40 | T[i] = float(fields[0]) |
---|
41 | Q[i] = float(fields[1]) |
---|
42 | |
---|
43 | |
---|
44 | #Create tms file |
---|
45 | from Scientific.IO.NetCDF import NetCDFFile |
---|
46 | |
---|
47 | print 'Writing to', filename |
---|
48 | fid = NetCDFFile(filename, 'w') |
---|
49 | |
---|
50 | fid.institution = 'Geoscience Australia' |
---|
51 | fid.description = 'Input wave for Benchmark 2' |
---|
52 | fid.starttime = 0.0 |
---|
53 | fid.createDimension('number_of_timesteps', len(T)) |
---|
54 | fid.createVariable('time', Float, ('number_of_timesteps',)) |
---|
55 | fid.variables['time'][:] = T |
---|
56 | |
---|
57 | fid.createVariable('stage', Float, ('number_of_timesteps',)) |
---|
58 | fid.variables['stage'][:] = Q[:] |
---|
59 | |
---|
60 | fid.createVariable('xmomentum', Float, ('number_of_timesteps',)) |
---|
61 | fid.variables['xmomentum'][:] = 0.0 |
---|
62 | |
---|
63 | fid.createVariable('ymomentum', Float, ('number_of_timesteps',)) |
---|
64 | fid.variables['ymomentum'][:] = 0.0 |
---|
65 | |
---|
66 | fid.close() |
---|
67 | |
---|
68 | |
---|
69 | #------------------------------------------------------------- |
---|
70 | if __name__ == "__main__": |
---|
71 | |
---|
72 | |
---|
73 | #Preparing points |
---|
74 | #(Only when using original Benchmark_2_Bathymetry.txt file) |
---|
75 | # FIXME: Replace by using geospatial data |
---|
76 | # |
---|
77 | #from anuga.abstract_2d_finite_volumes.data_manager import xya2pts |
---|
78 | #xya2pts(project.bathymetry_filename, verbose = True, |
---|
79 | # z_func = lambda z: -z) |
---|
80 | |
---|
81 | |
---|
82 | # Prepare time boundary |
---|
83 | prepare_timeboundary(project.boundary_filename) |
---|
84 | |
---|
85 | |
---|
86 | # Create Mesh |
---|
87 | |
---|
88 | #Basic geometry |
---|
89 | |
---|
90 | xleft = 0 |
---|
91 | xright = 5.448 |
---|
92 | ybottom = 0 |
---|
93 | ytop = 3.402 |
---|
94 | |
---|
95 | #Outline |
---|
96 | point_sw = [xleft, ybottom] |
---|
97 | point_se = [xright, ybottom] |
---|
98 | point_nw = [xleft, ytop] |
---|
99 | point_ne = [xright, ytop] |
---|
100 | |
---|
101 | #Midway points (left) |
---|
102 | point_mtop = [xleft + (xright-xleft)/3+1, ytop] |
---|
103 | point_mbottom = [xleft + (xright-xleft)/3+1, ybottom] |
---|
104 | |
---|
105 | |
---|
106 | geo = Geo_reference(xllcorner = xleft, |
---|
107 | yllcorner = ybottom) |
---|
108 | |
---|
109 | |
---|
110 | print "***********************" |
---|
111 | print "geo ref", geo |
---|
112 | print "***********************" |
---|
113 | |
---|
114 | m = Mesh(geo_reference=geo) |
---|
115 | |
---|
116 | #Boundary |
---|
117 | dict = {} |
---|
118 | dict['points'] = [point_se, #se |
---|
119 | point_ne, |
---|
120 | point_mtop, |
---|
121 | point_nw, |
---|
122 | point_sw, |
---|
123 | point_mbottom] |
---|
124 | |
---|
125 | |
---|
126 | dict['segments'] = [[0,1], [1,2], [2,3], [3,4], |
---|
127 | [4,5], [5,0], #The outer border |
---|
128 | [2,5]] #Separator |
---|
129 | |
---|
130 | dict['segment_tags'] = ['wall', |
---|
131 | 'wall', |
---|
132 | 'wall', |
---|
133 | 'wave', |
---|
134 | 'wall', |
---|
135 | 'wall', |
---|
136 | ''] #Interior |
---|
137 | |
---|
138 | |
---|
139 | m.addVertsSegs(dict) |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | #Localised refined area for gulleys |
---|
146 | dict = {} |
---|
147 | xl = 4.8 |
---|
148 | xr = 5.3 |
---|
149 | yb = 1.6 |
---|
150 | yt = 2.3 |
---|
151 | p0 = [xl, yb] |
---|
152 | p1 = [xr, yb] |
---|
153 | p2 = [xr, yt] |
---|
154 | p3 = [xl, yt] |
---|
155 | |
---|
156 | dict['points'] = [p0, p1, p2, p3] |
---|
157 | dict['segments'] = [[0,1], [1,2], [2,3], [3,0]] |
---|
158 | dict['segment_tags'] = ['', '', '', ''] |
---|
159 | m.addVertsSegs(dict) |
---|
160 | |
---|
161 | #Island area |
---|
162 | island_0 = [xleft + 2*(xright-xleft)/3+1.2, ytop-0.5] |
---|
163 | island_1 = [xleft + 2*(xright-xleft)/3+0.5, ybottom + 2*(ytop-ybottom)/3] |
---|
164 | island_2 = [xleft + (xright-xleft)/2+0.3, ybottom + 2*(ytop-ybottom)/3-0.3] |
---|
165 | island_3 = [xleft + (xright-xleft)/2+0.3, ybottom + (ytop-ybottom)/3+0.3] |
---|
166 | island_4 = [xleft + 2*(xright-xleft)/3+0.4, ybottom + (ytop-ybottom)/3-0.3] |
---|
167 | island_5 = [xleft + 2*(xright-xleft)/3+1.2, ybottom+0.2] |
---|
168 | island_6 = [xl-.01, yb] #OK |
---|
169 | island_7 = [xl-.01, yt] #OK |
---|
170 | |
---|
171 | |
---|
172 | dict['points'] = [island_0, island_1, island_2, |
---|
173 | island_3, island_4, island_5, |
---|
174 | #p0, p3] |
---|
175 | island_6, island_7] |
---|
176 | |
---|
177 | |
---|
178 | dict['segments'] = [[0,1], [1,2], [2,3], [3,4], |
---|
179 | [4,5], [5,6], [6,7], [7,0]] |
---|
180 | |
---|
181 | dict['segment_tags'] = ['', '', '', '', '', '', '', ''] |
---|
182 | |
---|
183 | |
---|
184 | m.addVertsSegs(dict) |
---|
185 | |
---|
186 | |
---|
187 | # |
---|
188 | |
---|
189 | base_resolution = 1 |
---|
190 | |
---|
191 | ocean = m.addRegionEN(xleft+.1, ybottom+.1) |
---|
192 | ocean.setMaxArea(0.1*base_resolution) |
---|
193 | |
---|
194 | mid = m.addRegionEN(point_mbottom[0]+.1, ybottom+.1) |
---|
195 | mid.setMaxArea(0.0005*base_resolution) |
---|
196 | |
---|
197 | |
---|
198 | #inner = m.addRegionEN(island_3[0]+.1, island_3[1]+.1) |
---|
199 | #inner.setMaxArea(0.00007*base_resolution) |
---|
200 | |
---|
201 | inner = m.addRegionEN(island_3[0]+.1, island_3[1]+.1) |
---|
202 | inner.setMaxArea(0.0003*base_resolution) |
---|
203 | |
---|
204 | |
---|
205 | gulleys = m.addRegionEN(p0[0]+0.1, p0[1]+0.1) |
---|
206 | gulleys.setMaxArea(0.00003*base_resolution) |
---|
207 | |
---|
208 | |
---|
209 | # From r 1709 11 August 2005 |
---|
210 | #base_resolution = 100 |
---|
211 | # |
---|
212 | #ocean = m.addRegionEN(xleft+.1, ybottom+.1) |
---|
213 | #ocean.setMaxArea(0.01*base_resolution) |
---|
214 | # |
---|
215 | #mid = m.addRegionEN(point_mbottom[0]+.1, ybottom+.1) |
---|
216 | #mid.setMaxArea(0.001*base_resolution) |
---|
217 | |
---|
218 | #inner = m.addRegionEN(island_3[0]+.1, island_3[1]+.1) |
---|
219 | #inner.setMaxArea(0.0001*base_resolution) |
---|
220 | |
---|
221 | |
---|
222 | #gulleys = m.addRegionEN(p0[0]+0.1, p0[1]+0.1) |
---|
223 | #gulleys.setMaxArea(0.00001*base_resolution) |
---|
224 | |
---|
225 | |
---|
226 | m.generateMesh('pzq28.0za1000000a') |
---|
227 | |
---|
228 | import project |
---|
229 | m.export_mesh_file(project.mesh_filename) |
---|
230 | |
---|