[7839] | 1 | import os |
---|
| 2 | from math import sqrt, pow, pi |
---|
| 3 | |
---|
[7842] | 4 | import numpy |
---|
[7839] | 5 | |
---|
[7842] | 6 | from anuga_1d.channel.channel_domain import * |
---|
| 7 | from anuga_1d.config import g, epsilon |
---|
| 8 | from anuga_1d.generic.generic_mesh import interval_mesh |
---|
[7839] | 9 | |
---|
| 10 | |
---|
| 11 | print "Channel Flow 1 Padarn Test" |
---|
| 12 | |
---|
| 13 | # Define functions for initial quantities |
---|
| 14 | def initial_area(x): |
---|
| 15 | return 1.4691*width(x) |
---|
| 16 | |
---|
| 17 | def width(x): |
---|
| 18 | x1=(x/1000)*(x/1000) |
---|
| 19 | x2=x1*(x/1000) |
---|
| 20 | x3=x2*(x/1000) |
---|
| 21 | return 10-64*(x1-2*x2+x3) |
---|
| 22 | |
---|
| 23 | def bed(x): |
---|
[7842] | 24 | y = numpy.ones(len(x),numpy.float) |
---|
[7839] | 25 | |
---|
[7842] | 26 | return numpy.where( (x<525) & (x>475),y,0.0) |
---|
| 27 | |
---|
| 28 | |
---|
[7839] | 29 | def initial_discharge(x): |
---|
| 30 | return 20 |
---|
| 31 | |
---|
| 32 | import time |
---|
| 33 | |
---|
| 34 | # Set final time and yield time for simulation |
---|
[7842] | 35 | finaltime = 50.0 |
---|
| 36 | yieldstep = 10.0 |
---|
[7839] | 37 | |
---|
| 38 | # Length of channel (m) |
---|
| 39 | L = 1000.0 |
---|
| 40 | # Define the number of cells |
---|
[7842] | 41 | N = 200 |
---|
[7839] | 42 | |
---|
[7842] | 43 | # Create domain with centroid points as defined above |
---|
| 44 | domain = Domain(*interval_mesh(N)) |
---|
[7839] | 45 | |
---|
| 46 | |
---|
| 47 | # Set initial values of quantities - default to zero |
---|
| 48 | domain.set_quantity('area', initial_area) |
---|
| 49 | domain.set_quantity('width',width) |
---|
| 50 | domain.set_quantity('elevation',bed) |
---|
| 51 | domain.set_quantity('discharge',initial_discharge) |
---|
| 52 | |
---|
| 53 | # Set boundry type, order, timestepping method and limiter |
---|
[7842] | 54 | Bd = Dirichlet_boundary([14,20,0,1.4,20/14,9,1.4]) |
---|
| 55 | domain.set_boundary({'left': Bd , 'right' : Bd }) |
---|
| 56 | |
---|
| 57 | |
---|
[7839] | 58 | domain.order = 2 |
---|
| 59 | domain.set_timestepping_method('rk2') |
---|
| 60 | domain.set_CFL(1.0) |
---|
| 61 | domain.set_limiter("vanleer") |
---|
| 62 | #domain.h0=0.0001 |
---|
| 63 | |
---|
| 64 | # Start timer |
---|
| 65 | t0 = time.time() |
---|
| 66 | |
---|
| 67 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
| 68 | domain.write_time() |
---|
| 69 | |
---|
[7842] | 70 | |
---|
| 71 | exit() |
---|
| 72 | |
---|
| 73 | HeightC = domain.quantities['height'].centroid_values |
---|
[7839] | 74 | DischargeC = domain.quantities['discharge'].centroid_values |
---|
[7842] | 75 | C = domain.centroids |
---|
[7839] | 76 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
[7842] | 77 | X = domain.vertices |
---|
| 78 | HeightQ = domain.quantities['height'].vertex_values |
---|
| 79 | VelocityQ = domain.quantities['velocity'].vertex_values |
---|
| 80 | Z = domain.quantities['elevation'].vertex_values |
---|
| 81 | Stage = HeightQ+Z |
---|
[7839] | 82 | |
---|
| 83 | from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot |
---|
| 84 | |
---|
| 85 | hold(False) |
---|
| 86 | |
---|
| 87 | plot1 = subplot(211) |
---|
| 88 | |
---|
[7842] | 89 | plot(X.flat,Z.flat,X.flat,Stage.flat) |
---|
[7839] | 90 | |
---|
| 91 | plot1.set_ylim([-1,11]) |
---|
| 92 | xlabel('Position') |
---|
| 93 | ylabel('Stage') |
---|
| 94 | legend(('Analytical Solution', 'Numerical Solution'), |
---|
| 95 | 'upper right', shadow=True) |
---|
[7842] | 96 | |
---|
[7839] | 97 | plot2 = subplot(212) |
---|
[7842] | 98 | plot(X.flat,VelocityQ.flat) |
---|
[7839] | 99 | plot2.set_ylim([-10,10]) |
---|
| 100 | |
---|
| 101 | xlabel('Position') |
---|
| 102 | ylabel('Velocity') |
---|
| 103 | |
---|
| 104 | show() |
---|
| 105 | |
---|