1 | import os |
---|
2 | import random |
---|
3 | from math import sqrt, pow, pi ,sin, cos |
---|
4 | import numpy |
---|
5 | |
---|
6 | from anuga_1d.pipe.pipe_domain import * |
---|
7 | |
---|
8 | from anuga_1d.config import g, epsilon |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | print "Pipe Variable Width Only Test" |
---|
13 | |
---|
14 | # Define functions for initial quantities |
---|
15 | def initial_stage(x): |
---|
16 | z_infty = 10.0 ## max equilibrium water depth at lowest point. |
---|
17 | L_x = 2500.0 ## width of channel |
---|
18 | A0 = 0.5*L_x ## determines amplitudes of oscillations |
---|
19 | omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation |
---|
20 | t=0.0 |
---|
21 | y = numpy.zeros(len(x),numpy.float) |
---|
22 | for i in range(len(x)): |
---|
23 | #y[i] = z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t)) |
---|
24 | y[i] = 12.0 |
---|
25 | return y |
---|
26 | |
---|
27 | def bed(x): |
---|
28 | N = len(x) |
---|
29 | z_infty = 10.0 |
---|
30 | z = numpy.zeros(N,numpy.float) |
---|
31 | L_x = 2500.0 |
---|
32 | A0 = 0.5*L_x |
---|
33 | omega = sqrt(2*g*z_infty)/L_x |
---|
34 | for i in range(N): |
---|
35 | z[i] = z_infty*(x[i]**2/L_x**2) |
---|
36 | return z |
---|
37 | |
---|
38 | def initial_area(x): |
---|
39 | y = numpy.zeros(len(x),numpy.float) |
---|
40 | for i in range(len(x)): |
---|
41 | y[i]=initial_stage([x[i]])-bed([x[i]]) |
---|
42 | |
---|
43 | return y |
---|
44 | |
---|
45 | def width(x): |
---|
46 | return 1 |
---|
47 | |
---|
48 | def top(x): |
---|
49 | return 4 |
---|
50 | |
---|
51 | import time |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | # Set final time and yield time for simulation |
---|
56 | finaltime = 10.0 |
---|
57 | yieldstep = 1.0 |
---|
58 | |
---|
59 | # Length of channel (m) |
---|
60 | L = 2500.0 |
---|
61 | # Define the number of cells |
---|
62 | number_of_cells = [50] |
---|
63 | |
---|
64 | # Define cells for finite volume and their size |
---|
65 | N = int(number_of_cells[0]) |
---|
66 | print "Evaluating domain with %d cells" %N |
---|
67 | cell_len = 4*L/N # Origin = 0.0 |
---|
68 | points = numpy.zeros(N+1,numpy.float) |
---|
69 | for i in range(N+1): |
---|
70 | points[i] = -2*L +i*cell_len |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | # Create domain with centroid points as defined above |
---|
75 | domain = Domain(points) |
---|
76 | |
---|
77 | |
---|
78 | # Set initial values of quantities - default to zero |
---|
79 | domain.set_quantity('area', initial_area) |
---|
80 | domain.set_quantity('elevation',bed) |
---|
81 | domain.set_quantity('width',width) |
---|
82 | domain.set_quantity('top',top) |
---|
83 | |
---|
84 | # Set boundry type, order, timestepping method and limiter |
---|
85 | domain.set_boundary({'exterior':Reflective_boundary(domain)}) |
---|
86 | domain.order = 2 |
---|
87 | domain.set_timestepping_method('euler') |
---|
88 | domain.set_CFL(1.0) |
---|
89 | domain.set_limiter("vanleer") |
---|
90 | #domain.h0=0.0001 |
---|
91 | |
---|
92 | # Start timer |
---|
93 | t0 = time.time() |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
100 | domain.write_time() |
---|
101 | |
---|
102 | N = float(N) |
---|
103 | HeightC = domain.quantities['height'].centroid_values |
---|
104 | DischargeC = domain.quantities['discharge'].centroid_values |
---|
105 | C = domain.centroids |
---|
106 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
107 | X = domain.vertices |
---|
108 | HeightQ = domain.quantities['area'].vertex_values |
---|
109 | VelocityQ = domain.quantities['velocity'].vertex_values |
---|
110 | Z = domain.quantities['elevation'].vertex_values |
---|
111 | PipeH = domain.quantities['top'].vertex_values |
---|
112 | Top = Z + PipeH |
---|
113 | Stage = HeightQ + Z |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot |
---|
118 | |
---|
119 | hold(False) |
---|
120 | |
---|
121 | plot1 = subplot(211) |
---|
122 | plot(X.flat,Z.flat, X.flat,Stage.flat, X.flat,Top.flat) |
---|
123 | |
---|
124 | plot1.set_ylim([-1,35]) |
---|
125 | xlabel('Position') |
---|
126 | ylabel('Stage') |
---|
127 | legend(('Bed', 'Stage', 'Top'), 'upper right', shadow=True) |
---|
128 | plot2 = subplot(212) |
---|
129 | plot(X.flat,VelocityQ.flat) |
---|
130 | plot2.set_ylim([-10,10]) |
---|
131 | |
---|
132 | xlabel('Position') |
---|
133 | ylabel('Velocity') |
---|
134 | |
---|
135 | show() |
---|