1 | import os |
---|
2 | #from math import sqrt, pi |
---|
3 | from shallow_water_h import Domain, Reflective_boundary |
---|
4 | from Numeric import zeros, Float |
---|
5 | #from config import g, epsilon |
---|
6 | from analytic_dam import AnalyticDam |
---|
7 | |
---|
8 | |
---|
9 | h0 = 5.0 |
---|
10 | h1 = 10.0 |
---|
11 | |
---|
12 | analytical_sol = AnalyticDam(h0, h1) |
---|
13 | |
---|
14 | def newLinePlot(title='Simple Plot'): |
---|
15 | import Gnuplot |
---|
16 | g = Gnuplot.Gnuplot(persist=0) |
---|
17 | g.title(title) |
---|
18 | g('set data style linespoints') |
---|
19 | g.xlabel('x') |
---|
20 | g.ylabel('y') |
---|
21 | return g |
---|
22 | |
---|
23 | def linePlot(g,x1,y1,x2,y2): |
---|
24 | import Gnuplot |
---|
25 | plot1 = Gnuplot.PlotItems.Data(x1.flat,y1.flat,with="linespoints") |
---|
26 | plot2 = Gnuplot.PlotItems.Data(x2.flat,y2.flat,with="lines 3") |
---|
27 | g.plot(plot1,plot2) |
---|
28 | |
---|
29 | |
---|
30 | print "TEST 1D-SOLUTION I" |
---|
31 | |
---|
32 | L = 2000.0 # Length of channel (m) |
---|
33 | N = 100 # Number of computational cells |
---|
34 | cell_len = L/N # Origin = 0.0 |
---|
35 | |
---|
36 | points = zeros(N+1,Float) |
---|
37 | for i in range(N+1): |
---|
38 | points[i] = i*cell_len |
---|
39 | |
---|
40 | domain = Domain(points) |
---|
41 | |
---|
42 | def height(x): |
---|
43 | y = zeros(len(x),Float) |
---|
44 | for i in range(len(x)): |
---|
45 | if x[i]<=1000.0: |
---|
46 | y[i] = h1 |
---|
47 | else: |
---|
48 | y[i] = h0 |
---|
49 | return y |
---|
50 | |
---|
51 | |
---|
52 | domain.set_quantity('height', height) |
---|
53 | |
---|
54 | domain.default_order = 2 |
---|
55 | domain.order = 2 |
---|
56 | domain.default_time_order = 1 |
---|
57 | domain.cfl = 0.8 |
---|
58 | #domain.beta = 1.0 |
---|
59 | domain.split = False |
---|
60 | print "domain.order", domain.order |
---|
61 | domain.limiter = "minmod" |
---|
62 | |
---|
63 | |
---|
64 | domain.set_boundary({'exterior': Reflective_boundary(domain)}) |
---|
65 | |
---|
66 | X = domain.vertices |
---|
67 | C = domain.centroids |
---|
68 | plot1 = newLinePlot("Height") |
---|
69 | plot2 = newLinePlot("Momentum") |
---|
70 | |
---|
71 | import time |
---|
72 | t0 = time.time() |
---|
73 | yieldstep = 1.0 |
---|
74 | finaltime = 20.0 |
---|
75 | print "integral", domain.quantities['height'].get_integral() |
---|
76 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
77 | domain.write_time() |
---|
78 | print "integral", domain.quantities['height'].get_integral() |
---|
79 | if t > 0.0: |
---|
80 | HeightQ = domain.quantities['height'].vertex_values |
---|
81 | y , my = analytical_sol(X.flat,domain.time) |
---|
82 | linePlot(plot1,X,HeightQ,X,y) |
---|
83 | MomentumQ = domain.quantities['xmomentum'].vertex_values |
---|
84 | linePlot(plot2,X,MomentumQ,X,my) |
---|
85 | #raw_input('press_return') |
---|
86 | |
---|
87 | #pass |
---|
88 | |
---|
89 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
90 | |
---|
91 | #C = domain.quantities['height'].centroid_values |
---|
92 | |
---|