[7909] | 1 | import os |
---|
| 2 | from math import sqrt |
---|
| 3 | from sww_domain_simplified import * |
---|
| 4 | from Numeric import Float |
---|
| 5 | from numpy import zeros |
---|
| 6 | from sf_parameters import * |
---|
| 7 | |
---|
| 8 | N = int(N) # number of cells |
---|
| 9 | print "number of cells=",N |
---|
| 10 | boundary = {(0,0):'left', (N-1,1): 'right'} |
---|
| 11 | domain = Domain(points,boundary) |
---|
| 12 | domain.order = 2 |
---|
| 13 | domain.set_timestepping_method('rk2') |
---|
| 14 | domain.cfl = 1.0 |
---|
| 15 | domain.limiter = "minmod" |
---|
| 16 | |
---|
| 17 | def stage(x): |
---|
| 18 | y=zeros(len(x), Float) |
---|
| 19 | for i in range(len(x)): |
---|
| 20 | if x[i] < 11.666: |
---|
| 21 | y[i] = 0.4125 |
---|
| 22 | else: |
---|
| 23 | y[i] = 0.33 |
---|
| 24 | return y |
---|
| 25 | domain.set_quantity('stage',stage) |
---|
| 26 | |
---|
| 27 | def elevation(x): |
---|
| 28 | z_b = zeros(len(x),Float) |
---|
| 29 | for i in range(len(x)): |
---|
| 30 | if (x[i] >= 8.0) & (x[i] <= 12.0): |
---|
| 31 | z_b[i] = 0.2 - 0.05*(x[i]-10.0)**2.0 |
---|
| 32 | else: |
---|
| 33 | z_b[i] = 0.0 |
---|
| 34 | return z_b |
---|
| 35 | domain.set_quantity('elevation',elevation) |
---|
| 36 | |
---|
| 37 | ### ================ Define the boundary function ========================= |
---|
| 38 | # ['stage', 'xmomentum', 'elevation', 'height', 'velocity'] |
---|
| 39 | D_left = Dirichlet_boundary([0.4125, 0.18, 0.0, 0.4125, 0.18/0.4125]) |
---|
| 40 | D_right = Dirichlet_boundary([0.33, 0.18, 0.0, 0.33, 0.18/0.33]) |
---|
| 41 | domain.set_boundary({'left':D_left,'right':D_right}) |
---|
| 42 | ### ================ End of the definition of boundary function =========== |
---|
| 43 | |
---|
| 44 | X=domain.vertices |
---|
| 45 | C=domain.centroids |
---|
| 46 | import time |
---|
| 47 | yieldstep=finaltime=0.1 |
---|
| 48 | t0=time.time() |
---|
| 49 | i=1 |
---|
| 50 | |
---|
| 51 | while finaltime < 0.101: |
---|
| 52 | for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): |
---|
| 53 | domain.write_time() |
---|
| 54 | finaltime = finaltime + 10.0 |
---|
| 55 | if t>0.0: |
---|
| 56 | N = float(N) |
---|
| 57 | StageC = domain.quantities['stage'].centroid_values |
---|
| 58 | XmomC = domain.quantities['xmomentum'].centroid_values |
---|
| 59 | VelC = domain.quantities['velocity'].centroid_values |
---|
| 60 | |
---|
| 61 | X = domain.vertices |
---|
| 62 | StageQ = domain.quantities['stage'].vertex_values.flat |
---|
| 63 | XmomQ = domain.quantities['xmomentum'].vertex_values.flat |
---|
| 64 | VelQ = domain.quantities['velocity'].vertex_values.flat |
---|
| 65 | BedQ = domain.quantities['elevation'].vertex_values.flat |
---|
| 66 | |
---|
| 67 | SD = domain.shock_detector |
---|
| 68 | |
---|
| 69 | from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot |
---|
| 70 | hold(False) |
---|
| 71 | |
---|
| 72 | plot1 = subplot(211) |
---|
| 73 | plot(X,StageQ, X,BedQ) |
---|
| 74 | #plot1.set_ylim([-1,11]) |
---|
| 75 | #plot1.set_xlim([0.0,2000.0]) |
---|
| 76 | legend(('Numerical solution', 'Bed elevation'), |
---|
| 77 | 'upper left', shadow=False) |
---|
| 78 | #xlabel('Position') |
---|
| 79 | ylabel('Stage') |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | plot2 = subplot(212) |
---|
| 83 | plot(points,SD) |
---|
| 84 | #plot2.set_xlim([0.0,2000.0]) |
---|
| 85 | xlabel('Position') |
---|
| 86 | ylabel('Smoothness indicator') |
---|
| 87 | |
---|
| 88 | print 'That took %.2f seconds'%(time.time()-t0) |
---|
| 89 | show() |
---|
| 90 | |
---|
| 91 | #filename = "%s%04i%s" %("dam_", i, ".eps") |
---|
| 92 | #savefig(filename) |
---|
| 93 | #finaltime = finaltime + 0.25 |
---|
| 94 | #print "finaltime=", finaltime |
---|
| 95 | #i = i + 1 |
---|
| 96 | #print "The domain.limiter is", domain.limiter |
---|
| 97 | #print 'That took %.2f seconds'%(time.time()-t0) |
---|
| 98 | #print '=============================================================================' |
---|