[6694] | 1 | import os |
---|
| 2 | import time |
---|
| 3 | from math import sqrt, sin, cos, pi, exp |
---|
| 4 | from shallow_water_domain_suggestion2 import * |
---|
| 5 | from Numeric import zeros, Float |
---|
| 6 | from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot |
---|
| 7 | |
---|
| 8 | print "TEST 1D-SOLUTION I" |
---|
| 9 | L=2000.0 |
---|
| 10 | N=200 |
---|
| 11 | |
---|
| 12 | cell_len=L/N |
---|
| 13 | points=zeros(N+1, Float) |
---|
| 14 | for i in range(N+1): |
---|
| 15 | points[i]=i*cell_len |
---|
| 16 | |
---|
| 17 | domain=Domain(points) |
---|
| 18 | domain.order = 2 |
---|
| 19 | domain.set_timestepping_method('rk2') |
---|
| 20 | domain.cfl = 1.0 |
---|
[6713] | 21 | domain.limiter = "vanleer" |
---|
[6694] | 22 | |
---|
| 23 | def stage_flat(x): |
---|
| 24 | y=zeros(len(x), Float) |
---|
| 25 | for i in range(len(x)): |
---|
| 26 | y[i]=4.0 |
---|
| 27 | return y |
---|
| 28 | |
---|
| 29 | def elevation_arbitrary(x): |
---|
| 30 | y=zeros(len(x), Float) |
---|
| 31 | for i in range(len(x)): |
---|
| 32 | if 0 <= x[i] < 200.0: |
---|
| 33 | y[i] = -0.01*(x[i]-200) + 4.0 |
---|
| 34 | elif 200.0 <= x[i] < 300.0: |
---|
| 35 | y[i] = -0.02*(x[i]-200) + 4.0 |
---|
| 36 | elif 300.0 <= x[i] < 400.0: |
---|
| 37 | y[i] = -0.01*(x[i]-300) + 2.0 |
---|
| 38 | elif 400.0 <= x[i] < 550.0: |
---|
| 39 | y[i] = (-1/75.0)*(x[i]-400.0) + 2.0 |
---|
| 40 | elif 550.0 <= x[i] < 700.0: |
---|
| 41 | y[i] = (1/11250)*(x[i]-550)*(x[i]-550) |
---|
| 42 | elif 700.0 <= x[i] < 800.0: |
---|
| 43 | y[i] = 0.03*(x[i]-700) |
---|
| 44 | elif 800.0 <= x[i] < 900.0: |
---|
| 45 | y[i] = -0.03*(x[i]-800) + 3.0 |
---|
| 46 | elif 900.0 <= x[i] < 1000.0: |
---|
| 47 | y[i] = 6.0 |
---|
| 48 | elif 1000.0 <= x[i] < 1400.0: |
---|
| 49 | y[i] = (-1.0/20000)*(x[i]-1000)*(x[i]-1400) |
---|
| 50 | elif 1400.0 <= x[i] < 1500.0: |
---|
| 51 | y[i] = 0.0 |
---|
| 52 | elif 1500.0 <= x[i] < 1700.0: |
---|
| 53 | y[i] = 3.0 |
---|
| 54 | elif 1700.0 <= x[i] < 1800.0: |
---|
| 55 | y[i] = -0.03*(x[i]-1700) + 3.0 |
---|
| 56 | else: |
---|
| 57 | y[i] = (3.0/40000)*(x[i]-1800)*(x[i]-1800) + 2.0 |
---|
| 58 | return y |
---|
| 59 | |
---|
| 60 | def elevation_arbitrary1(x): |
---|
| 61 | y=zeros(len(x), Float) |
---|
| 62 | for i in range(len(x)): |
---|
| 63 | if 0 <= x[i] < 200.0: |
---|
| 64 | y[i] = -0.01*(x[i]-200) + 5.0 |
---|
| 65 | elif 200.0 <= x[i] < 900.0: |
---|
| 66 | y[i] = 0.0 |
---|
| 67 | elif 900.0 <= x[i] < 1000.0: # This is the island |
---|
| 68 | y[i] = 5.0 |
---|
| 69 | elif 1000.0 <= x[i] < 1800.0: |
---|
| 70 | y[i] = 0.0 |
---|
| 71 | else: |
---|
| 72 | y[i] = 0.03*(x[i]-1700) + 3.0 |
---|
| 73 | return y |
---|
| 74 | |
---|
| 75 | def elevation_arbitrary2(x): |
---|
| 76 | y=zeros(len(x), Float) |
---|
| 77 | for i in range(len(x)): |
---|
| 78 | if 0 <= x[i] < 1000.0: # This is the island |
---|
| 79 | y[i] = 5.0 |
---|
| 80 | else: |
---|
| 81 | y[i] = 0.0 |
---|
| 82 | return y |
---|
| 83 | |
---|
| 84 | domain.set_quantity('stage',stage_flat) |
---|
| 85 | domain.set_quantity('elevation',elevation_arbitrary) |
---|
| 86 | domain.set_boundary({'exterior':Reflective_boundary(domain)}) |
---|
[6713] | 87 | X=domain.vertices.flat |
---|
| 88 | C=domain.centroids.flat |
---|
[6694] | 89 | |
---|
| 90 | t0=time.time() |
---|
| 91 | yieldstep=finaltime=60.0 |
---|
| 92 | while finaltime < 60.2: |
---|
| 93 | for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): |
---|
| 94 | domain.write_time() |
---|
| 95 | print "t=",t |
---|
| 96 | print "integral", domain.quantities['height'].get_integral() |
---|
[6713] | 97 | StageQ=domain.quantities['stage'].vertex_values.flat |
---|
| 98 | MomentumQ=domain.quantities['xmomentum'].vertex_values.flat |
---|
| 99 | ElevationQ=domain.quantities['elevation'].vertex_values.flat |
---|
| 100 | VelocityQ=domain.quantities['velocity'].vertex_values.flat |
---|
[6694] | 101 | |
---|
| 102 | hold(False) |
---|
| 103 | plot1 = subplot(311) |
---|
| 104 | plot(X,StageQ, X,ElevationQ) |
---|
| 105 | plot1.set_ylim([-1.0,8.0]) |
---|
| 106 | xlabel('Position') |
---|
| 107 | ylabel('Stage') |
---|
| 108 | legend( ('Numerical Solution', 'Bed Elevation'), 'upper right', shadow=False) |
---|
| 109 | |
---|
| 110 | plot2 = subplot(312) |
---|
| 111 | plot(X,MomentumQ) |
---|
| 112 | #plot2.set_ylim([3.998,4.002]) |
---|
| 113 | legend( ('Numerical Solution', 'for momentum'), 'upper right', shadow=False) |
---|
| 114 | xlabel('Position') |
---|
| 115 | ylabel('Xmomentum') |
---|
| 116 | |
---|
| 117 | plot3 = subplot(313) |
---|
| 118 | plot(X,VelocityQ) |
---|
| 119 | #plot2.set_ylim([-5.0,30.0]) |
---|
| 120 | legend( ('Numerical Solution', 'for velocity'), 'upper right', shadow=False) |
---|
| 121 | xlabel('Position') |
---|
| 122 | ylabel('Velocity') |
---|
| 123 | |
---|
| 124 | file = "island_" |
---|
| 125 | file += str(finaltime) |
---|
| 126 | file += ".png" |
---|
| 127 | #savefig(file) |
---|
| 128 | show() |
---|
| 129 | |
---|
| 130 | print 'That took %.2f seconds'%(time.time()-t0) |
---|
| 131 | finaltime = finaltime + 10.0 |
---|
| 132 | raw_input("Press return key") |
---|