1 | """Create mesh and time boundary for the Okushiri island validation |
---|
2 | """ |
---|
3 | |
---|
4 | |
---|
5 | import numpy as num |
---|
6 | |
---|
7 | from anuga.pmesh.mesh import * |
---|
8 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
9 | from anuga.coordinate_transforms.geo_reference import Geo_reference |
---|
10 | from anuga.geospatial_data import Geospatial_data |
---|
11 | from anuga.config import netcdf_float |
---|
12 | |
---|
13 | import project |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | #-------------------------------------------------------------------------- |
---|
19 | # Create the triangular mesh based on overall clipping polygon with a |
---|
20 | # tagged |
---|
21 | # boundary and interior regions defined in project.py along with |
---|
22 | # resolutions (maximal area of per triangle) for each polygon |
---|
23 | #-------------------------------------------------------------------------- |
---|
24 | |
---|
25 | |
---|
26 | base_resolution = 1 # Use this to coarsen or refine entire mesh. |
---|
27 | |
---|
28 | # Basic geometry and bounding polygon |
---|
29 | xleft = 0 |
---|
30 | xright = 5.448 |
---|
31 | ybottom = 0 |
---|
32 | ytop = 3.402 |
---|
33 | |
---|
34 | point_sw = [xleft, ybottom] |
---|
35 | point_se = [xright, ybottom] |
---|
36 | point_nw = [xleft, ytop] |
---|
37 | point_ne = [xright, ytop] |
---|
38 | |
---|
39 | bounding_polygon = [point_se, |
---|
40 | point_ne, |
---|
41 | point_nw, |
---|
42 | point_sw] |
---|
43 | |
---|
44 | |
---|
45 | # Localised refined area for gulleys |
---|
46 | xl = 4.8 |
---|
47 | xr = 5.3 |
---|
48 | yb = 1.6 |
---|
49 | yt = 2.3 |
---|
50 | p0 = [xl, yb] |
---|
51 | p1 = [xr, yb] |
---|
52 | p2 = [xr, yt] |
---|
53 | p3 = [xl, yt] |
---|
54 | |
---|
55 | gulleys = [p0, p1, p2, p3] |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | # Island area and drawdown region |
---|
60 | island_0 = [xleft + 2*(xright-xleft)/3+1.2, ytop-0.5] |
---|
61 | island_1 = [xleft + 2*(xright-xleft)/3+0.5, ybottom + 2*(ytop-ybottom)/3] |
---|
62 | island_2 = [xleft + (xright-xleft)/2+0.4, ybottom + 2*(ytop-ybottom)/3-0.3] |
---|
63 | island_3 = [xleft + (xright-xleft)/2+0.4, ybottom + (ytop-ybottom)/3+0.3] |
---|
64 | island_4 = [xleft + 2*(xright-xleft)/3+0.4, ybottom + (ytop-ybottom)/3-0.3] |
---|
65 | island_5 = [xleft + 2*(xright-xleft)/3+1.2, ybottom+0.8] |
---|
66 | island_6 = [xl-.01, yb] # Keep right edge just off the gulleys |
---|
67 | island_7 = [xl-.01, yt] |
---|
68 | |
---|
69 | island = [island_0, island_1, island_2, |
---|
70 | island_3, island_4, island_5, |
---|
71 | island_6, island_7] |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | # Region spanning half right hand side of domain just inside boundary |
---|
76 | rhs_nw = [xleft + (xright-xleft)/3+1, ytop-1.4] |
---|
77 | rhs_sw = [xleft + (xright-xleft)/3+1, ybottom+0.5] |
---|
78 | rhs_se = [xright-0.1, ybottom+0.2] |
---|
79 | rhs_ne = [xright-0.1, ytop-0.2] |
---|
80 | |
---|
81 | rhs_region = [rhs_nw, rhs_ne, rhs_se, rhs_sw] |
---|
82 | |
---|
83 | |
---|
84 | # Interior regions and creation of mesh |
---|
85 | interior_regions = [[rhs_region, 0.0005], |
---|
86 | [island, 0.0003*base_resolution], |
---|
87 | [gulleys, 0.00003*base_resolution]] |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | def prepare_timeboundary(filename): |
---|
93 | """Convert benchmark 2 time series to NetCDF tms file. |
---|
94 | This is a 'throw-away' code taylor made for files like |
---|
95 | 'Benchmark_2_input.txt' from the LWRU2 benchmark |
---|
96 | """ |
---|
97 | |
---|
98 | from Scientific.IO.NetCDF import NetCDFFile |
---|
99 | |
---|
100 | print 'Creating', filename |
---|
101 | |
---|
102 | # Read the ascii (.txt) version of this file |
---|
103 | fid = open(filename[:-4] + '.txt') |
---|
104 | |
---|
105 | # Skip first line |
---|
106 | line = fid.readline() |
---|
107 | |
---|
108 | # Read remaining lines |
---|
109 | lines = fid.readlines() |
---|
110 | fid.close() |
---|
111 | |
---|
112 | |
---|
113 | N = len(lines) |
---|
114 | T = num.zeros(N, num.float) #Time |
---|
115 | Q = num.zeros(N, num.float) #Values |
---|
116 | |
---|
117 | for i, line in enumerate(lines): |
---|
118 | fields = line.split() |
---|
119 | |
---|
120 | T[i] = float(fields[0]) |
---|
121 | Q[i] = float(fields[1]) |
---|
122 | |
---|
123 | |
---|
124 | # Create tms NetCDF file |
---|
125 | |
---|
126 | fid = NetCDFFile(filename, 'w') |
---|
127 | fid.institution = 'Geoscience Australia' |
---|
128 | fid.description = 'Input wave for Benchmark 2' |
---|
129 | fid.starttime = 0.0 |
---|
130 | fid.createDimension('number_of_timesteps', len(T)) |
---|
131 | fid.createVariable('time', netcdf_float, ('number_of_timesteps',)) |
---|
132 | fid.variables['time'][:] = T |
---|
133 | |
---|
134 | fid.createVariable('stage', netcdf_float, ('number_of_timesteps',)) |
---|
135 | fid.variables['stage'][:] = Q[:] |
---|
136 | |
---|
137 | fid.createVariable('xmomentum', netcdf_float, ('number_of_timesteps',)) |
---|
138 | fid.variables['xmomentum'][:] = 0.0 |
---|
139 | |
---|
140 | fid.createVariable('ymomentum', netcdf_float, ('number_of_timesteps',)) |
---|
141 | fid.variables['ymomentum'][:] = 0.0 |
---|
142 | |
---|
143 | fid.close() |
---|
144 | |
---|
145 | |
---|
146 | def create_mesh(elevation_in_mesh=False): |
---|
147 | # Prepare time boundary |
---|
148 | prepare_timeboundary(project.boundary_filename) |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | meshname = project.mesh_filename + '.msh' |
---|
153 | m = create_mesh_from_regions(bounding_polygon, |
---|
154 | boundary_tags={'wall': [0, 1, 3], |
---|
155 | 'wave': [2]}, |
---|
156 | maximum_triangle_area=0.1*base_resolution, |
---|
157 | interior_regions=interior_regions, |
---|
158 | filename=project.mesh_filename, |
---|
159 | use_cache=False, |
---|
160 | verbose=True) |
---|
161 | |
---|
162 | if elevation_in_mesh is True: |
---|
163 | fit_to_mesh_file(project.mesh_filename, project.bathymetry_filename, |
---|
164 | project.mesh_filename) |
---|
165 | |
---|
166 | |
---|
167 | #------------------------------------------------------------- |
---|
168 | if __name__ == "__main__": |
---|
169 | create_mesh() |
---|
170 | |
---|
171 | |
---|