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

Last change on this file since 7576 was 7576, checked in by sudi, 14 years ago
File size: 3.7 KB
Line 
1import os
2from math import sqrt
3from shallow_water_domain_h_wellbalanced import *
4from Numeric import zeros, Float
5from scipy import linspace
6#from analytic_dam_sudi import AnalyticDam
7
8h0=5.0
9h1=10.0
10
11#analytical_sol=AnalyticDam(h0,h1)
12
13
14print "TEST 1D-SOLUTION I"
15
16L=2000.0
17N=16000
18
19cell_len=L/N
20
21points=zeros(N+1, Float)
22for i in range(N+1):
23    points[i]=i*cell_len
24
25domain=Domain(points)
26
27domain.order = 2
28domain.set_timestepping_method('rk2')
29domain.cfl = 1.0
30domain.limiter = "minmod"
31
32
33
34def stage(x):
35    y=zeros(len(x), Float)
36    for i in range (len(x)):
37        if x[i]<=L/4.0:
38            y[i]=0.0 #h0
39        elif x[i]<=3*L/4.0:
40            y[i]=h1
41        else:
42            y[i]=h0
43    return y
44
45def elevation(x):
46    y=zeros(len(x), Float)
47    for i in range (len(x)):
48        if x[i]<=500:
49            y[i]=4*x[i]*x[i]/250000
50        elif x[i]<=1500:
51            y[i]=(500-x[i])/1000 + 4
52        else:
53            y[i]=-3*(x[i]-1000)*(x[i]-2000)/250000
54    return y
55
56
57P=linspace(0,2000,2000)
58Elev_bed=elevation(P)
59
60domain.set_quantity('stage',stage)
61domain.set_quantity('elevation', elevation)
62print "domain order", domain.order
63
64domain.set_boundary({'exterior':Reflective_boundary(domain)})
65
66X=domain.vertices
67C=domain.centroids
68#plot1x=newLinePlot("Height")
69#plot2x=newLinePlot("Momentum")
70
71import time
72yieldstep=finaltime=0.0001
73t0=time.time()
74
75i=1
76while finaltime < 0.00011:
77    for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime):
78        domain.write_time()
79    #if t>0.0:
80        #N = float(N)
81        #StageC = domain.quantities['stage'].centroid_values
82        #XmomC = domain.quantities['xmomentum'].centroid_values
83        #VelC = domain.quantities['velocity'].centroid_values
84        #C = domain.centroids
85        #hC, uhC, uC = analytical_sol(C,domain.time)
86
87
88        #h_error = sum(abs(hC-StageC))/N
89        #uh_error = sum(abs(uhC-XmomC))/N
90        #u_error = sum(abs(uC-VelC))/N
91        #print "h_error %.10f" %(h_error)
92        #print "uh_error %.10f"%(uh_error)
93        #print "u_error %.10f" %(u_error)
94        #print 'That took %.2f seconds' %(time.time()-t0)
95        X = domain.vertices
96        StageQ = domain.quantities['stage'].vertex_values
97        XmomQ = domain.quantities['xmomentum'].vertex_values
98        VelQ = domain.quantities['velocity'].vertex_values
99
100        #h, uh, u = analytical_sol(X.flat, domain.time)
101        #linePlot(plot1x, X, HeightQ, X, h)
102        #linePlot(plot2x, X, MomentumQ, X, uh)
103        #print "press return"
104        #pass
105   
106        from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot
107        hold(False)
108           
109        plot1 = subplot(311)
110        plot(X,StageQ, P,Elev_bed) #plot(X,StageQ,'k-', P,Elev_bed,'k:')
111        plot1.set_ylim([-1,11])
112        plot1.set_xlim([0.0,2000.0])
113        #xlabel('Position')
114        ylabel('Stage')
115        #legend(('Analytical Solution', 'Numerical Solution'),
116        #   'lower right', shadow=False)
117       
118        plot2 = subplot(312)
119        plot(X,XmomQ) #plot(X,XmomQ,'k-')
120        #plot2.set_ylim([-5,35])
121        plot2.set_xlim([0.0,2000.0])
122        #legend(('Analytical Solution', 'Numerical Solution'),
123        #        'lower right', shadow=False)
124        #xlabel('Position')
125        ylabel('Momentum')
126        plot3 = subplot(313)
127        plot(X,VelQ) #plot(X,VelQ,'k-')
128        #plot2.set_ylim([-5,35])
129        plot3.set_xlim([0.0,2000.0])
130        legend(('Penyelesaian Numeris', ' '),
131            'lower right', shadow=False)
132        xlabel('Posisi')
133        ylabel('Kecepatan')
134
135        #file = "dam"
136        #file += str(finaltime)
137        #file += ".png"
138        #savefig(file)
139        #show()
140       
141        filename = "%s%02i%s" %("dam_init2_", i, ".eps")
142        savefig(filename)
143        finaltime = finaltime + 0.25
144        i = i + 1
Note: See TracBrowser for help on using the repository browser.