source: anuga_work/development/pyvolution-1d/dry_dam.py @ 6409

Last change on this file since 6409 was 3370, checked in by steve, 19 years ago

Playing with limiters

File size: 3.2 KB
Line 
1import os
2from math import sqrt, pi
3from shallow_water_1d 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-L/2
19    #x = zeros(n,Float)
20    #for i in range(n):
21    #    x[i] = C[i]-1000.0
22
23    for i in range(n):
24        # Calculate Analytical Solution at time t > 0
25        u3 = 2/3*(sqrt(g*h1)+x[i]/t) 
26        h3 = 4/(9*g)*(sqrt(g*h1)-x[i]/(2*t))*(sqrt(g*h1)-x[i]/(2*t)) 
27
28        if ( x[i] <= -t*sqrt(g*h1) ):
29            u[i] = 0.0 
30            h[i] = h1
31        elif ( x[i] <= 2*t*sqrt(g*h1) ):
32            u[i] = u3
33            h[i] = h3
34        else:
35            u[i] = 0.0 
36            h[i] = h0
37
38    return h , u*h
39
40def newLinePlot(title='Simple Plot'):
41    import Gnuplot
42    g = Gnuplot.Gnuplot(persist=1)
43    g.title(title)
44    g('set data style linespoints') 
45    g.xlabel('x')
46    g.ylabel('y')
47    return g
48
49def linePlot(g,x1,y1,x2,y2):
50    import Gnuplot
51    plot1 = Gnuplot.PlotItems.Data(x1.flat,y1.flat,with="linespoints")
52    plot2 = Gnuplot.PlotItems.Data(x2.flat,y2.flat, with="lines 3")
53    g.plot(plot1,plot2)
54
55debug = False
56
57print "TEST 1D-SOLUTION III -- DRY BED"
58
59L = 2000.0     # Length of channel (m)
60N = 400        # Number of compuational cells
61cell_len = L/N # Origin = 0.0
62
63points = zeros(N+1,Float)
64for i in range(N+1):
65    points[i] = i*cell_len
66
67domain = Domain(points)
68
69def stage(x):
70    y = zeros(len(x),Float)
71    for i in range(len(x)):
72        if x[i]<=1000.0:
73            y[i] = 10.0
74        else:
75            y[i] = 0.0
76    return y
77
78domain.set_quantity('stage', stage)
79
80domain.order = 2
81domain.default_order = 2
82print "domain.order", domain.order
83
84if (debug == True):
85    area = domain.areas
86    for i in range(len(area)):
87        if area != 20:
88            print "Cell Areas are Wrong"
89           
90    L = domain.quantities['stage'].vertex_values
91    print "Initial Stage"
92    print L
93
94domain.set_boundary({'exterior': Reflective_boundary(domain)})
95
96X = domain.vertices
97C = domain.centroids
98plot1 = newLinePlot("Stage")
99plot2 = newLinePlot("Momentum")
100
101import time
102t0 = time.time()
103yieldstep = 1.0
104finaltime = 30.0
105for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
106    domain.write_time()
107    if t > 0.0:
108        StageQ = domain.quantities['stage'].vertex_values
109        y,my = analytical_sol(X.flat,domain.time)
110        linePlot(plot1,X,StageQ,X,y)
111        MomentumQ = domain.quantities['xmomentum'].vertex_values
112        linePlot(plot2,X,MomentumQ,X,my)
113       
114    #raw_input('press_return')
115    #pass
116
117print 'That took %.2f seconds' %(time.time()-t0)
118
119C = domain.quantities['stage'].centroid_values
120
121if (debug == True):
122    L = domain.quantities['stage'].vertex_values
123    print "Final Stage Vertex Values"
124    print L
125    print "Final Stage Centroid Values"
126    print C
127
128#f = file('test_solution_I.out', 'w')
129#for i in range(N):
130#    f.write(str(C[i]))
131#    f.write("\n")
132#f.close
133
Note: See TracBrowser for help on using the repository browser.