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

Last change on this file since 6160 was 6160, checked in by rwilson, 15 years ago

Change Numeric imports to general form - ready to change to NumPy?.

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