1 | import os |
---|
2 | import random |
---|
3 | from math import sqrt, pow, pi |
---|
4 | from channel_domain import * |
---|
5 | from numpy import allclose, array, zeros, ones, take, sqrt |
---|
6 | from anuga_1d.config import g, epsilon |
---|
7 | |
---|
8 | |
---|
9 | print "Variable Width Only Test" |
---|
10 | |
---|
11 | # Define functions for initial quantities |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | #def initial_area(x): |
---|
16 | # y = zeros(len(x),'f') |
---|
17 | # for i in range(len(x)): |
---|
18 | # y[i]=(10-randomarray[i]) |
---|
19 | # return y |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | def bed(x): |
---|
24 | |
---|
25 | y = zeros(len(x),'f') |
---|
26 | for i in range(len(x)): |
---|
27 | y[i]=randomarray[i] |
---|
28 | randomarray[i]=random.normalvariate(3,1) |
---|
29 | return y |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | def width(x): |
---|
36 | y = zeros(len(x),'f') |
---|
37 | return y+1 |
---|
38 | |
---|
39 | |
---|
40 | stage = 6.0 |
---|
41 | |
---|
42 | def initial_area(x): |
---|
43 | |
---|
44 | a_bed = bed(x) |
---|
45 | a_width = width(x) |
---|
46 | |
---|
47 | a_height = 6.0 - a_bed |
---|
48 | |
---|
49 | y = a_height*a_width |
---|
50 | |
---|
51 | return y |
---|
52 | |
---|
53 | |
---|
54 | import time |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | # Length of channel (m) |
---|
59 | L = 1000.0 |
---|
60 | # Define the number of cells |
---|
61 | number_of_cells = [50] |
---|
62 | |
---|
63 | # Define cells for finite volume and their size |
---|
64 | N = int(number_of_cells[0]) |
---|
65 | print "Evaluating domain with %d cells" %N |
---|
66 | cell_len = L/N # Origin = 0.0 |
---|
67 | points = zeros(N+1,'f') |
---|
68 | |
---|
69 | # Define the centroid points |
---|
70 | for j in range(N+1): |
---|
71 | points[j] = j*cell_len |
---|
72 | |
---|
73 | # Create domain with centroid points as defined above |
---|
74 | domain = Domain(points) |
---|
75 | |
---|
76 | # Define random array for width |
---|
77 | |
---|
78 | randomarray=zeros(len(points),'f') |
---|
79 | for j in range(N+1): |
---|
80 | randomarray[j]=random.normalvariate(3,1) |
---|
81 | |
---|
82 | |
---|
83 | # Set initial values of quantities - default to zero |
---|
84 | #domain.set_quantity('stage',6.0) |
---|
85 | domain.set_quantity('elevation',bed, location='centroids') |
---|
86 | domain.set_quantity('width',width, location='centroids') |
---|
87 | domain.set_quantity('area', initial_area, location='centroids') |
---|
88 | |
---|
89 | |
---|
90 | #domain.setstageflag = True |
---|
91 | # Set boundry type, order, timestepping method and limiter |
---|
92 | domain.set_boundary({'exterior':Reflective_boundary(domain)}) |
---|
93 | domain.order = 2 |
---|
94 | domain.set_timestepping_method('rk2') |
---|
95 | domain.set_CFL(1.0) |
---|
96 | domain.set_limiter("vanleer") |
---|
97 | #domain.h0=0.0001 |
---|
98 | |
---|
99 | |
---|
100 | #domain.distribute_to_vertices_and_edges() |
---|
101 | |
---|
102 | |
---|
103 | AreaC = domain.quantities['area'].centroid_values |
---|
104 | BedC = domain.quantities['elevation'].centroid_values |
---|
105 | WidthC = domain.quantities['width'].centroid_values |
---|
106 | # |
---|
107 | AreaC[:] = (8.0 - BedC)* WidthC |
---|
108 | |
---|
109 | #domain.set_quantity('area', initial_area) |
---|
110 | |
---|
111 | #domain.distribute_to_vertices_and_edges() |
---|
112 | |
---|
113 | # Start timer |
---|
114 | t0 = time.time() |
---|
115 | i=0 |
---|
116 | |
---|
117 | print 'elevation vertex values' |
---|
118 | print domain.quantities['elevation'].vertex_values |
---|
119 | print 'stage vertex values' |
---|
120 | print domain.quantities['stage'].vertex_values |
---|
121 | print 'area vertex values' |
---|
122 | print domain.quantities['area'].vertex_values |
---|
123 | print 'width vertex values' |
---|
124 | print domain.quantities['width'].vertex_values |
---|
125 | |
---|
126 | |
---|
127 | domain.distribute_to_vertices_and_edges() |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | # Set final time and yield time for simulation |
---|
132 | finaltime = 100.0 |
---|
133 | yieldstep = 1.0 |
---|
134 | |
---|
135 | domain.initialize_plotting(stage_lim = [-2.0, 12.0], |
---|
136 | width_lim = [0.0, 2.0], |
---|
137 | velocity_lim = [-10.0, 10.0]) |
---|
138 | |
---|
139 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
140 | domain.write_time() |
---|
141 | |
---|
142 | domain.update_plotting() |
---|
143 | |
---|
144 | |
---|
145 | print domain.quantities['elevation'].vertex_values |
---|
146 | |
---|
147 | domain.hold_plotting(save="not_well_balanced_random_depth") |
---|
148 | |
---|
149 | |
---|