source: trunk/anuga_1d_core/channel/run_padarn.py @ 9737

Last change on this file since 9737 was 9099, checked in by steve, 11 years ago

Changed name so that scrit is not picked up in test_all

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