1 | """Example of shallow water wave equation. |
---|
2 | |
---|
3 | Island surrounded by water. |
---|
4 | This example investigates onshore 'creep' |
---|
5 | |
---|
6 | Creep is defined as water moving uphill over many timesteps. |
---|
7 | The initial adjustment at time = 0 is not 'creep' |
---|
8 | |
---|
9 | """ |
---|
10 | |
---|
11 | |
---|
12 | #------------------------------------------------------------------------------ |
---|
13 | # Import necessary modules |
---|
14 | #------------------------------------------------------------------------------ |
---|
15 | |
---|
16 | # Standard modules |
---|
17 | from math import exp |
---|
18 | |
---|
19 | # Application specific imports |
---|
20 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular |
---|
21 | from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary |
---|
22 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
23 | from anuga.utilities.polygon import Polygon_function, read_polygon |
---|
24 | |
---|
25 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
26 | from Numeric import allclose |
---|
27 | |
---|
28 | #------------------------------------------------------------------------------ |
---|
29 | # Setup computational domain |
---|
30 | #------------------------------------------------------------------------------ |
---|
31 | name = 'island' |
---|
32 | mesh_filename = name + '.tsh' |
---|
33 | if True: |
---|
34 | #Create basic mesh |
---|
35 | create_mesh_from_regions( [[0,0], [100,0], [100,100], [0,100]], |
---|
36 | boundary_tags = {'bottom': [0], |
---|
37 | 'right': [1], |
---|
38 | 'top': [2], |
---|
39 | 'left': [3]}, |
---|
40 | maximum_triangle_area = 2, |
---|
41 | filename = mesh_filename, |
---|
42 | interior_regions=[ ([[50,25], [70,25], [70,75], [50,75]], 10.0)] |
---|
43 | #interior_holes=[[[50,25], [70,25], [70,75], [50,75]]], |
---|
44 | ) |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | # Select precomputed meshes here. In changeset:4725 there is a huge difference |
---|
51 | # in timestepping characteristics depending on the mesh used. |
---|
52 | # The mesh generated on windows takes 10 times as many timesteps. |
---|
53 | |
---|
54 | #Create shallow water domain |
---|
55 | domain = Domain(mesh_filename = mesh_filename) |
---|
56 | domain.smooth = False #True |
---|
57 | domain.set_name(name) |
---|
58 | #domain.set_name('island_not_unique') |
---|
59 | domain.default_order = 2 |
---|
60 | |
---|
61 | print domain.statistics() |
---|
62 | |
---|
63 | |
---|
64 | #--------------------------- |
---|
65 | # Combinations with less creep |
---|
66 | #--------------------------- |
---|
67 | |
---|
68 | domain.maximum_allowed_speed = 0 |
---|
69 | domain.tight_slope_limiters = True |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | #------------------------------------------------------------------------------ |
---|
74 | # Setup initial conditions |
---|
75 | #------------------------------------------------------------------------------ |
---|
76 | |
---|
77 | def island(x, y): |
---|
78 | z = 0*x |
---|
79 | for i in range(len(x)): |
---|
80 | z[i] = 20*exp( -((x[i]-50)**2 + (y[i]-50)**2)/100 ) |
---|
81 | |
---|
82 | #z[i] += 0.5*exp( -((x[i]-10)**2 + (y[i]-10)**2)/50 ) |
---|
83 | |
---|
84 | return z |
---|
85 | |
---|
86 | def slump(x, y): |
---|
87 | z = 0*x |
---|
88 | for i in range(len(x)): |
---|
89 | z[i] -= 0.7*exp( -((x[i]-10)**2 + (y[i]-10)**2)/200 ) |
---|
90 | |
---|
91 | return z |
---|
92 | |
---|
93 | stage_value = 10.0 |
---|
94 | #domain.set_quantity('friction', 0.1) #Honky dory |
---|
95 | domain.set_quantity('friction', 0.01) #Creep |
---|
96 | domain.set_quantity('elevation', island) |
---|
97 | domain.set_quantity('stage', stage_value) |
---|
98 | domain.max_timestep = 0.01 |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | #------------------------------------------------------------------------------ |
---|
103 | # Setup boundary conditions (all reflective) |
---|
104 | #------------------------------------------------------------------------------ |
---|
105 | |
---|
106 | Br = Reflective_boundary(domain) |
---|
107 | Bd = Dirichlet_boundary([stage_value, 0, 0]) |
---|
108 | |
---|
109 | domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd, 'exterior': Br}) |
---|
110 | domain.check_integrity() |
---|
111 | |
---|
112 | #------------------------------------------------------------------------------ |
---|
113 | # Evolve system through time |
---|
114 | #------------------------------------------------------------------------------ |
---|
115 | |
---|
116 | import time |
---|
117 | for t in domain.evolve(yieldstep = 1, finaltime = 25): |
---|
118 | domain.write_time() |
---|
119 | #if allclose(t, 100): |
---|
120 | # Q = domain.get_quantity('stage') |
---|
121 | # Q_s = Quantity(domain) |
---|
122 | # Q_s.set_values(slump) |
---|
123 | # domain.set_quantity('stage', Q + Q_s) |
---|
124 | #print ' Volume: ', domain.get_quantity('stage').get_integral() |
---|
125 | |
---|
126 | print 'Done' |
---|