source: trunk/anuga_validation/automated_validation_tests/okushiri_tank_validation/create_okushiri.py @ 7877

Last change on this file since 7877 was 7877, checked in by hudson, 14 years ago

Moved all development files into trunk.

File size: 4.7 KB
Line 
1"""Create mesh and time boundary for the Okushiri island validation
2"""
3
4
5import numpy 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
11from anuga.config import netcdf_float
12
13import 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
26base_resolution = 1 # Use this to coarsen or refine entire mesh.
27
28# Basic geometry and bounding polygon
29xleft   = 0
30xright  = 5.448
31ybottom = 0
32ytop    = 3.402
33
34point_sw = [xleft, ybottom]
35point_se = [xright, ybottom]
36point_nw = [xleft, ytop]   
37point_ne = [xright, ytop]
38
39bounding_polygon = [point_se,
40                    point_ne,
41                    point_nw,
42                    point_sw]
43
44
45# Localised refined area for gulleys
46xl = 4.8
47xr = 5.3
48yb = 1.6
49yt = 2.3
50p0 = [xl, yb]
51p1 = [xr, yb]
52p2 = [xr, yt]
53p3 = [xl, yt]
54
55gulleys = [p0, p1, p2, p3]
56
57
58
59# Island area and drawdown region
60island_0 = [xleft + 2*(xright-xleft)/3+1.2, ytop-0.5]
61island_1 = [xleft + 2*(xright-xleft)/3+0.5, ybottom + 2*(ytop-ybottom)/3]
62island_2 = [xleft + (xright-xleft)/2+0.4, ybottom + 2*(ytop-ybottom)/3-0.3]
63island_3 = [xleft + (xright-xleft)/2+0.4, ybottom + (ytop-ybottom)/3+0.3]
64island_4 = [xleft + 2*(xright-xleft)/3+0.4, ybottom + (ytop-ybottom)/3-0.3]
65island_5 = [xleft + 2*(xright-xleft)/3+1.2, ybottom+0.8]
66island_6 = [xl-.01, yb]  # Keep right edge just off the gulleys
67island_7 = [xl-.01, yt]
68
69island = [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
76rhs_nw = [xleft + (xright-xleft)/3+1, ytop-1.4]
77rhs_sw = [xleft + (xright-xleft)/3+1, ybottom+0.5]
78rhs_se = [xright-0.1, ybottom+0.2]
79rhs_ne = [xright-0.1, ytop-0.2]       
80
81rhs_region = [rhs_nw, rhs_ne, rhs_se, rhs_sw]
82
83
84# Interior regions and creation of mesh
85interior_regions = [[rhs_region, 0.0005],
86                    [island, 0.0003*base_resolution],
87                    [gulleys, 0.00003*base_resolution]]   
88
89
90
91
92def 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
146def 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#-------------------------------------------------------------
168if __name__ == "__main__":
169    create_mesh()
170
171
Note: See TracBrowser for help on using the repository browser.