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 "Radial Dam Break Test" |
---|
9 | |
---|
10 | # Define functions for initial quantities |
---|
11 | |
---|
12 | def initial_area(x): |
---|
13 | y=zeros(len(x),Float) |
---|
14 | for i in range (len(x)): |
---|
15 | if x[i]<=40: |
---|
16 | y[i]=10*(x[i]*pi*2) |
---|
17 | else: |
---|
18 | y[i]=1*(x[i]*pi*2) |
---|
19 | return y |
---|
20 | |
---|
21 | |
---|
22 | def width(x): |
---|
23 | return 2*pi*x |
---|
24 | |
---|
25 | import time |
---|
26 | |
---|
27 | # Set final time and yield time for simulation |
---|
28 | finaltime = 2.0 |
---|
29 | yieldstep = finaltime |
---|
30 | |
---|
31 | # Length of channel (m) |
---|
32 | L = 100.0 |
---|
33 | # Define the number of cells |
---|
34 | number_of_cells = [200] |
---|
35 | |
---|
36 | # Define cells for finite volume and their size |
---|
37 | N = int(number_of_cells[0]) |
---|
38 | print "Evaluating domain with %d cells" %N |
---|
39 | cell_len = L/N # Origin = 0.0 |
---|
40 | points = zeros(N+1,Float) |
---|
41 | |
---|
42 | # Define the centroid points |
---|
43 | for j in range(N+1): |
---|
44 | points[j] = j*cell_len |
---|
45 | |
---|
46 | # Create domain with centroid points as defined above |
---|
47 | domain = Domain(points) |
---|
48 | |
---|
49 | # Set initial values of quantities - default to zero |
---|
50 | domain.set_quantity('area', initial_area) |
---|
51 | domain.set_quantity('width',width) |
---|
52 | |
---|
53 | |
---|
54 | # Set boundry type, order, timestepping method and limiter |
---|
55 | domain.set_boundary({'exterior':Reflective_boundary(domain)}) |
---|
56 | domain.order = 2 |
---|
57 | domain.set_timestepping_method('rk2') |
---|
58 | domain.set_CFL(1.0) |
---|
59 | domain.set_limiter("vanleer") |
---|
60 | #domain.h0=0.0001 |
---|
61 | |
---|
62 | # Start timer |
---|
63 | t0 = time.time() |
---|
64 | |
---|
65 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
66 | domain.write_time() |
---|
67 | |
---|
68 | N = float(N) |
---|
69 | HeightC = domain.quantities['height'].centroid_values |
---|
70 | DischargeC = domain.quantities['discharge'].centroid_values |
---|
71 | C = domain.centroids |
---|
72 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
73 | X = domain.vertices |
---|
74 | HeightQ = domain.quantities['height'].vertex_values |
---|
75 | VelocityQ = domain.quantities['velocity'].vertex_values |
---|
76 | x = X.flat |
---|
77 | z = domain.quantities['elevation'].vertex_values.flat |
---|
78 | stage=HeightQ.flat+z |
---|
79 | |
---|
80 | ################# REPEAT ABOVE WITH MORE CELLS |
---|
81 | # Set final time and yield time for simulation |
---|
82 | finaltime2 = 2.0 |
---|
83 | yieldstep2 = finaltime2 |
---|
84 | |
---|
85 | # Length of channel (m) |
---|
86 | L2 = 100.0 |
---|
87 | # Define the number of cells |
---|
88 | number_of_cells2 = [2000] |
---|
89 | |
---|
90 | # Define cells for finite volume and their size |
---|
91 | N2 = int(number_of_cells2[0]) |
---|
92 | print "Evaluating domain with %d cells" %N2 |
---|
93 | cell_len2 = L2/N2 # Origin = 0.0 |
---|
94 | points2 = zeros(N2+1,Float) |
---|
95 | |
---|
96 | # Define the centroid points |
---|
97 | for j in range(N2+1): |
---|
98 | points2[j] = j*cell_len2 |
---|
99 | |
---|
100 | # Create domain with centroid points as defined above |
---|
101 | domain2 = Domain(points2) |
---|
102 | |
---|
103 | # Set initial values of quantities - default to zero |
---|
104 | domain2.set_quantity('area', initial_area) |
---|
105 | domain2.set_quantity('width',width) |
---|
106 | |
---|
107 | |
---|
108 | # Set boundry type, order, timestepping method and limiter |
---|
109 | domain2.set_boundary({'exterior':Reflective_boundary(domain2)}) |
---|
110 | domain2.order = 2 |
---|
111 | domain2.set_timestepping_method('rk2') |
---|
112 | domain2.set_CFL(1.0) |
---|
113 | domain2.set_limiter("vanleer") |
---|
114 | #domain.h0=0.0001 |
---|
115 | |
---|
116 | # Start timer |
---|
117 | t02 = time.time() |
---|
118 | |
---|
119 | for t in domain2.evolve(yieldstep = yieldstep2, finaltime = finaltime2): |
---|
120 | domain2.write_time() |
---|
121 | |
---|
122 | N2 = float(N2) |
---|
123 | HeightC2 = domain2.quantities['height'].centroid_values |
---|
124 | DischargeC2 = domain2.quantities['discharge'].centroid_values |
---|
125 | C2 = domain2.centroids |
---|
126 | print 'That took %.2f seconds' %(time.time()-t02) |
---|
127 | X2 = domain2.vertices |
---|
128 | HeightQ2 = domain2.quantities['height'].vertex_values |
---|
129 | VelocityQ2 = domain2.quantities['velocity'].vertex_values |
---|
130 | x2 = X2.flat |
---|
131 | z2 = domain2.quantities['elevation'].vertex_values.flat |
---|
132 | stage2=HeightQ2.flat+z2 |
---|
133 | |
---|
134 | ################# REPEAT ABOVE |
---|
135 | |
---|
136 | from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot |
---|
137 | |
---|
138 | hold(False) |
---|
139 | plot1 = subplot(211) |
---|
140 | |
---|
141 | plot(x,stage,'ro',x2,stage2) |
---|
142 | |
---|
143 | plot1.set_ylim([-1,11]) |
---|
144 | xlabel('Position') |
---|
145 | ylabel('Stage') |
---|
146 | legend(('Analytical Solution', 'Numerical Solution'), |
---|
147 | 'upper right', shadow=True) |
---|
148 | plot2 = subplot(212) |
---|
149 | plot(x,VelocityQ.flat) |
---|
150 | plot2.set_ylim([-10,10]) |
---|
151 | |
---|
152 | xlabel('Position') |
---|
153 | ylabel('Velocity') |
---|
154 | |
---|
155 | show() |
---|
156 | |
---|
157 | |
---|
158 | |
---|