1 | import os |
---|
2 | from math import sqrt, pow, pi |
---|
3 | |
---|
4 | from Numeric import allclose, array, zeros, ones, Float, take, sqrt |
---|
5 | |
---|
6 | from channel_domain import * |
---|
7 | from config import g, epsilon |
---|
8 | |
---|
9 | |
---|
10 | print "Channel Flow 1 Padarn Test" |
---|
11 | |
---|
12 | # Define functions for initial quantities |
---|
13 | def initial_area(x): |
---|
14 | return 1.4691*width(x) |
---|
15 | |
---|
16 | def width(x): |
---|
17 | x1=(x/1000)*(x/1000) |
---|
18 | x2=x1*(x/1000) |
---|
19 | x3=x2*(x/1000) |
---|
20 | return 10-64*(x1-2*x2+x3) |
---|
21 | |
---|
22 | def bed(x): |
---|
23 | y = zeros(len(x),Float) |
---|
24 | for i in range(len(x)): |
---|
25 | if x[i]<525 and x[i]>475: |
---|
26 | y[i]=1 |
---|
27 | else: |
---|
28 | y[i]=0 |
---|
29 | return y |
---|
30 | |
---|
31 | def initial_discharge(x): |
---|
32 | return 20 |
---|
33 | |
---|
34 | import time |
---|
35 | |
---|
36 | # Set final time and yield time for simulation |
---|
37 | finaltime = 10.0 |
---|
38 | yieldstep = finaltime |
---|
39 | |
---|
40 | # Length of channel (m) |
---|
41 | L = 1000.0 |
---|
42 | # Define the number of cells |
---|
43 | number_of_cells = [200] |
---|
44 | |
---|
45 | # Define cells for finite volume and their size |
---|
46 | N = int(number_of_cells[0]) |
---|
47 | print "Evaluating domain with %d cells" %N |
---|
48 | cell_len = L/N # Origin = 0.0 |
---|
49 | points = zeros(N+1,Float) |
---|
50 | |
---|
51 | # Define the centroid points |
---|
52 | for j in range(N+1): |
---|
53 | points[j] = j*cell_len |
---|
54 | |
---|
55 | # Create domain with centroid points as defined above |
---|
56 | domain = Domain(points) |
---|
57 | |
---|
58 | # Set initial values of quantities - default to zero |
---|
59 | domain.set_quantity('area', initial_area) |
---|
60 | domain.set_quantity('width',width) |
---|
61 | domain.set_quantity('elevation',bed) |
---|
62 | domain.set_quantity('discharge',initial_discharge) |
---|
63 | |
---|
64 | # Set boundry type, order, timestepping method and limiter |
---|
65 | domain.set_boundary({'exterior': Dirichlet_boundary([14,20,0,1.4,20/14,9])}) |
---|
66 | domain.order = 2 |
---|
67 | domain.set_timestepping_method('rk2') |
---|
68 | domain.set_CFL(1.0) |
---|
69 | domain.set_limiter("vanleer") |
---|
70 | #domain.h0=0.0001 |
---|
71 | |
---|
72 | # Start timer |
---|
73 | t0 = time.time() |
---|
74 | |
---|
75 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
76 | domain.write_time() |
---|
77 | |
---|
78 | N = float(N) |
---|
79 | HeightC = domain.quantities['height'].centroid_values |
---|
80 | DischargeC = domain.quantities['discharge'].centroid_values |
---|
81 | C = domain.centroids |
---|
82 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
83 | X = domain.vertices |
---|
84 | HeightQ = domain.quantities['height'].vertex_values |
---|
85 | VelocityQ = domain.quantities['velocity'].vertex_values |
---|
86 | x = X.flat |
---|
87 | z = domain.quantities['elevation'].vertex_values.flat |
---|
88 | stage=HeightQ.flat+z |
---|
89 | |
---|
90 | from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot |
---|
91 | |
---|
92 | hold(False) |
---|
93 | |
---|
94 | plot1 = subplot(211) |
---|
95 | |
---|
96 | plot(x,z,x,stage) |
---|
97 | |
---|
98 | plot1.set_ylim([-1,11]) |
---|
99 | xlabel('Position') |
---|
100 | ylabel('Stage') |
---|
101 | legend(('Analytical Solution', 'Numerical Solution'), |
---|
102 | 'upper right', shadow=True) |
---|
103 | plot2 = subplot(212) |
---|
104 | plot(x,VelocityQ.flat) |
---|
105 | plot2.set_ylim([-10,10]) |
---|
106 | |
---|
107 | xlabel('Position') |
---|
108 | ylabel('Velocity') |
---|
109 | |
---|
110 | show() |
---|
111 | |
---|