source: anuga_validation/automated_validation_tests/okushiri_tank_validation/create_okushiri.py @ 3916

Last change on this file since 3916 was 3916, checked in by ole, 17 years ago

Second stab at automatic validation using okushiri data

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