1 | """Example of shallow water wave equation analytical solution |
---|
2 | consists of a symmetrical converging frictionless channel. |
---|
3 | |
---|
4 | Specific methods pertaining to the 2D shallow water equation |
---|
5 | are imported from shallow_water |
---|
6 | for use with the generic finite volume framework |
---|
7 | |
---|
8 | Copyright 2005 |
---|
9 | Christopher Zoppou, Stephen Roberts |
---|
10 | ANU |
---|
11 | |
---|
12 | Specific methods pertaining to the 2D shallow water equation |
---|
13 | are imported from shallow_water |
---|
14 | for use with the generic finite volume framework |
---|
15 | |
---|
16 | Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the |
---|
17 | numerical vector named conserved_quantities. |
---|
18 | """ |
---|
19 | |
---|
20 | #--------------- |
---|
21 | # Module imports |
---|
22 | from anuga.shallow_water import Transmissive_boundary, Reflective_boundary, \ |
---|
23 | Dirichlet_boundary |
---|
24 | from anuga.shallow_water import Domain |
---|
25 | from pmesh2domain import pmesh_to_domain_instance |
---|
26 | from mesh_factory import contracting_channel_cross |
---|
27 | |
---|
28 | #------- |
---|
29 | # Domain from a file |
---|
30 | # filename = 'converging_channel_30846.tsh' |
---|
31 | # print 'Creating domain from', filename |
---|
32 | # domain = pmesh_to_domain_instance(filename, Domain) |
---|
33 | |
---|
34 | ###################### |
---|
35 | # Domain created within python |
---|
36 | # |
---|
37 | Total_length = 50 |
---|
38 | W_upstream = 5. |
---|
39 | W_downstream = 2.5 |
---|
40 | L_1 = 5. |
---|
41 | L_2 = 11 |
---|
42 | L_3 = Total_length - L_1 - L_2 |
---|
43 | n = 5 |
---|
44 | m = 50 |
---|
45 | |
---|
46 | points, elements, boundary = \ |
---|
47 | contracting_channel_cross(m, n, W_upstream, W_downstream, L_1, L_2, L_3) |
---|
48 | domain = Domain(points, elements, boundary) |
---|
49 | |
---|
50 | |
---|
51 | print 'Number of triangles = ', len(domain) |
---|
52 | |
---|
53 | #---------------- |
---|
54 | # Order of scheme |
---|
55 | domain.default_order = 2 |
---|
56 | domain.smooth = True |
---|
57 | |
---|
58 | #------------------------------------- |
---|
59 | # Provide file name for storing output |
---|
60 | domain.store = True #Store for visualisation purposes |
---|
61 | domain.format = 'sww' #Native netcdf visualisation format |
---|
62 | domain.set_name('contracting_channel_second-order') |
---|
63 | |
---|
64 | |
---|
65 | #---------------------------------------------------------- |
---|
66 | # Decide which quantities are to be stored at each timestep |
---|
67 | domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
68 | |
---|
69 | #------------------------------------------------ |
---|
70 | # This is for Visual Python |
---|
71 | domain.visualise = True |
---|
72 | |
---|
73 | #------------------------------------------ |
---|
74 | # Reduction operation for get_vertex_values |
---|
75 | #from anuga.pyvolution.util import mean |
---|
76 | #domain.reduction = mean |
---|
77 | |
---|
78 | #------------------------ |
---|
79 | # Set boundary Conditions |
---|
80 | tags = {} |
---|
81 | tags['left'] = Dirichlet_boundary([0.2, 1.2, 0.0]) |
---|
82 | tags['top'] = Reflective_boundary(domain) |
---|
83 | tags['bottom'] = Reflective_boundary(domain) |
---|
84 | tags['right'] = Transmissive_boundary(domain) |
---|
85 | domain.set_boundary(tags) |
---|
86 | |
---|
87 | #---------------------- |
---|
88 | # Set initial condition |
---|
89 | domain.set_quantity('elevation', 0.0) |
---|
90 | domain.set_quantity('stage', 0.2) |
---|
91 | |
---|
92 | # Use the inscribed circle with safety factor of 0.9 to establish the time step |
---|
93 | # domain.set_to_inscribed_circle(safety_factor=0.9) |
---|
94 | |
---|
95 | #---------- |
---|
96 | # Evolution |
---|
97 | import time |
---|
98 | t0 = time.time() |
---|
99 | for t in domain.evolve(yieldstep = 5.0, finaltime = 50.0): |
---|
100 | domain.write_time() |
---|
101 | |
---|
102 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
103 | |
---|
104 | N = domain.number_of_elements |
---|
105 | |
---|
106 | Stage = domain.quantities['stage'] |
---|
107 | stage = Stage.centroid_values |
---|
108 | XY = domain.centroid_coordinates |
---|
109 | |
---|
110 | # Calculate average |
---|
111 | average_stage = 0.0 |
---|
112 | n_points = 0 |
---|
113 | for n in range(N): |
---|
114 | if XY[n,0] > 35.0: |
---|
115 | average_stage = average_stage + stage[n] |
---|
116 | n_points = n_points + 1 |
---|
117 | |
---|
118 | average_stage = average_stage/n_points |
---|
119 | |
---|
120 | #Standard Deviation |
---|
121 | sigma = 0.0 |
---|
122 | max_stage = -999999. |
---|
123 | min_stage = 999999 |
---|
124 | for n in range(N): |
---|
125 | if XY[n,0] > 35.0: |
---|
126 | sigma = sigma + (average_stage - stage[n])**2 |
---|
127 | if stage[n] > max_stage: |
---|
128 | max_stage = stage[n] |
---|
129 | if stage[n] < min_stage: |
---|
130 | min_stage = stage[n] |
---|
131 | |
---|
132 | import math |
---|
133 | sigma = math.sqrt(sigma/(n_points-1)) |
---|
134 | |
---|
135 | print L_2, average_stage, sigma, max_stage, min_stage, n_points |
---|
136 | |
---|
137 | domain.initialise_visualiser() |
---|
138 | domain.visualiser.update_all() |
---|