source: anuga_work/development/anuga_1d/anuga_1d_suggestion1_2_3/horizontal_dry_dam_h_1side.py @ 7576

Last change on this file since 7576 was 7576, checked in by sudi, 14 years ago
File size: 4.6 KB
Line 
1import os
2from math import sqrt, sin, cos, pi, exp
3from shallow_water_domain_h_nonwellbalanced import *
4from Numeric import zeros, Float
5
6def analytic_dry_dam(C,t):
7    #t  = 0.0     # time (s)
8    g  = 9.81     # gravity (m/s^2)
9    h1 = 10.0     # depth upstream (m)
10    h0 = 0.0      # depth downstream (m)
11    L = 2000.0    # length of stream/domain (m)
12    n = len(C)    # number of cells
13
14    u = zeros(n,Float)
15    h = zeros(n,Float)
16    z = zeros(n,Float)
17    x = C-L/2.0
18
19    for i in range(n):
20        # Calculate Analytical Solution at time t > 0
21        u3 = 2.0/3.0*(sqrt(g*h1)+x[i]/t) 
22        h3 = 4.0/(9.0*g)*(sqrt(g*h1)-x[i]/(2.0*t))*(sqrt(g*h1)-x[i]/(2.0*t)) 
23
24        if ( x[i] <= -t*sqrt(g*h1) ):
25            u[i] = 0.0 
26            h[i] = h1
27        elif ( x[i] <= 2.0*t*sqrt(g*h1) ):
28            u[i] = u3
29            h[i] = h3
30        else:
31            u[i] = 0.0 
32            h[i] = h0
33
34    return h+z , u*(h+z)
35
36
37def stage_dam(x):
38    h1 = 10.0
39    h0 = 0.0
40    y=zeros(len(x), Float)
41    for i in range(len(x)):
42        if x[i] <= 1000.0:
43            y[i] = h1
44        else:
45            y[i] = h0
46    return y
47
48
49
50'''
51def newLinePlot(title='Simple Plot'):
52    import Gnuplot
53    gg=Gnuplot.Gnuplot(persist=0)
54    gg.title(title)
55    gg('set data style linespoints')
56    gg.xlabel('x')
57    gg.ylabel('y')
58    return gg
59
60def linePlot(gg, x1, y1, x2, y2):
61    import Gnuplot
62    plot1=Gnuplot.PlotItems.Data(x1.flat, y1.flat, with="linespoints")
63    plot2=Gnuplot.PlotItems.Data(x2.flat, y2.flat, with="lines 3")
64    gg.plot(plot1, plot2)
65'''
66
67
68print "TEST 1D-SOLUTION I"
69
70L=2000.0
71N=400
72cell_len=L/N
73points=zeros(N+1, Float)
74for i in range(N+1):
75    points[i]=i*cell_len
76domain=Domain(points)
77domain.order = 2
78domain.set_timestepping_method('rk2')
79domain.cfl = 1.0
80domain.limiter = "vanleer"
81domain.set_quantity('stage',stage_dam)
82domain.set_boundary({'exterior':Reflective_boundary(domain)})
83
84X=domain.vertices
85C=domain.centroids
86
87#plot1x=newLinePlot("Stage")
88#plot2x=newLinePlot("Momentum")
89
90print 'THE DOMAIN ORDER is', domain.order
91print 'The Time Stepping Method is', domain.set_timestepping_method
92print 'THE DOMAIN LIMITER is', domain.limiter
93import time
94t0=time.time()
95yieldstep=20.0
96finaltime=20.0
97print "integral", domain.quantities['stage'].get_integral()
98for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime):
99    domain.write_time()
100    print "integral", domain.quantities['stage'].get_integral()
101    if t>0.0:
102        StageQ=domain.quantities['stage'].vertex_values
103        MomentumQ=domain.quantities['xmomentum'].vertex_values
104        ElevationQ=domain.quantities['elevation'].vertex_values
105       
106        #h, uh=analytical_sol(X.flat, domain.time)
107        #linePlot(plot1x, X, StageQ, X, ElevationQ)
108        #linePlot(plot2x, X, MomentumQ, X, MomentumQ)#, X, uh)   #(plot2x, X, MomentumQ, X, uh)
109        #print "press return"
110        #pass
111
112
113        #This is only for dry dam
114        N = float(N)
115        StageC = domain.quantities['stage'].centroid_values
116        XmomC = domain.quantities['xmomentum'].centroid_values
117        ElevationC = domain.quantities['elevation'].centroid_values
118        C = domain.centroids
119        h, uh = analytic_dry_dam(C,domain.time)
120        h_error = 1.0/(N)*sum(abs(h-StageC))
121        uh_error = 1.0/(N)*sum(abs(uh-XmomC))
122        print "h_error %.10f" %(h_error)
123        print "uh_error %.10f"% (uh_error)
124        print 'That took %.2f seconds' %(time.time()-t0)
125        X = domain.vertices
126        StageQ = domain.quantities['stage'].vertex_values
127        XmomQ = domain.quantities['xmomentum'].vertex_values
128        h, uh = analytic_dry_dam(X.flat,domain.time)
129        #End for dry dam
130   
131       
132        from pylab import clf,plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot,ion
133        #ion()
134        hold(False)
135        clf()
136
137        plot1 = subplot(211)
138        plot(X,StageQ, X,h, X,ElevationQ)   #(X,ElevationQ,X,StageQ, X,h)
139        plot1.set_ylim([-1.0,11.0]) #([9.999,10.006]) #([9.9999,10.0006]) #([-1.0,11.0])
140        xlabel('Position')
141        ylabel('Stage')
142        legend( ('Numerical Solution', 'Analytical Solution', 'Bed Elevation'), 'upper right', shadow=False)     
143
144        plot2 = subplot(212)
145        plot(X,MomentumQ, X,uh)
146        plot2.set_ylim([-5.0,30.0])
147        legend( ('Numerical Solution', 'for momentum'), 'upper right', shadow=False)   
148        xlabel('Position')
149        ylabel('Xmomentum')
150       
151        #file = "dam_h_"
152        #file += str(number_of_cells[i])
153        #file += ".eps"
154        #savefig(file)
155        show()
156       
157print 'That took %.2f seconds'%(time.time()-t0)
158raw_input("Press return key")
159
Note: See TracBrowser for help on using the repository browser.