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 exp |
---|
11 | from anuga.shallow_water.shallow_water_domain import Domain as Domain |
---|
12 | |
---|
13 | ## Set up mesh |
---|
14 | |
---|
15 | boundaryPolygon=[ [0., 0.], [0., 100.], [100.0, 100.0], [100.0, 0.0]] |
---|
16 | midResPolygon=[ [30., 30.], [30., 70.], [70., 70.], [70., 30.]] |
---|
17 | higherResPolygon=[ [40., 40.], [40., 60.], [60., 60.], [60., 40.]] |
---|
18 | # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values |
---|
19 | riverWall={ 'leftWall': |
---|
20 | [ [50., 0.0, -0.0], |
---|
21 | [50., 45.5, -0.0]], |
---|
22 | 'centralWall': |
---|
23 | [[50., 45.5, -0.2], |
---|
24 | [50., 54.5, -0.2]], |
---|
25 | 'rightWall': |
---|
26 | [ [50., 54.5, -0.0], |
---|
27 | [50., 100.0, -0.0]] |
---|
28 | } |
---|
29 | |
---|
30 | riverWall_Par={'centralWall':{'Qfactor':1.0}} |
---|
31 | # Try to avoid any shallow-water type solution -- becomes unstable |
---|
32 | #riverWall_Par={'centralWall':{'Qfactor':1.0, 's1': 0.999, 's2':0.9999, 'h1':100, 'h2':150}} |
---|
33 | |
---|
34 | # The boundary polygon + riverwall breaks the mesh into multiple regions |
---|
35 | # Must define the resolution in these areas with an xy point + maximum area |
---|
36 | # Otherwise triangle.c gets confused |
---|
37 | regionPtAreas=[ [99., 99., 10.0*10.0*0.5], |
---|
38 | [1., 1., 10.0*10.0*0.5], |
---|
39 | [45., 45., 1.0*1.0*0.5], |
---|
40 | [55., 55., 1.0*1.0*0.5], |
---|
41 | [65., 65., 3.0*3.0*0.5], |
---|
42 | [35., 35., 3.0*3.0*0.5] ] |
---|
43 | |
---|
44 | anuga.create_mesh_from_regions(boundaryPolygon, |
---|
45 | boundary_tags={'left': [0], |
---|
46 | 'top': [1], |
---|
47 | 'right': [2], |
---|
48 | 'bottom': [3]}, |
---|
49 | maximum_triangle_area = 1.0e+20, |
---|
50 | minimum_triangle_angle = 28.0, |
---|
51 | filename = 'runup.msh', |
---|
52 | interior_regions = [ [higherResPolygon, 1.*1.*0.5], |
---|
53 | [midResPolygon, 3.0*3.0*0.5]], |
---|
54 | breaklines=riverWall.values(), |
---|
55 | use_cache=False, |
---|
56 | verbose=True, |
---|
57 | regionPtArea=regionPtAreas) |
---|
58 | |
---|
59 | domain=anuga.create_domain_from_file('runup.msh') |
---|
60 | domain.set_name('runup_riverwall') |
---|
61 | domain.set_datadir('.') |
---|
62 | domain.set_flow_algorithm('DE1') |
---|
63 | domain.set_store_vertices_uniquely(True) |
---|
64 | domain.riverwallData.create_riverwalls(riverWall, riverWall_Par) |
---|
65 | |
---|
66 | #------------------ |
---|
67 | # Define topography |
---|
68 | #------------------ |
---|
69 | |
---|
70 | scale_me=1.0 |
---|
71 | |
---|
72 | def topography(x,y): |
---|
73 | return -x/150.*scale_me |
---|
74 | |
---|
75 | def stagefun(x,y): |
---|
76 | stg=-0.5*scale_me |
---|
77 | return stg |
---|
78 | |
---|
79 | domain.set_quantity('elevation',topography) # Use function for elevation |
---|
80 | |
---|
81 | domain.set_quantity('friction',0.03) # Constant friction |
---|
82 | |
---|
83 | domain.set_quantity('stage', stagefun) # Constant negative initial stage |
---|
84 | |
---|
85 | #-------------------------- |
---|
86 | # Setup boundary conditions |
---|
87 | #-------------------------- |
---|
88 | |
---|
89 | Br=anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
90 | |
---|
91 | def boundaryFun(t): |
---|
92 | output=-0.4*exp(-t/100.)-0.1 |
---|
93 | output=min(output,-0.11) |
---|
94 | #output=min(output,-0.3) |
---|
95 | return output |
---|
96 | |
---|
97 | Bin_tmss = anuga.shallow_water.boundaries.Transmissive_momentum_set_stage_boundary(domain=domain, function = boundaryFun) |
---|
98 | |
---|
99 | #---------------------------------------------- |
---|
100 | # Associate boundary tags with boundary objects |
---|
101 | #---------------------------------------------- |
---|
102 | domain.set_boundary({'left': Br, 'right': Bin_tmss, 'top': Br, 'bottom':Br}) |
---|
103 | |
---|
104 | #------------------------------ |
---|
105 | #Evolve the system through time |
---|
106 | #------------------------------ |
---|
107 | |
---|
108 | for t in domain.evolve(yieldstep=10.0,finaltime=4000.0): |
---|
109 | print domain.timestepping_statistics() |
---|
110 | # Print velocity as we go |
---|
111 | uh=domain.quantities['xmomentum'].centroid_values |
---|
112 | vh=domain.quantities['ymomentum'].centroid_values |
---|
113 | depth=domain.quantities['height'].centroid_values |
---|
114 | depth=depth*(depth>1.0e-06) + 1.0e-06 |
---|
115 | vel=((uh/depth)**2 + (vh/depth)**2)**0.5 |
---|
116 | print 'peak speed is', vel.max() |
---|
117 | |
---|
118 | print 'Finished' |
---|