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