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