source: anuga_work/development/anuga_1d/run_profile_dry.py @ 6038

Last change on this file since 6038 was 5588, checked in by sudi, 16 years ago
File size: 3.0 KB
Line 
1import os
2from math import sqrt, pi
3from shallow_water_domain import *
4from Numeric import allclose, array, zeros, ones, Float, take, sqrt
5from config import g, epsilon
6
7def analytical_sol(C,t):
8   
9    #t  = 0.0     # time (s)
10    g  = 9.81    # gravity (m/s^2)
11    h1 = 10.0    # depth upstream (m)
12    h0 = 0.0     # depth downstream (m)
13    L = 2000.0   # length of stream/domain (m)
14    n = len(C)    # number of cells
15
16    u = zeros(n,Float)
17    h = zeros(n,Float)
18    x = C-3*L/4.0
19   
20
21    for i in range(n):
22        # Calculate Analytical Solution at time t > 0
23        u3 = 2.0/3.0*(sqrt(g*h1)+x[i]/t) 
24        h3 = 4.0/(9.0*g)*(sqrt(g*h1)-x[i]/(2.0*t))*(sqrt(g*h1)-x[i]/(2.0*t)) 
25
26        if ( x[i] <= -t*sqrt(g*h1) ):
27            u[i] = 0.0 
28            h[i] = h1
29        elif ( x[i] <= 2.0*t*sqrt(g*h1) ):
30            u[i] = u3
31            h[i] = h3
32        else:
33            u[i] = 0.0 
34            h[i] = h0
35
36    return h , u*h
37
38#def newLinePlot(title='Simple Plot'):
39#   import Gnuplot
40#    gg = Gnuplot.Gnuplot(persist=0)
41#    gg.terminal(postscript)
42#    gg.title(title)
43#    gg('set data style linespoints')
44#    gg.xlabel('x')
45#    gg.ylabel('y')
46#    return gg
47
48#def linePlot(gg,x1,y1,x2,y2):
49#    import Gnuplot
50#    plot1 = Gnuplot.PlotItems.Data(x1.flat,y1.flat,with="linespoints")
51#    plot2 = Gnuplot.PlotItems.Data(x2.flat,y2.flat, with="lines 3")
52#    g.plot(plot1,plot2)
53
54
55
56print "TEST 1D-SOLUTION III -- DRY BED"
57
58L = 2000.0     # Length of channel (m)
59N = 800        # Number of compuational cells
60cell_len = L/N # Origin = 0.0
61
62points = zeros(N+1,Float)
63for i in range(N+1):
64    points[i] = i*cell_len
65
66domain = Domain(points)
67
68def stage(x):
69    h1 = 10.0
70    h0 = 0.0
71    y = zeros(len(x),Float)
72    for i in range(len(x)):
73        if x[i]<=L/4.0:
74            y[i] = h0
75        elif x[i]<=3*L/4.0:
76            y[i] = h1
77        else:
78            y[i] = h0
79    return y
80
81
82import time
83
84finaltime = 20.0
85yieldstep = 1.0
86L = 2000.0     # Length of channel (m)
87k = 0
88
89print "Evaluating domain with %d cells" %N
90cell_len = L/N # Origin = 0.0
91points = zeros(N+1,Float)
92for j in range(N+1):
93    points[j] = j*cell_len
94       
95domain = Domain(points)
96   
97domain.set_quantity('stage', stage)
98domain.set_boundary({'exterior': Reflective_boundary(domain)})
99domain.default_order = 2
100domain.default_time_order = 1
101domain.cfl = 1.0
102domain.limiter = "vanleer"
103
104t0 = time.time()
105
106s = 'for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): domain.write_time()'
107
108import profile, pstats
109FN = 'profile.dat'
110
111profile.run(s, FN)
112
113    #print 'That took %.2f seconds' %(time.time()-t0)
114
115S = pstats.Stats(FN)
116s = S.sort_stats('cumulative').print_stats(30)
117
118print s   
119       
120N = float(N)
121StageC = domain.quantities['stage'].centroid_values
122XmomC = domain.quantities['xmomentum'].centroid_values
123C = domain.centroids
124h, uh = analytical_sol(C,domain.time)
125h_error = 1.0/(N)*sum(abs(h-StageC))
126uh_error = 1.0/(N)*sum(abs(uh-XmomC))
127print "h_error %.10f" %(h_error)
128print "uh_error %.10f"% (uh_error)
129
130print 'That took %.2f seconds' %(time.time()-t0)
131
Note: See TracBrowser for help on using the repository browser.