[8308] | 1 | """Runup example from the manual, slightly modified |
---|
| 2 | """ |
---|
| 3 | #--------- |
---|
| 4 | #Import Modules |
---|
| 5 | #-------- |
---|
| 6 | import anuga |
---|
| 7 | |
---|
| 8 | import numpy |
---|
| 9 | |
---|
| 10 | from math import sin, pi, exp |
---|
| 11 | #from anuga.shallow_water_balanced2.swb2_domain import Domain as Domain |
---|
| 12 | #from anuga.shallow_water.shallow_water_domain import Domain as Domain |
---|
| 13 | #from shallow_water_balanced_steve.swb_domain import * |
---|
| 14 | #import shallow_water_balanced_steve.swb_domain |
---|
| 15 | #from shallow_water_balanced_steve.swb_domain import Domain as Domain |
---|
| 16 | #path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/shallow_water_balanced_steve') |
---|
| 17 | #from swb_domain import * |
---|
| 18 | #path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/development/gareth/balanced_basic') |
---|
[8353] | 19 | #from balanced_basic import * |
---|
| 20 | from balanced_dev import * |
---|
[8308] | 21 | #--------- |
---|
| 22 | #Setup computational domain |
---|
| 23 | #--------- |
---|
| 24 | points, vertices, boundary = anuga.rectangular_cross(40,40) |
---|
| 25 | |
---|
| 26 | domain=Domain(points,vertices,boundary) # Create Domain |
---|
| 27 | domain.set_name('runup_v2') # Output to file runup.sww |
---|
| 28 | domain.set_datadir('.') # Use current folder |
---|
| 29 | domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) |
---|
[8353] | 30 | #domain.set_store_vertices_uniquely(True) |
---|
[8308] | 31 | #------------------ |
---|
| 32 | # Define topography |
---|
| 33 | #------------------ |
---|
| 34 | |
---|
| 35 | def topography(x,y): |
---|
| 36 | return -x/2 #+0.05*numpy.sin((x+y)*50.0) #+0.1*(numpy.random.rand(len(x)) -0.5) # Linear bed slope + small random perturbation |
---|
| 37 | |
---|
| 38 | def stagefun(x,y): |
---|
| 39 | #stg=-0.2*(x<0.5) -0.1*(x>=0.5) |
---|
| 40 | stg=-0.2 # Stage |
---|
| 41 | #topo=topography(x,y) #Bed |
---|
| 42 | return stg #*(stg>topo) + topo*(stg<=topo) |
---|
| 43 | |
---|
| 44 | domain.set_quantity('elevation',topography) # Use function for elevation |
---|
| 45 | domain.get_quantity('elevation').smooth_vertex_values() # Steve's fix -- without this, substantial artificial velcities are generated everywhere in the domain. With this fix, there are artificial velocities near the coast, but not elsewhere. |
---|
| 46 | |
---|
| 47 | domain.set_quantity('friction',0.00) # Constant friction |
---|
| 48 | |
---|
| 49 | domain.set_quantity('stage', stagefun) # Constant negative initial stage |
---|
| 50 | |
---|
| 51 | #-------------------------- |
---|
| 52 | # Setup boundary conditions |
---|
| 53 | #-------------------------- |
---|
| 54 | Br=anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
| 55 | Bt=anuga.Transmissive_boundary(domain) # Continue all values of boundary -- not used in this example |
---|
| 56 | Bd=anuga.Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values -- not used in this example |
---|
| 57 | Bw=anuga.Time_boundary(domain=domain, |
---|
| 58 | f=lambda t: [(0.0*sin(t*2*pi)-0.1)*exp(-t)-0.1,0.0,0.0]) # Time varying boundary -- get rid of the 0.0 to do a runup. |
---|
| 59 | |
---|
| 60 | #---------------------------------------------- |
---|
| 61 | # Associate boundary tags with boundary objects |
---|
| 62 | #---------------------------------------------- |
---|
[8353] | 63 | domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom':Br}) |
---|
[8308] | 64 | |
---|
| 65 | #------------------------------ |
---|
| 66 | #Evolve the system through time |
---|
| 67 | #------------------------------ |
---|
| 68 | |
---|
[8446] | 69 | for t in domain.evolve(yieldstep=0.2,finaltime=60.0): |
---|
[8308] | 70 | print domain.timestepping_statistics() |
---|
[8446] | 71 | uh=domain.quantities['xmomentum'].centroid_values |
---|
| 72 | vh=domain.quantities['ymomentum'].centroid_values |
---|
| 73 | depth=domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values |
---|
| 74 | depth=depth*(depth>1.0e-06) + 1.0e-06 |
---|
| 75 | vel=((uh/depth)**2 + (vh/depth)**2)**0.5 |
---|
| 76 | print 'peak speed is', vel.max() |
---|
[8308] | 77 | |
---|
| 78 | print 'Finished' |
---|