source: branches/numpy_anuga_validation/okushiri_2005/create_okushiri.py

Last change on this file was 7184, checked in by rwilson, 16 years ago

Updated all licence files to use new checksum.

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