source: trunk/anuga_work/development/2010-projects/anuga_1d/pipe/test_pipe.py @ 8183

Last change on this file since 8183 was 8183, checked in by paul, 14 years ago

Add top label to test plot

File size: 3.1 KB
Line 
1import os
2import random
3from math import sqrt, pow, pi ,sin, cos
4import numpy
5
6from anuga_1d.pipe.pipe_domain import *
7
8from anuga_1d.config import g, epsilon
9
10
11
12print "Pipe Variable Width Only Test"
13
14# Define functions for initial quantities
15def 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
27def 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
38def 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
45def width(x):
46    return 1
47
48def top(x):
49    return 4
50 
51import time
52
53
54
55# Set final time and yield time for simulation
56finaltime = 10.0
57yieldstep = 1.0
58
59# Length of channel (m)
60L = 2500.0
61# Define the number of cells
62number_of_cells = [50]
63
64# Define cells for finite volume and their size
65N = int(number_of_cells[0])     
66print "Evaluating domain with %d cells" %N
67cell_len = 4*L/N # Origin = 0.0
68points = numpy.zeros(N+1,numpy.float)
69for 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       
75domain = Domain(points)
76
77
78# Set initial values of quantities - default to zero
79domain.set_quantity('area', initial_area)
80domain.set_quantity('elevation',bed)
81domain.set_quantity('width',width)
82domain.set_quantity('top',top)
83
84# Set boundry type, order, timestepping method and limiter
85domain.set_boundary({'exterior':Reflective_boundary(domain)})
86domain.order = 2
87domain.set_timestepping_method('euler')
88domain.set_CFL(1.0)
89domain.set_limiter("vanleer")
90#domain.h0=0.0001
91
92# Start timer
93t0 = time.time()
94
95
96
97
98
99for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
100    domain.write_time()
101
102N = float(N)
103HeightC    = domain.quantities['height'].centroid_values
104DischargeC = domain.quantities['discharge'].centroid_values
105C          = domain.centroids
106print 'That took %.2f seconds' %(time.time()-t0)
107X          = domain.vertices
108HeightQ    = domain.quantities['area'].vertex_values
109VelocityQ  = domain.quantities['velocity'].vertex_values
110Z          = domain.quantities['elevation'].vertex_values
111PipeH      = domain.quantities['top'].vertex_values
112Top        = Z + PipeH
113Stage      = HeightQ + Z
114
115
116
117from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot
118
119hold(False)
120   
121plot1 = subplot(211)
122plot(X.flat,Z.flat, X.flat,Stage.flat, X.flat,Top.flat)
123 
124plot1.set_ylim([-1,35])
125xlabel('Position')
126ylabel('Stage')
127legend(('Bed', 'Stage', 'Top'), 'upper right', shadow=True)
128plot2 = subplot(212)
129plot(X.flat,VelocityQ.flat)
130plot2.set_ylim([-10,10])
131   
132xlabel('Position')
133ylabel('Velocity')
134   
135show()
Note: See TracBrowser for help on using the repository browser.