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.shallow_water_domain import Domain as Domain |
---|
12 | #from anuga.shallow_water_balanced2.swb2_domain import Domain as Domain |
---|
13 | #path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/development/gareth/balanced_basic') |
---|
14 | #from swb2_domain import * |
---|
15 | #from balanced_basic import * |
---|
16 | from balanced_dev import * |
---|
17 | #from anuga_tsunami import * |
---|
18 | |
---|
19 | #--------- |
---|
20 | #Setup computational domain |
---|
21 | #--------- |
---|
22 | points, vertices, boundary = anuga.rectangular_cross(20,20, len1=1., len2=1.) |
---|
23 | |
---|
24 | domain=Domain(points,vertices,boundary) # Create Domain |
---|
25 | domain.set_name('runup_sinusoid_v2') # Output to file runup.sww |
---|
26 | #domain.set_timestepping_method('euler') |
---|
27 | #------------------ |
---|
28 | # Define topography |
---|
29 | #------------------ |
---|
30 | scale_me=1.0 |
---|
31 | boundary_ws=-0.1 |
---|
32 | init_ws=-0.2 |
---|
33 | bumpiness=10. # Higher = shorter wavelength oscillations in topography |
---|
34 | #domain.minimum_allowed_height=domain.minimum_allowed_height*scale_me # Seems needed to make the algorithms behave |
---|
35 | |
---|
36 | def topography(x,y): |
---|
37 | return (-x/2.0 +0.05*numpy.sin((x+y)*bumpiness))*scale_me |
---|
38 | |
---|
39 | def stagefun(x,y): |
---|
40 | stge=init_ws*scale_me# +0.1*(x>0.9)*scale_me |
---|
41 | #topo=topography(x,y) |
---|
42 | return stge#*(stge>topo) + (topo)*(stge<=topo) |
---|
43 | |
---|
44 | domain.set_quantity('elevation',topography) # Use function for elevation |
---|
45 | domain.get_quantity('elevation').smooth_vertex_values() |
---|
46 | domain.set_quantity('friction',0.00) # Constant friction |
---|
47 | |
---|
48 | #def frict_change(x,y): |
---|
49 | # return 0.2*(x>0.5)+0.1*(x<=0.5) |
---|
50 | # |
---|
51 | #domain.set_quantity('friction',frict_change) |
---|
52 | |
---|
53 | domain.set_quantity('stage', stagefun) # Constant negative initial stage |
---|
54 | domain.get_quantity('stage').smooth_vertex_values() |
---|
55 | |
---|
56 | #print domain.forcing_terms |
---|
57 | #assert 0==1 |
---|
58 | # Experiment with rain. |
---|
59 | # rainin = anuga.shallow_water.forcing.Rainfall(domain, rate=0.001) #, center=(0.,0.), radius=1000. ) |
---|
60 | # domain.forcing_terms.append(rainin) |
---|
61 | |
---|
62 | #-------------------------- |
---|
63 | # Setup boundary conditions |
---|
64 | #-------------------------- |
---|
65 | Br=anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
66 | Bt=anuga.Transmissive_boundary(domain) # Continue all values of boundary -- not used in this example |
---|
67 | Bd=anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.]) # Constant boundary values -- not used in this example |
---|
68 | def waveform(t): |
---|
69 | return boundary_ws*scale_me |
---|
70 | #return -0.2*scale_me #-0.1 #(0.0*sin(t*2*pi)-0.1)*exp(-t)-0.1 |
---|
71 | Bt2=anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain,waveform) |
---|
72 | #Bw=anuga.Time_boundary(domain=domain, |
---|
73 | # 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. |
---|
74 | |
---|
75 | #---------------------------------------------- |
---|
76 | # Associate boundary tags with boundary objects |
---|
77 | #---------------------------------------------- |
---|
78 | domain.set_boundary({'left': Br, 'right': Bt2, 'top': Br, 'bottom':Br}) |
---|
79 | |
---|
80 | #------------------------------ |
---|
81 | #Evolve the system through time |
---|
82 | #------------------------------ |
---|
83 | |
---|
84 | for t in domain.evolve(yieldstep=0.2,finaltime=120.00): |
---|
85 | print domain.timestepping_statistics() |
---|
86 | #print domain.boundary_flux_integral |
---|
87 | xx = domain.quantities['xmomentum'].centroid_values |
---|
88 | yy = domain.quantities['ymomentum'].centroid_values |
---|
89 | dd = domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values |
---|
90 | dd_raw=1.0*dd |
---|
91 | dd = dd*(dd>1.0e-03)+1.0e-03*(dd<=1.0e-03) |
---|
92 | vv = ( (xx/dd)**2 + (yy/dd)**2)**0.5 |
---|
93 | vv = vv*(dd>1.0e-03) |
---|
94 | print 'Peak velocity is: ', vv.max(), vv.argmax(), dd[vv.argmax()] |
---|
95 | print 'Volume is', sum(dd_raw*domain.areas) |
---|
96 | #print 'Volume less flux int', sum(dd_raw*domain.areas) - domain.boundary_flux_integral |
---|
97 | |
---|
98 | |
---|
99 | vel_final_inds=(vv>1.0e-01).nonzero() |
---|
100 | print 'vel_final_inds', vel_final_inds |
---|
101 | |
---|
102 | print 'Finished' |
---|