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 | import sys |
---|
23 | from os import sep |
---|
24 | sys.path.append('..'+sep+'pyvolution') |
---|
25 | |
---|
26 | from shallow_water import Transmissive_boundary, Reflective_boundary, \ |
---|
27 | Dirichlet_boundary |
---|
28 | from shallow_water import Constant_height, Domain |
---|
29 | from pmesh2domain import pmesh_to_domain_instance |
---|
30 | from mesh_factory import contracting_channel_cross |
---|
31 | |
---|
32 | #------- |
---|
33 | # Domain from a file |
---|
34 | # filename = 'converging_channel_30846.tsh' |
---|
35 | # print 'Creating domain from', filename |
---|
36 | # domain = pmesh_to_domain_instance(filename, Domain) |
---|
37 | |
---|
38 | ###################### |
---|
39 | # Domain created within python |
---|
40 | # |
---|
41 | Total_length = 50 |
---|
42 | W_upstream = 5. |
---|
43 | W_downstream = 2.5 |
---|
44 | L_1 = 5. |
---|
45 | L_2 = 11 |
---|
46 | L_3 = Total_length - L_1 - L_2 |
---|
47 | n = 5 |
---|
48 | m = 50 |
---|
49 | |
---|
50 | points, elements, boundary = \ |
---|
51 | contracting_channel_cross(m, n, W_upstream, W_downstream, L_1, L_2, L_3) |
---|
52 | domain = Domain(points, elements, boundary) |
---|
53 | |
---|
54 | |
---|
55 | print 'Number of triangles = ', len(domain) |
---|
56 | |
---|
57 | #---------------- |
---|
58 | # Order of scheme |
---|
59 | domain.default_order = 2 |
---|
60 | domain.smooth = True |
---|
61 | |
---|
62 | #------------------------------------- |
---|
63 | # Provide file name for storing output |
---|
64 | domain.store = True #Store for visualisation purposes |
---|
65 | domain.format = 'sww' #Native netcdf visualisation format |
---|
66 | domain.filename = 'contracting_channel_second-order' |
---|
67 | |
---|
68 | |
---|
69 | #---------------------------------------------------------- |
---|
70 | # Decide which quantities are to be stored at each timestep |
---|
71 | domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
72 | |
---|
73 | #------------------------------------------------ |
---|
74 | # This is for Visual Python |
---|
75 | domain.visualise = True |
---|
76 | |
---|
77 | #------------------------------------------ |
---|
78 | # Reduction operation for get_vertex_values |
---|
79 | #from util import mean |
---|
80 | #domain.reduction = mean |
---|
81 | |
---|
82 | #------------------------ |
---|
83 | # Set boundary Conditions |
---|
84 | tags = {} |
---|
85 | tags['left'] = Dirichlet_boundary([0.2, 1.2, 0.0]) |
---|
86 | tags['top'] = Reflective_boundary(domain) |
---|
87 | tags['bottom'] = Reflective_boundary(domain) |
---|
88 | tags['right'] = Transmissive_boundary(domain) |
---|
89 | domain.set_boundary(tags) |
---|
90 | |
---|
91 | #---------------------- |
---|
92 | # Set initial condition |
---|
93 | domain.set_quantity('elevation', 0.0) |
---|
94 | domain.set_quantity('stage', 0.2) |
---|
95 | |
---|
96 | # Use the inscribed circle with safety factor of 0.9 to establish the time step |
---|
97 | # domain.set_to_inscribed_circle(safety_factor=0.9) |
---|
98 | |
---|
99 | #---------- |
---|
100 | # Evolution |
---|
101 | import time |
---|
102 | t0 = time.time() |
---|
103 | for t in domain.evolve(yieldstep = 5.0, finaltime = 50.0): |
---|
104 | domain.write_time() |
---|
105 | |
---|
106 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
107 | |
---|
108 | N = domain.number_of_elements |
---|
109 | |
---|
110 | Stage = domain.quantities['stage'] |
---|
111 | stage = Stage.centroid_values |
---|
112 | XY = domain.centroid_coordinates |
---|
113 | |
---|
114 | # Calculate average |
---|
115 | average_stage = 0.0 |
---|
116 | n_points = 0 |
---|
117 | for n in range(N): |
---|
118 | if XY[n,0] > 35.0: |
---|
119 | average_stage = average_stage + stage[n] |
---|
120 | n_points = n_points + 1 |
---|
121 | |
---|
122 | average_stage = average_stage/n_points |
---|
123 | |
---|
124 | #Standard Deviation |
---|
125 | sigma = 0.0 |
---|
126 | max_stage = -999999. |
---|
127 | min_stage = 999999 |
---|
128 | for n in range(N): |
---|
129 | if XY[n,0] > 35.0: |
---|
130 | sigma = sigma + (average_stage - stage[n])**2 |
---|
131 | if stage[n] > max_stage: |
---|
132 | max_stage = stage[n] |
---|
133 | if stage[n] < min_stage: |
---|
134 | min_stage = stage[n] |
---|
135 | |
---|
136 | import math |
---|
137 | sigma = math.sqrt(sigma/(n_points-1)) |
---|
138 | |
---|
139 | print L_2, average_stage, sigma, max_stage, min_stage, n_points |
---|
140 | |
---|
141 | domain.initialise_visualiser() |
---|
142 | domain.visualiser.update_all() |
---|