source: anuga_validation/conical_island/run_circular.py @ 4987

Last change on this file since 4987 was 4987, checked in by nick, 16 years ago

run_circular now uses a function to define the water tank. This is more accurate and reduces the IO compared to reading a file.

File size: 8.6 KB
Line 
1"""Validation of the AnuGA implementation of the shallow water wave equation.
2
3This script sets up 2D circular island.....
4
5"""
6
7# Module imports
8from anuga.shallow_water import Domain
9from anuga.shallow_water import Reflective_boundary
10from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary
11from anuga.shallow_water import Dirichlet_boundary, Time_boundary
12from anuga.shallow_water.data_manager import get_maximum_inundation_data
13from anuga.abstract_2d_finite_volumes.util import file_function, sww2csv_gauges
14from anuga.pmesh.mesh_interface import create_mesh_from_regions
15from anuga.utilities.polygon import read_polygon#, plot_polygons
16#from cmath import cos,sin,cosh,pi
17from math import cos,pi,sin,tan,sqrt
18from Numeric import array, zeros, Float, allclose,resize
19from anuga.shallow_water.data_manager import csv2dict
20
21#-------------------------
22# Create Domain from mesh
23#-------------------------
24
25def get_xy(x=0,y=0,r=1,angle=1):
26    x1 = x + cos(angle)*r
27    y1 = y + sin(-angle)*r
28#    print "get",x,y,r,x1,y1,"angle",angle, cos(angle),sin(angle)
29    return x1,y1,
30
31def prepare_timeboundary(filename):
32    """Converting benchmark 2 time series to NetCDF tms file.
33    This is a 'throw-away' code taylor made for files like
34    'Benchmark_2_input.txt' from the LWRU2 benchmark
35    """
36
37    textversion = filename[:-4] + '.txt'
38
39    print 'Preparing time boundary from %s' %textversion
40    from Numeric import array
41
42    fid = open(textversion)
43
44    #Skip first line
45    line = fid.readline()
46
47    #Read remaining lines
48    lines = fid.readlines()
49    fid.close()
50
51
52    N = len(lines)
53    T = zeros(N, Float)  #Time
54    Q = zeros(N, Float)  #Values
55
56    for i, line in enumerate(lines):
57        fields = line.split()
58#        print 'fields',i,line
59
60        T[i] = float(fields[0])
61        Q[i] = float(fields[1])
62
63
64    #Create tms file
65    from Scientific.IO.NetCDF import NetCDFFile
66
67    print 'Writing to', filename
68    fid = NetCDFFile(filename[:-4] + '.tms', 'w')
69
70    fid.institution = 'Geoscience Australia'
71    fid.description = 'Input wave for Benchmark 2'
72    fid.starttime = 0.0
73    fid.createDimension('number_of_timesteps', len(T))
74    fid.createVariable('time', Float, ('number_of_timesteps',))
75    fid.variables['time'][:] = T
76
77    fid.createVariable('stage', Float, ('number_of_timesteps',))
78    fid.variables['stage'][:] = Q[:]
79
80    fid.createVariable('xmomentum', Float, ('number_of_timesteps',))
81    fid.variables['xmomentum'][:] = 0.0
82
83    fid.createVariable('ymomentum', Float, ('number_of_timesteps',))
84    fid.variables['ymomentum'][:] = 0.0
85
86    fid.close()
87
88
89
90angles1 = (0.0, 22.5, 45.0, 67.5, 90.0, 112.5, 135.0, 157.5, 180.0, 202.5, 225.0,
91          247.5, 270.0, 292.5, 315.0, 337.5)
92
93x = 12.96
94y = 13.80
95r1 = 1.5
96r2 = 2.5
97d=0.75
98res=.05
99#res=1.
100
101#create polygons (circles) to have higher resolution
102poly = []
103poly1 = []
104internal_poly=[]
105for i,angle in enumerate(angles1):
106    #convert Degs to Rads
107    angle = ((angle-180)/180.0)*pi
108
109    p = get_xy(x,y,3.6,angle)
110    poly1.append([p[0],p[1]])
111
112poly.append(poly1)
113internal_poly.append([poly1,.1*res])
114
115poly2 = []
116for i,angle in enumerate(angles1):
117    #convert Degs to Rads
118    angle = ((angle-180)/180.0)*pi
119    p = get_xy(x,y,2.4,angle)
120    poly2.append([p[0],p[1]])
121   
122poly.append(poly2)
123internal_poly.append([poly2,.01*res])
124
125poly3 = []
126for i,angle in enumerate(angles1):
127    #convert Degs to Rads
128    angle = ((angle-180)/180.0)*pi
129    p = get_xy(x,y,1.6,angle)
130    poly3.append([p[0],p[1]])
131   
132poly.append(poly3)
133internal_poly.append([poly3,1*res])
134
135poly4 = []
136for i,angle in enumerate(angles1):
137    #convert Degs to Rads
138    angle = ((angle-180)/180.0)*pi
139    p = get_xy(x,y,1.1,angle)
140    poly4.append([p[0],p[1]])
141   
142poly.append(poly4)
143internal_poly.append([poly2,.01*res])
144
145#plot_polygons(poly,'poly.png')
146
147poly_all= [[0,7],[0,25],[30,25],[30,7]]
148create_mesh_from_regions(poly_all,
149                         boundary_tags={'wall': [0,2],'wave': [3], 'buffer':[1]},
150                         maximum_triangle_area=1,
151                         interior_regions=internal_poly,
152                         filename='temp.msh',
153                         use_cache=False,
154                         verbose=True)
155
156domain = Domain('temp.msh', use_cache=True, verbose=True)
157print domain.statistics()
158
159#-------------------------
160# Initial Conditions
161#-------------------------
162domain.set_quantity('friction', 0.0)
163water_height = 0.322
164domain.set_quantity('stage', water_height)
165
166#attribute_dic, title_index_dic = csv2dict('sqrt_table.csv')
167attribute_dic, title_index_dic = csv2dict('sqrt_table_new.csv')
168print attribute_dic['number'][10]
169
170def test(x,y):
171    center_x = 12.96
172#    center_y = 13.80
173    center_y = 6.80
174
175    du = (center_x-x)**2+(center_y-y)**2
176#    print 'x',min(x),max(x)
177#    print 'y',min(y),max(y)
178    z1=[]
179    for d in du:
180        # this finds the int that relates to the correct sqrt in the table
181        nn=int(round(d,2)*100)
182        zz=-float(attribute_dic['sqrt'][nn])
183#        print nn,zz
184        # this is the elevation for a cone with 1/4 slope and is ?? below the water .
185        z = zz*.25+0.8975
186
187        if z <0:
188            z=0
189        if z > .625:
190            z=0.625
191        print 'hello',d,nn,zz,z
192#        print 'hello',d,n1,n2,n3,nn,zz,z
193        z1.append(z)
194    return z1
195
196domain.set_quantity('elevation',test, alpha=1., verbose=True)
197
198
199#-------------------------
200# Set simulation parameters
201#-------------------------
202domain.set_name('test1')  # Name of output sww file
203domain.set_default_order(1)               # Apply second order scheme
204#domain.set_all_limiters(0.9)              # Max second order scheme (old lim)
205domain.set_minimum_storable_height(0.001) # Don't store w < 0.001m
206domain.set_maximum_allowed_speed(0.1)     # Allow a little runoff (0.1 is OK)
207domain.tight_slope_limiters = 1
208domain.beta_h = 0.0
209
210#Timings on AMD64-242 (beta_h=0)
211#  tight_slope_limiters = 0:
212#    3035s - 3110s
213#  tight_slope_limiters = 1:
214#    3000s - 3008s
215#
216# beta_h>0: In the order of 3200s
217
218#-------------------------
219# Boundary Conditions
220#-------------------------
221
222# Create boundary function from timeseries provided in file
223#function = file_function(project.boundary_filename,
224#                         domain, verbose=True)
225def waveform(t): 
226        return (sin(t*2*pi))
227
228# Create and assign boundary objects
229boundary_filename="ts2cnew1_input"
230prepare_timeboundary(boundary_filename+'.txt')
231
232function = file_function(boundary_filename+'.tms',
233                         domain, verbose=True)
234
235# Create and assign boundary objects
236Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
237
238#Bts = Transmissive_Momentum_Set_Stage_boundary(domain, waveform)
239Bw = Time_boundary(domain=domain,
240                   f=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0])
241Br = Reflective_boundary(domain)
242Bd = Dirichlet_boundary([water_height,0,0])
243domain.set_boundary({'wave': Bts, 'wall': Br, 'buffer':Bd})
244domain.starttime = 10
245#-------------------------
246# Evolve through time
247#-------------------------
248import time
249t0 = time.time()
250
251for t in domain.evolve(yieldstep = 1, finaltime = 30):
252    domain.write_time()
253#    domain.write_time(track_speeds=False)
254
255for t in domain.evolve(yieldstep = 0.1, finaltime = 36
256#for t in domain.evolve(yieldstep = 0.5, finaltime = 36
257                       ,skip_initial_step = True): 
258    domain.write_time()
259   
260for t in domain.evolve(yieldstep = 1, finaltime = 45
261                       ,skip_initial_step = True): 
262    domain.write_time()
263
264print 'That took %.2f seconds' %(time.time()-t0)
265
266
267
268#define the segments to find the run-up height to compare to wave tank study
269angles = (0.0, 22.5, 45.0, 67.5, 75.0, 80.0, 85.0, 87.5, 90.0, 92.5,
270          95.0, 100.0, 105.0, 112.5, 135.0, 157.5, 180.0, 202.5, 225.0,
271          247.5, 270.0, 292.5, 315.0, 337.5)
272#x = 12.96
273#y = 13.80
274r1 = 1.1
275r2 = 3.6
276d=2
277
278poly_segment = []
279
280for i,angle in enumerate(angles):
281    angle = ((angle-180)/180.0)*pi
282#    angle = angle1*3.14157
283    p1 = get_xy(x,y,r1,angle-0.01745*d)
284    p2 = get_xy(x,y,r2,angle-0.01745*d)
285    p3 = get_xy(x,y,r2,angle+0.01745*d)
286    p4 = get_xy(x,y,r1,angle+0.01745*d)
287#    print p1,p2,p3,p4,angle
288    poly_segment =[[p1[0],p1[1]],[p2[0],p2[1]],[p3[0],p3[1]],[p4[0],p4[1]]]
289#    print i, poly_segment, angle
290    #print i,poly[i]
291   
292    run_up, x_y = get_maximum_inundation_data(filename='test.sww',polygon=poly_segment, verbose=False)
293   
294    print 'maximum_inundation_data',((angle/pi)*180)+180, run_up, x_y
295
296
297
298
299
300
301
Note: See TracBrowser for help on using the repository browser.