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

Last change on this file was 8209, checked in by steve, 14 years ago

Commiting quite a few changes to operators and parallel stuff

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