1 | """Example of shallow water wave equation analytical solution |
---|
2 | consists of a parabolic profile in a parabolic basin. Analytical |
---|
3 | solutiuon to this problem was derived by Carrier and Greenspan |
---|
4 | and used by Yoon and Chou. |
---|
5 | |
---|
6 | Copyright 2005 |
---|
7 | Christopher Zoppou, Stephen Roberts, Ole Nielsen |
---|
8 | ANU, Geoscience Australia |
---|
9 | |
---|
10 | """ |
---|
11 | |
---|
12 | #--------------- |
---|
13 | # Module imports |
---|
14 | import sys |
---|
15 | from os import sep |
---|
16 | sys.path.append('..'+sep+'pyvolution') |
---|
17 | from shallow_water import Domain, Dirichlet_boundary |
---|
18 | from math import sqrt, cos, sin, pi |
---|
19 | from mesh_factory import strang_mesh |
---|
20 | from util import inside_polygon |
---|
21 | from Numeric import asarray |
---|
22 | from least_squares import Interpolation |
---|
23 | |
---|
24 | #------------------------------- |
---|
25 | # Set up the domain of triangles |
---|
26 | # Strang_domain will search |
---|
27 | # through the file and test to |
---|
28 | # see if there are two or three |
---|
29 | # entries. Two entries are for |
---|
30 | # points and three for triangles. |
---|
31 | points, elements = strang_mesh('yoon_circle.pt') |
---|
32 | domain = Domain(points, elements) |
---|
33 | |
---|
34 | #---------------- |
---|
35 | # Order of scheme |
---|
36 | domain.default_order = 2 |
---|
37 | |
---|
38 | domain.smooth = True |
---|
39 | |
---|
40 | #------------------------------------- |
---|
41 | # Provide file name for storing output |
---|
42 | domain.store = False |
---|
43 | domain.format = 'sww' |
---|
44 | domain.filename = 'yoon_mesh_second_order.2' |
---|
45 | print 'Number of triangles = ', len(domain) |
---|
46 | |
---|
47 | #---------------------------------------------------------- |
---|
48 | # Decide which quantities are to be stored at each timestep |
---|
49 | domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
50 | |
---|
51 | #------------------------------------------ |
---|
52 | # Reduction operation for get_vertex_values |
---|
53 | from util import mean |
---|
54 | domain.reduction = mean #domain.reduction = min #Looks better near steep slopes |
---|
55 | |
---|
56 | |
---|
57 | #------------------ |
---|
58 | # Initial condition |
---|
59 | print 'Initial condition' |
---|
60 | t = 0.0 |
---|
61 | D0 = 1. |
---|
62 | L = 2500. |
---|
63 | R0 = 2000. |
---|
64 | g = 9.81 |
---|
65 | |
---|
66 | A = (L**4 - R0**4)/(L**4 + R0**4) |
---|
67 | omega = 2./L*sqrt(2.*g*D0) |
---|
68 | T = pi/omega |
---|
69 | |
---|
70 | #------------------ |
---|
71 | # Set bed elevation |
---|
72 | def x_slope(x,y): |
---|
73 | n = x.shape[0] |
---|
74 | z = 0*x |
---|
75 | for i in range(n): |
---|
76 | r = sqrt(x[i]*x[i] + y[i]*y[i]) |
---|
77 | z[i] = -D0*(1.-r*r/L/L) |
---|
78 | return z |
---|
79 | domain.set_quantity('elevation', x_slope) |
---|
80 | |
---|
81 | #---------------------------- |
---|
82 | # Set the initial water level |
---|
83 | def level(x,y): |
---|
84 | z = x_slope(x,y) |
---|
85 | n = x.shape[0] |
---|
86 | h = 0*x |
---|
87 | for i in range(n): |
---|
88 | r = sqrt(x[i]*x[i] + y[i]*y[i]) |
---|
89 | h[i] = D0*((sqrt(1-A*A))/(1.-A*cos(omega*t)) |
---|
90 | -1.-r*r/L/L*((1.-A*A)/((1.-A*cos(omega*t))**2)-1.)) |
---|
91 | if h[i] < z[i]: |
---|
92 | h[i] = z[i] |
---|
93 | return h |
---|
94 | domain.set_quantity('stage', level) |
---|
95 | |
---|
96 | |
---|
97 | #--------- |
---|
98 | # Boundary |
---|
99 | print 'Boundary conditions' |
---|
100 | domain.set_boundary({'exterior': Dirichlet_boundary([0.0, 0.0, 0.0])}) |
---|
101 | |
---|
102 | #--------------------------------------------- |
---|
103 | # Find triangle that contains the point points |
---|
104 | # and print to file |
---|
105 | points = [0.,0.] |
---|
106 | for n in range(len(domain.triangles)): |
---|
107 | t = domain.triangles[n] |
---|
108 | tri = [domain.coordinates[t[0]],domain.coordinates[t[1]],domain.coordinates[t[2]]] |
---|
109 | |
---|
110 | if inside_polygon(points,tri): |
---|
111 | print 'Point is within triangle with vertices '+'%s'%tri |
---|
112 | n_point = n |
---|
113 | t = domain.triangles[n_point] |
---|
114 | tri = [domain.coordinates[t[0]],domain.coordinates[t[1]],domain.coordinates[t[2]]] |
---|
115 | |
---|
116 | filename=domain.filename |
---|
117 | file = open(filename,'w') |
---|
118 | |
---|
119 | #---------- |
---|
120 | # Evolution |
---|
121 | import time |
---|
122 | t0 = time.time() |
---|
123 | for t in domain.evolve(yieldstep = 20.0, finaltime = 3000 ): |
---|
124 | domain.write_time() |
---|
125 | |
---|
126 | tri_array = asarray(tri) |
---|
127 | t_array = asarray([[0,1,2]]) |
---|
128 | interp = Interpolation(tri_array,t_array,[points]) |
---|
129 | |
---|
130 | stage = domain.get_quantity('stage').get_values()[n_point] |
---|
131 | xmomentum = domain.get_quantity('xmomentum').get_values()[n_point] |
---|
132 | ymomentum = domain.get_quantity('ymomentum').get_values()[n_point] |
---|
133 | |
---|
134 | interp_stage = interp.interpolate([[stage[0]],[stage[1]],[stage[2]]]) |
---|
135 | interp_xmomentum = interp.interpolate([[xmomentum[0]],[xmomentum[1]],[xmomentum[2]]]) |
---|
136 | interp_ymomentum = interp.interpolate([[ymomentum[0]],[ymomentum[1]],[ymomentum[2]]]) |
---|
137 | |
---|
138 | file.write( '%10.6f %10.6f %10.6f %10.6f\n'%(t,interp_stage[0][0],interp_xmomentum[0][0],interp_ymomentum[0][0]) ) |
---|
139 | |
---|
140 | file.close() |
---|
141 | print 'That took %.2f seconds' %(time.time()-t0) |
---|