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') |
---|
19 | #from balanced_basic import * |
---|
20 | #from bal_and import * |
---|
21 | #from anuga_tsunami import * |
---|
22 | #--------- |
---|
23 | #Setup computational domain |
---|
24 | #--------- |
---|
25 | points, vertices, boundary = anuga.rectangular_cross(40,40) |
---|
26 | |
---|
27 | domain=Domain(points,vertices,boundary) # Create Domain |
---|
28 | domain.set_name('runup_v2') # Output to file runup.sww |
---|
29 | domain.set_datadir('.') # Use current folder |
---|
30 | #domain.set_store_centroids(True) |
---|
31 | domain.set_flow_algorithm('DE1') |
---|
32 | #domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) |
---|
33 | #domain.set_store_vertices_uniquely(True) |
---|
34 | #------------------ |
---|
35 | # Define topography |
---|
36 | #------------------ |
---|
37 | |
---|
38 | scale_me=1.0 |
---|
39 | |
---|
40 | def topography(x,y): |
---|
41 | return -x/2*scale_me #+0.05*numpy.sin((x+y)*50.0) #+0.1*(numpy.random.rand(len(x)) -0.5) # Linear bed slope + small random perturbation |
---|
42 | |
---|
43 | def stagefun(x,y): |
---|
44 | #stg=(-0.2*(x<0.5) -0.1*(x>=0.5))*scale_me |
---|
45 | stg=-0.2*scale_me # Stage |
---|
46 | #topo=topography(x,y) #Bed |
---|
47 | return stg #*(stg>topo) + topo*(stg<=topo) |
---|
48 | |
---|
49 | domain.set_quantity('elevation',topography) # Use function for elevation |
---|
50 | 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. |
---|
51 | |
---|
52 | domain.set_quantity('friction',0.03) # Constant friction |
---|
53 | |
---|
54 | domain.set_quantity('stage', stagefun) # Constant negative initial stage |
---|
55 | |
---|
56 | #-------------------------- |
---|
57 | # Setup boundary conditions |
---|
58 | #-------------------------- |
---|
59 | Br=anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
60 | Bt=anuga.Transmissive_boundary(domain) # Continue all values of boundary -- not used in this example |
---|
61 | Bd=anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.]) # Constant boundary values -- not used in this example |
---|
62 | #Bw=anuga.Time_boundary(domain=domain, |
---|
63 | # 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. |
---|
64 | |
---|
65 | #---------------------------------------------- |
---|
66 | # Associate boundary tags with boundary objects |
---|
67 | #---------------------------------------------- |
---|
68 | domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom':Br}) |
---|
69 | |
---|
70 | #------------------------------ |
---|
71 | #Evolve the system through time |
---|
72 | #------------------------------ |
---|
73 | |
---|
74 | for t in domain.evolve(yieldstep=0.2,finaltime=30.0): |
---|
75 | print domain.timestepping_statistics() |
---|
76 | uh=domain.quantities['xmomentum'].centroid_values |
---|
77 | vh=domain.quantities['ymomentum'].centroid_values |
---|
78 | depth=domain.quantities['height'].centroid_values#domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values |
---|
79 | depth=depth*(depth>1.0e-06) + 1.0e-06 |
---|
80 | vel=((uh/depth)**2 + (vh/depth)**2)**0.5 |
---|
81 | print 'peak speed is', vel.max() |
---|
82 | |
---|
83 | print 'Finished' |
---|