1 | import os |
---|
2 | from math import sqrt |
---|
3 | from sww_domain_shm import * |
---|
4 | from Numeric import Float |
---|
5 | from numpy import zeros |
---|
6 | #from analytic_dam_sudi import AnalyticDam |
---|
7 | #Note:apply analytical_sol given in debris avalanche solution |
---|
8 | from parameters import * |
---|
9 | |
---|
10 | N = int(N) # number of cells |
---|
11 | print "number of cells=",N |
---|
12 | #analytical_sol=AnalyticDam(h_0,h_1) |
---|
13 | boundary = {(0,0):'left', (N-1,1): 'right'} |
---|
14 | domain = Domain(points,boundary) |
---|
15 | domain.order = 2 |
---|
16 | domain.set_timestepping_method('rk2') |
---|
17 | domain.cfl = 1.0 |
---|
18 | domain.limiter = "minmod" |
---|
19 | |
---|
20 | def stage(x): |
---|
21 | y=zeros(len(x), Float) |
---|
22 | for i in range (len(x)): |
---|
23 | if x[i]<=L/4.0: |
---|
24 | y[i]=bed_slope*x[i]#0.0 |
---|
25 | elif x[i]<=3*L/4.0: |
---|
26 | y[i]=h_1 |
---|
27 | else: |
---|
28 | y[i]=h_0 |
---|
29 | return y |
---|
30 | domain.set_quantity('stage',stage) |
---|
31 | |
---|
32 | def elevation(x): |
---|
33 | y=zeros(len(x), Float) |
---|
34 | for i in range (len(x)): |
---|
35 | y[i] = bed_slope*x[i] |
---|
36 | return y |
---|
37 | domain.set_quantity('elevation',elevation) |
---|
38 | |
---|
39 | ### ================ Define the boundary function ========================= |
---|
40 | #def f_right(t): |
---|
41 | # z_r = bed_slope*(0.5*L) |
---|
42 | # h_r = h_0 #+ bed_slope*cell_len |
---|
43 | # w_r = z_r + h_r |
---|
44 | # u_r = m*t |
---|
45 | # #['stage', 'xmomentum', 'elevation', 'height', 'velocity'] |
---|
46 | # return [w_r, u_r*h_r, z_r, h_r, u_r] |
---|
47 | |
---|
48 | #T_right = Time_boundary(domain,f_right) |
---|
49 | #D_right = Dirichlet_boundary([bed_slope*(0.5*L)+h_0,(m*domain.time)*h_0,bed_slope*(0.5*L),h_0,m*domain.time]) |
---|
50 | #D_left = Dirichlet_boundary([-1.0*bed_slope*(0.5*L), 0.0, -1.0*bed_slope*(0.5*L), 0.0, 0.0]) |
---|
51 | D_right = Dirichlet_boundary([h_0, 0.0, 0.0, h_0, 0.0]) |
---|
52 | D_left = Dirichlet_boundary([0.0, 0.0, 0.0, 0.0, 0.0]) |
---|
53 | domain.set_boundary({'left':D_left,'right':D_right}) |
---|
54 | ### ================ End of the definition of boundary function =========== |
---|
55 | |
---|
56 | X=domain.vertices |
---|
57 | C=domain.centroids |
---|
58 | import time |
---|
59 | yieldstep=finaltime=1.0 |
---|
60 | t0=time.time() |
---|
61 | i=1 |
---|
62 | |
---|
63 | while finaltime < 1.01: |
---|
64 | for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): |
---|
65 | domain.write_time() |
---|
66 | finaltime = finaltime + 10.0 |
---|
67 | if t>0.0: |
---|
68 | N = float(N) |
---|
69 | StageC = domain.quantities['stage'].centroid_values |
---|
70 | XmomC = domain.quantities['xmomentum'].centroid_values |
---|
71 | VelC = domain.quantities['velocity'].centroid_values |
---|
72 | #hC, uhC, uC = analytical_sol(C,domain.time) |
---|
73 | #h_error = sum(abs(hC-StageC))/N |
---|
74 | #uh_error = sum(abs(uhC-XmomC))/N |
---|
75 | #u_error = sum(abs(uC-VelC))/N |
---|
76 | #print "h_error %.10f" %(h_error) |
---|
77 | #print "uh_error %.10f"%(uh_error) |
---|
78 | #print "u_error %.10f" %(u_error) |
---|
79 | #print 'That took %.2f seconds' %(time.time()-t0) |
---|
80 | X = domain.vertices.flat |
---|
81 | StageQ = domain.quantities['stage'].vertex_values.flat |
---|
82 | XmomQ = domain.quantities['xmomentum'].vertex_values.flat |
---|
83 | VelQ = domain.quantities['velocity'].vertex_values.flat |
---|
84 | BedQ = domain.quantities['elevation'].vertex_values.flat |
---|
85 | #h, uh, u = analytical_sol(X.flat, domain.time) |
---|
86 | |
---|
87 | SD = domain.shock_detector |
---|
88 | |
---|
89 | from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot |
---|
90 | hold(False) |
---|
91 | plot1 = subplot(211) |
---|
92 | #plot(X,h, X,StageQ, X,BedQ) #plot(X,h,'k-',X,StageQ,'k--') |
---|
93 | plot(X,StageQ, X,BedQ) |
---|
94 | plot1.set_ylim([-1,11]) |
---|
95 | plot1.set_xlim([0.0,2000.0]) |
---|
96 | legend(('Numerical solution', 'Bed elevation'), |
---|
97 | 'upper left', shadow=False) |
---|
98 | #xlabel('Position') |
---|
99 | ylabel('Stage') |
---|
100 | |
---|
101 | |
---|
102 | plot2 = subplot(212) |
---|
103 | plot(points,SD) |
---|
104 | plot2.set_xlim([0.0,2000.0]) |
---|
105 | xlabel('Position') |
---|
106 | ylabel('Smoothness indicator') |
---|
107 | |
---|
108 | show() |
---|
109 | |
---|
110 | #filename = "%s%04i%s" %("dam_", i, ".eps") |
---|
111 | #savefig(filename) |
---|
112 | #finaltime = finaltime + 0.25 |
---|
113 | #print "finaltime=", finaltime |
---|
114 | #i = i + 1 |
---|
115 | #print "The domain.limiter is", domain.limiter |
---|
116 | #print 'That took %.2f seconds'%(time.time()-t0) |
---|
117 | #print '=============================================================================' |
---|