[7857] | 1 | import os |
---|
| 2 | from math import sqrt, pi |
---|
[7860] | 3 | import numpy |
---|
| 4 | import time |
---|
| 5 | #from Numeric import allclose, array, zeros, ones, Float, take, sqrt |
---|
[7857] | 6 | |
---|
| 7 | |
---|
[7860] | 8 | |
---|
| 9 | from anuga_1d.sww.sww_domain import * |
---|
| 10 | from anuga_1d.config import g, epsilon |
---|
| 11 | from anuga_1d.base.generic_mesh import uniform_mesh |
---|
| 12 | |
---|
[7857] | 13 | h1 = 10.0 |
---|
[7868] | 14 | h0 = 0.1 |
---|
[7857] | 15 | |
---|
| 16 | def analytical_sol(C,t): |
---|
| 17 | |
---|
| 18 | #t = 0.0 # time (s) |
---|
| 19 | # gravity (m/s^2) |
---|
| 20 | #h1 = 10.0 # depth upstream (m) |
---|
| 21 | #h0 = 0.0 # depth downstream (m) |
---|
| 22 | L = 2000.0 # length of stream/domain (m) |
---|
| 23 | n = len(C) # number of cells |
---|
| 24 | |
---|
| 25 | u = zeros(n,Float) |
---|
| 26 | h = zeros(n,Float) |
---|
| 27 | x = C-3*L/4.0 |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | for i in range(n): |
---|
| 31 | # Calculate Analytical Solution at time t > 0 |
---|
| 32 | u3 = 2.0/3.0*(sqrt(g*h1)+x[i]/t) |
---|
| 33 | h3 = 4.0/(9.0*g)*(sqrt(g*h1)-x[i]/(2.0*t))*(sqrt(g*h1)-x[i]/(2.0*t)) |
---|
| 34 | u3_ = 2.0/3.0*((x[i]+L/2.0)/t-sqrt(g*h1)) |
---|
| 35 | h3_ = 1.0/(9.0*g)*((x[i]+L/2.0)/t+2*sqrt(g*h1))*((x[i]+L/2.0)/t+2*sqrt(g*h1)) |
---|
| 36 | |
---|
| 37 | if ( x[i] <= -1*L/2.0+2*(-sqrt(g*h1)*t)): |
---|
| 38 | u[i] = 0.0 |
---|
| 39 | h[i] = h0 |
---|
| 40 | elif ( x[i] <= -1*L/2.0-(-sqrt(g*h1)*t)): |
---|
| 41 | u[i] = u3_ |
---|
| 42 | h[i] = h3_ |
---|
| 43 | |
---|
| 44 | elif ( x[i] <= -t*sqrt(g*h1) ): |
---|
| 45 | u[i] = 0.0 |
---|
| 46 | h[i] = h1 |
---|
| 47 | elif ( x[i] <= 2.0*t*sqrt(g*h1) ): |
---|
| 48 | u[i] = u3 |
---|
| 49 | h[i] = h3 |
---|
| 50 | else: |
---|
| 51 | u[i] = 0.0 |
---|
| 52 | h[i] = h0 |
---|
| 53 | |
---|
| 54 | return h , u*h, u |
---|
| 55 | |
---|
| 56 | |
---|
[7860] | 57 | |
---|
[7857] | 58 | def stage(x): |
---|
[7860] | 59 | import numpy |
---|
| 60 | |
---|
| 61 | y = numpy.where( (x>=L/4.0) & (x<=3*L/4.0), h1 , h0) |
---|
| 62 | |
---|
| 63 | # for i in range(len(x)): |
---|
| 64 | # if x[i]<=L/4.0: |
---|
| 65 | # y[i] = h0 |
---|
| 66 | # elif x[i]<=3*L/4.0: |
---|
| 67 | # y[i] = h1 |
---|
| 68 | # else: |
---|
| 69 | # y[i] = h0 |
---|
[7857] | 70 | return y |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
[7860] | 74 | print "TEST 1D-SOLUTION III -- DRY BED" |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | finaltime = 4.0 |
---|
[7857] | 78 | yieldstep = 0.1 |
---|
| 79 | L = 2000.0 # Length of channel (m) |
---|
| 80 | |
---|
| 81 | k = 0 |
---|
| 82 | |
---|
[7868] | 83 | N = 3200 |
---|
[7857] | 84 | print "Evaluating domain with %d cells" %N |
---|
[7868] | 85 | domain = Domain(*uniform_mesh(N,x_1=L)) |
---|
[7857] | 86 | |
---|
| 87 | domain.set_quantity('stage', stage) |
---|
[7860] | 88 | |
---|
| 89 | Br = Reflective_boundary(domain) |
---|
| 90 | |
---|
| 91 | domain.set_boundary({'left': Br, 'right' : Br}) |
---|
[7868] | 92 | domain.set_spatial_order(2) |
---|
| 93 | domain.set_timestepping_method('rk2') |
---|
[7857] | 94 | domain.set_CFL(1.0) |
---|
[7868] | 95 | domain.set_limiter("minmod_kurganov") |
---|
[7857] | 96 | #domain.h0=0.0001 |
---|
| 97 | |
---|
| 98 | t0 = time.time() |
---|
| 99 | |
---|
| 100 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
| 101 | domain.write_time() |
---|
| 102 | |
---|
[7860] | 103 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
[7857] | 104 | |
---|
| 105 | |
---|
[7860] | 106 | N = float(N) |
---|
| 107 | HeightC = domain.quantities['height'].centroid_values |
---|
| 108 | StageC = domain.quantities['stage'].centroid_values |
---|
| 109 | BedC = domain.quantities['elevation'].centroid_values |
---|
| 110 | C = domain.centroids |
---|
| 111 | |
---|
| 112 | HeightV = domain.quantities['height'].vertex_values |
---|
| 113 | StageV = domain.quantities['stage'].vertex_values |
---|
| 114 | BedV = domain.quantities['elevation'].vertex_values |
---|
| 115 | VelocityV = domain.quantities['velocity'].vertex_values |
---|
| 116 | X = domain.vertices |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | import pylab |
---|
| 120 | |
---|
| 121 | pylab.hold(False) |
---|
| 122 | |
---|
| 123 | plot1 = pylab.subplot(211) |
---|
| 124 | |
---|
| 125 | pylab.plot(X.flat,BedV.flat,X.flat,StageV.flat) |
---|
| 126 | |
---|
| 127 | plot1.set_ylim([-1,11]) |
---|
| 128 | |
---|
| 129 | pylab.xlabel('Position') |
---|
| 130 | pylab.ylabel('Stage') |
---|
| 131 | pylab.legend(('Analytical Solution', 'Numerical Solution'), |
---|
| 132 | 'upper right', shadow=True) |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | plot2 = pylab.subplot(212) |
---|
| 136 | |
---|
| 137 | pylab.plot(X.flat,VelocityV.flat) |
---|
[7868] | 138 | plot2.set_ylim([-15,15]) |
---|
[7860] | 139 | |
---|
| 140 | pylab.xlabel('Position') |
---|
| 141 | pylab.ylabel('Velocity') |
---|
| 142 | |
---|
| 143 | pylab.show() |
---|
| 144 | |
---|