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 | #--------- |
---|
18 | #Setup computational domain |
---|
19 | #--------- |
---|
20 | points, vertices, boundary = anuga.rectangular_cross(40,40) |
---|
21 | |
---|
22 | domain=Domain(points,vertices,boundary) # Create Domain |
---|
23 | domain.set_name('runup_sinusoid_v2') # Output to file runup.sww |
---|
24 | domain.set_datadir('.') # Use current folder |
---|
25 | domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) |
---|
26 | #domain.set_store_vertices_uniquely(True) |
---|
27 | |
---|
28 | #------------------ |
---|
29 | # Define topography |
---|
30 | #------------------ |
---|
31 | scale_me=1.0 |
---|
32 | def topography(x,y): |
---|
33 | return (-x/2.0 +0.05*numpy.sin((x+y)*50.0))*scale_me |
---|
34 | |
---|
35 | def stagefun(x,y): |
---|
36 | stge=-0.2*scale_me #-0.1*(x>0.5) -0.2*(x<=0.5) |
---|
37 | #topo=topography(x,y) |
---|
38 | return stge#*(stge>topo) + (topo)*(stge<=topo) |
---|
39 | |
---|
40 | domain.set_quantity('elevation',topography) # Use function for elevation |
---|
41 | domain.get_quantity('elevation').smooth_vertex_values() |
---|
42 | |
---|
43 | domain.set_quantity('friction',0.00) # Constant friction |
---|
44 | |
---|
45 | #def frict_change(x,y): |
---|
46 | # return 0.2*(x>0.5)+0.1*(x<=0.5) |
---|
47 | # |
---|
48 | #domain.set_quantity('friction',frict_change) |
---|
49 | |
---|
50 | domain.set_quantity('stage', stagefun) # Constant negative initial stage |
---|
51 | domain.get_quantity('stage').smooth_vertex_values() |
---|
52 | |
---|
53 | # Experiment with rain. |
---|
54 | # rainin = anuga.shallow_water.forcing.Rainfall(domain, rate=0.001) #, center=(0.,0.), radius=1000. ) |
---|
55 | # domain.forcing_terms.append(rainin) |
---|
56 | |
---|
57 | #-------------------------- |
---|
58 | # Setup boundary conditions |
---|
59 | #-------------------------- |
---|
60 | Br=anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
61 | Bt=anuga.Transmissive_boundary(domain) # Continue all values of boundary -- not used in this example |
---|
62 | Bd=anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.]) # Constant boundary values -- not used in this example |
---|
63 | #Bw=anuga.Time_boundary(domain=domain, |
---|
64 | # 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. |
---|
65 | |
---|
66 | #---------------------------------------------- |
---|
67 | # Associate boundary tags with boundary objects |
---|
68 | #---------------------------------------------- |
---|
69 | domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom':Br}) |
---|
70 | |
---|
71 | #------------------------------ |
---|
72 | #Evolve the system through time |
---|
73 | #------------------------------ |
---|
74 | |
---|
75 | for t in domain.evolve(yieldstep=0.1,finaltime=20.0): |
---|
76 | print domain.timestepping_statistics() |
---|
77 | |
---|
78 | print 'Finished' |
---|