1 | |
---|
2 | import os |
---|
3 | from math import sqrt, pi |
---|
4 | from shallow_water_1d import * |
---|
5 | from Numeric import allclose, array, zeros, ones, Float, take, sqrt |
---|
6 | from config import g, epsilon |
---|
7 | from analytic_dam import AnalyticDam |
---|
8 | |
---|
9 | |
---|
10 | h0 = 5.0 |
---|
11 | h1 = 10.0 |
---|
12 | |
---|
13 | analytical_sol = AnalyticDam(h0, h1) |
---|
14 | |
---|
15 | def newLinePlot(title='Simple Plot'): |
---|
16 | import Gnuplot |
---|
17 | g = Gnuplot.Gnuplot(persist=1) |
---|
18 | g.title(title) |
---|
19 | g('set data style linespoints') |
---|
20 | g.xlabel('x') |
---|
21 | g.ylabel('y') |
---|
22 | return g |
---|
23 | |
---|
24 | def linePlot(g,x1,y1,x2,y2): |
---|
25 | import Gnuplot |
---|
26 | plot1 = Gnuplot.PlotItems.Data(x1.flat,y1.flat,with="linespoints") |
---|
27 | plot2 = Gnuplot.PlotItems.Data(x2.flat,y2.flat, with="lines 3") |
---|
28 | g.plot(plot1,plot2) |
---|
29 | #g.plot(Gnuplot.PlotItems.Data(x1.flat,y1.flat),with="linespoints") |
---|
30 | #g.plot(Gnuplot.PlotItems.Data(x2.flat,y2.flat), with="lines") |
---|
31 | |
---|
32 | debug = False |
---|
33 | |
---|
34 | print "TEST 1D-SOLUTION I" |
---|
35 | |
---|
36 | L = 2000.0 # Length of channel (m) |
---|
37 | N = 100 # Number of compuational cells |
---|
38 | cell_len = L/N # Origin = 0.0 |
---|
39 | |
---|
40 | points = zeros(N+1,Float) |
---|
41 | for i in range(N+1): |
---|
42 | points[i] = i*cell_len |
---|
43 | |
---|
44 | domain = Domain(points) |
---|
45 | |
---|
46 | def stage(x): |
---|
47 | y = zeros(len(x),Float) |
---|
48 | for i in range(len(x)): |
---|
49 | if x[i]<=1000.0: |
---|
50 | y[i] = h1 |
---|
51 | else: |
---|
52 | y[i] = h0 |
---|
53 | return y |
---|
54 | |
---|
55 | domain.set_quantity('stage', stage) |
---|
56 | |
---|
57 | domain.order = 2 |
---|
58 | domain.default_order = 2 |
---|
59 | domain.cfl = 0.8 |
---|
60 | #domain.beta = 0.0 |
---|
61 | print "domain.order", domain.order |
---|
62 | |
---|
63 | if (debug == True): |
---|
64 | area = domain.areas |
---|
65 | for i in range(len(area)): |
---|
66 | if area != 20: |
---|
67 | print "Cell Areas are Wrong" |
---|
68 | |
---|
69 | L = domain.quantities['stage'].vertex_values |
---|
70 | print "Initial Stage" |
---|
71 | print L |
---|
72 | |
---|
73 | domain.set_boundary({'exterior': Reflective_boundary(domain)}) |
---|
74 | |
---|
75 | X = domain.vertices |
---|
76 | C = domain.centroids |
---|
77 | plot1 = newLinePlot("Stage") |
---|
78 | plot2 = newLinePlot("Momentum") |
---|
79 | |
---|
80 | import time |
---|
81 | t0 = time.time() |
---|
82 | yieldstep = 1.0 |
---|
83 | finaltime = 50.0 |
---|
84 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
85 | domain.write_time() |
---|
86 | if t > 0.0: |
---|
87 | StageQ = domain.quantities['stage'].vertex_values |
---|
88 | y , my = analytical_sol(X.flat,domain.time) |
---|
89 | linePlot(plot1,X,StageQ,X,y) |
---|
90 | MomentumQ = domain.quantities['xmomentum'].vertex_values |
---|
91 | linePlot(plot2,X,MomentumQ,X,my) |
---|
92 | #raw_input('press_return') |
---|
93 | #pass |
---|
94 | |
---|
95 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
96 | |
---|
97 | C = domain.quantities['stage'].centroid_values |
---|
98 | |
---|
99 | if (debug == True): |
---|
100 | L = domain.quantities['stage'].vertex_values |
---|
101 | print "Final Stage Vertex Values" |
---|
102 | print L |
---|
103 | print "Final Stage Centroid Values" |
---|
104 | print C |
---|
105 | |
---|
106 | #f = file('test_solution_I.out', 'w') |
---|
107 | #for i in range(N): |
---|
108 | # f.write(str(C[i])) |
---|
109 | # f.write("\n") |
---|
110 | #f.close |
---|
111 | |
---|