1 | import os |
---|
2 | from math import * |
---|
3 | import random |
---|
4 | import numpy as np |
---|
5 | import time |
---|
6 | import anuga |
---|
7 | import csv |
---|
8 | from Scientific.IO.NetCDF import NetCDFFile |
---|
9 | from anuga_1d.sww.sww_domain import * |
---|
10 | from anuga_1d.config import g, epsilon |
---|
11 | from anuga_1d.base.generic_mesh import uniform_mesh |
---|
12 | |
---|
13 | |
---|
14 | #=========================================================================== |
---|
15 | |
---|
16 | |
---|
17 | # Define functions for initial quantities |
---|
18 | ## initial area for 1D SWE |
---|
19 | def initial_area(x): |
---|
20 | return (stage(x)-sea_bed(x))*width(x) |
---|
21 | |
---|
22 | #-------------------------------------------- |
---|
23 | def width(x): |
---|
24 | return 1.0 |
---|
25 | #--------------------------------------------- |
---|
26 | # sea bed or bathymetry data |
---|
27 | |
---|
28 | def elevation(): |
---|
29 | x=[] |
---|
30 | elevation=[] |
---|
31 | |
---|
32 | f=open('gebco_1m.txt') |
---|
33 | lines=f.readlines() |
---|
34 | f.close |
---|
35 | for line in lines[2:]: |
---|
36 | val=[float(v) for v in line.split()] |
---|
37 | y=val[1] |
---|
38 | r=y-4152074.2 |
---|
39 | if abs(r)<810:# and val[0]<=max(x): |
---|
40 | #if np.allclose(y,4243929.72563): |
---|
41 | x.append(val[0]) |
---|
42 | elevation.append(val[2]) |
---|
43 | return x, elevation |
---|
44 | #----------------------------------------------------- |
---|
45 | # initial stage |
---|
46 | # Formula for solitary wave in 1D |
---|
47 | |
---|
48 | def stage(x): |
---|
49 | a=0.0*x |
---|
50 | #a=gaussian_filtered(x) |
---|
51 | y = 0.0*x |
---|
52 | wd=abs(-6000) # water depth |
---|
53 | wh=2.5 # wave height |
---|
54 | xm=908432.19999999995 |
---|
55 | k=10*sqrt(3.0*wh/(4.0*wd))/wd |
---|
56 | for i in range(len(x)): |
---|
57 | th=tanh(k*(x[i]-xm))**2 |
---|
58 | y[i]= wh*(1.0-th)#+a[i] |
---|
59 | return y |
---|
60 | # -------------------------------------------------------- |
---|
61 | |
---|
62 | |
---|
63 | # Initial momentum is zero |
---|
64 | |
---|
65 | def initial_momentum(x): |
---|
66 | return 1.0 |
---|
67 | |
---|
68 | |
---|
69 | # Length of channel (m) |
---|
70 | |
---|
71 | # Define cells for finite volume and their size |
---|
72 | # Define the number of cells |
---|
73 | x,elev=elevation() |
---|
74 | print x |
---|
75 | boundary = { (0,0) : 'left', (len(x)-2, 1) : 'right'} |
---|
76 | print boundary |
---|
77 | domain = Domain(x,boundary) |
---|
78 | print domain.boundary |
---|
79 | print type(x), len(x), type(elev),len(elev) |
---|
80 | |
---|
81 | |
---|
82 | # Set initial values of quantities - default to zero |
---|
83 | domain.set_quantity('elevation', elev, location='unique_vertices') |
---|
84 | #domain.add_quantity('stage',stage) |
---|
85 | domain.set_quantity('stage',stage) |
---|
86 | domain.set_quantity('xmomentum',initial_momentum) |
---|
87 | |
---|
88 | # Set boundry type, order, timestepping method and limiter |
---|
89 | print 'Available boundary tags: ', domain.get_boundary_tags() |
---|
90 | |
---|
91 | Bd = Dirichlet_boundary([0, 0, 0, 0, 0]) #(w,uh,z,h,u) |
---|
92 | Br = Reflective_boundary(domain) |
---|
93 | Bt = Transmissive_boundary(domain) |
---|
94 | domain.set_boundary({'left': Br , 'right' : Br}) |
---|
95 | #domain.set_boundary({'exterior': Br}) |
---|
96 | print 'Available boundary tags: ', domain.get_boundary_tags() |
---|
97 | domain.order = 2 |
---|
98 | domain.set_timestepping_method(1) |
---|
99 | domain.set_CFL(1.0) |
---|
100 | domain.set_limiter("vanleer") |
---|
101 | #domain.h0=0.0001 |
---|
102 | |
---|
103 | |
---|
104 | # Start timer |
---|
105 | t0 = time.time() |
---|
106 | |
---|
107 | # Set final time and yield time for simulation |
---|
108 | finaltime = 1.0 |
---|
109 | yieldstep = 1.0 |
---|
110 | |
---|
111 | #=================================================================== |
---|
112 | # Time loop |
---|
113 | #=================================================================== |
---|
114 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
115 | |
---|
116 | w = domain.quantities['stage'].vertex_values |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | domain.write_time() |
---|
121 | |
---|
122 | |
---|
123 | import pylab |
---|
124 | pylab.ion() |
---|
125 | |
---|
126 | x = domain.get_vertices().flatten() |
---|
127 | |
---|
128 | z = domain.quantities['elevation'].vertex_values.flatten() |
---|
129 | w = domain.quantities['stage'].vertex_values.flatten() |
---|
130 | h = domain.quantities['height'].vertex_values.flatten() |
---|
131 | u = domain.quantities['velocity'].vertex_values.flatten() |
---|
132 | uh = domain.quantities['xmomentum'].vertex_values.flatten() |
---|
133 | |
---|
134 | print x.shape |
---|
135 | print z.shape |
---|
136 | print w.shape |
---|
137 | print u.shape |
---|
138 | |
---|
139 | |
---|
140 | #print w |
---|
141 | #print z |
---|
142 | #print h |
---|
143 | #print u |
---|
144 | #print uh |
---|
145 | #print x |
---|
146 | |
---|
147 | #------------------------------- |
---|
148 | # Top plot |
---|
149 | #------------------------------- |
---|
150 | plot1 = pylab.subplot(211) |
---|
151 | |
---|
152 | zplot = pylab.plot(x, z, 'k') |
---|
153 | wplot = pylab.plot(x, w, 'k') |
---|
154 | |
---|
155 | #plot1.set_ylim(stage_lim) |
---|
156 | #pylab.xlabel('Position') |
---|
157 | pylab.ylabel('Bed/Stage') |
---|
158 | |
---|
159 | #------------------------------- |
---|
160 | # Bottom Plot |
---|
161 | #------------------------------- |
---|
162 | plot2 = pylab.subplot(212) |
---|
163 | |
---|
164 | uplot = pylab.plot(x, u, 'k') |
---|
165 | pylab.draw() |
---|
166 | |
---|
167 | #plot2.set_ylim(width_lim) |
---|
168 | #pylab.xlabel('Position') |
---|
169 | #pylab.ylabel('Velocity') |
---|
170 | |
---|
171 | |
---|
172 | #pylab.savefig('figure4.pdf') |
---|
173 | pylab.show() |
---|
174 | |
---|
175 | |
---|
176 | |
---|