source: trunk/anuga_1d_core/channel/circular_test.py @ 9737

Last change on this file since 9737 was 9098, checked in by steve, 11 years ago

Moved the channel code over from development

File size: 4.9 KB
Line 
1import os
2import random
3from math import sqrt, pow, pi
4from channel_domain import *
5from numpy import allclose, array, zeros, ones, take, sqrt
6from anuga_1d.config import g, epsilon
7
8from anuga_1d.base.generic_mesh import uniform_mesh
9
10
11print "varying width to mimic rotationally symmetric dam break"
12
13# Define functions for initial quantities
14
15
16
17def initialize_plotting(domain, style = '-k',
18                        stage_lim = [-1.0, 40.0],
19                        velocity_lim = [-5.0, 5.0]):
20
21    import pylab
22    pylab.ion()
23
24
25    x = domain.get_vertices().flatten()
26
27    z = domain.quantities['elevation'].vertex_values.flatten()
28    w = domain.quantities['stage'].vertex_values.flatten()
29    h = domain.quantities['height'].vertex_values.flatten()
30    v = domain.quantities['velocity'].vertex_values.flatten()
31    b = domain.quantities['width'].vertex_values.flatten()
32
33    print x.shape
34    print z.shape
35
36    #-------------------------------
37    # Top plot
38    #-------------------------------
39    domain.plot1 = pylab.subplot(211)
40
41    domain.zplot, = pylab.plot(x, z)
42    domain.wplot, = pylab.plot(x, w, style)
43
44    domain.plot1.set_ylim(stage_lim)
45    #pylab.xlabel('Position')
46    pylab.ylabel('Stage')
47
48
49    #-------------------------------
50    # Bottom Plot
51    #-------------------------------
52    domain.plot3 = pylab.subplot(212)
53
54    domain.vplot, = pylab.plot(x, v, style)
55
56    domain.plot3.set_ylim(velocity_lim)
57
58    pylab.xlabel('Position')
59    pylab.ylabel('Velocity')
60
61
62def update_plotting(domain):
63
64    import pylab
65
66    #x = domain.get_vertices().flatten()
67    z = domain.quantities['elevation'].vertex_values.flatten()
68    w = domain.quantities['stage'].vertex_values.flatten()
69    h = domain.quantities['height'].vertex_values.flatten()
70    v = domain.quantities['velocity'].vertex_values.flatten()
71    b = domain.quantities['width'].vertex_values.flatten()
72
73
74    domain.zplot.set_ydata(z)
75    domain.wplot.set_ydata(w)
76    #domain.bplot.set_ydata(b)
77    domain.vplot.set_ydata(v)
78
79    pylab.draw()
80
81
82def hold_plotting(domain,save=None):
83
84    update_plotting(domain)
85    import pylab
86
87    pylab.ioff()
88
89    if save != None:
90        file = save+".pdf"
91        pylab.savefig(file)
92
93    pylab.show()
94
95
96
97def finalize_plotting(domain):
98
99    pass
100
101
102
103
104
105def bed(x):
106    y = zeros(len(x),'f')
107    return y
108
109
110def width(x):
111   
112    return x*2.0*pi
113
114
115
116def initial_area(x):
117
118    a_width = width(x)
119
120    y = numpy.where (x <= 50.0,  15.0*a_width, 2.0*a_width )
121
122    return y
123
124
125import time
126
127
128# Define cells for finite volume and their size
129N = 100
130
131domain = Domain(*uniform_mesh(N, x_0 = 0.0, x_1 = 100.0))
132
133
134# Set initial values of quantities - default to zero
135#domain.set_quantity('stage',6.0)
136domain.set_quantity('elevation',bed)
137domain.set_quantity('width',width)
138domain.set_quantity('area', initial_area)
139
140
141#domain.setstageflag = True
142# Set boundry type, order, timestepping method and limiter
143Br = Reflective_boundary(domain)
144domain.set_boundary({'left':Br, 'right':Br})
145domain.order = 2
146domain.set_timestepping_method('rk2')
147domain.set_CFL(1.0)
148domain.set_limiter("vanleer")
149
150
151#AreaC = domain.quantities['area'].centroid_values
152#BedC = domain.quantities['elevation'].centroid_values
153#WidthC = domain.quantities['width'].centroid_values
154##
155#AreaC[:] = (8.0 - BedC)* WidthC
156
157
158# Start timer
159t0 = time.time()
160i=0
161
162#print 'elevation vertex values'
163#print domain.quantities['elevation'].vertex_values
164#print 'stage vertex values'
165#print domain.quantities['stage'].vertex_values
166#print 'area vertex values'
167#print domain.quantities['area'].vertex_values
168#print 'width vertex values'
169#print domain.quantities['width'].vertex_values
170
171
172domain.distribute_to_vertices_and_edges()
173
174
175
176# Set final time and yield time for simulation
177finaltime = 2.0
178yieldstep = 0.2
179
180initialize_plotting(domain, style = '.k', stage_lim = [0.0, 16.0],
181                            velocity_lim = [-10.0, 10.0])
182
183for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
184    domain.write_time()
185
186    update_plotting(domain)
187
188#-------------------------------------------------------------
189# Fine grid solution
190#-------------------------------------------------------------
191
192domain1 = Domain(*uniform_mesh(1000, x_0 = 0.0, x_1 = 100.0))
193
194
195# Set initial values of quantities - default to zero
196#domain.set_quantity('stage',6.0)
197domain1.set_quantity('elevation',bed)
198domain1.set_quantity('width',width)
199domain1.set_quantity('area', initial_area)
200
201
202#domain.setstageflag = True
203# Set boundry type, order, timestepping method and limiter
204Br = Reflective_boundary(domain1)
205domain1.set_boundary({'left':Br, 'right':Br})
206domain1.order = 2
207domain1.set_timestepping_method('rk2')
208domain1.set_CFL(1.0)
209domain1.set_limiter("vanleer")
210
211finaltime = 2.0
212yieldstep = finaltime
213
214initialize_plotting(domain1, stage_lim = [0.0, 16.0],
215                            velocity_lim = [-10.0, 10.0])
216
217for t in domain1.evolve(yieldstep = yieldstep, finaltime = finaltime):
218    domain1.write_time()
219
220    update_plotting(domain1)
221
222
223hold_plotting(domain1, save="circular_dam_break_well_balanced")
224
225
226
227
Note: See TracBrowser for help on using the repository browser.