source: anuga_core/source/anuga/examples/netherlands.py @ 3876

Last change on this file since 3876 was 3876, checked in by steve, 18 years ago

Added parameter alpha_balance to config.py to deal with large jumps in bed

File size: 5.3 KB
Line 
1"""Example of shallow water wave equation.
2
3This is called Netherlands because it shows a dam with a gap in it and
4stylised housed behind it and below the water surface.
5
6"""
7
8######################
9# Module imports
10#
11#import rpdb
12#rpdb.set_active()
13
14from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
15     Transmissive_boundary, Constant_height, Constant_stage
16
17from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
18from Numeric import array
19from anuga.visualiser.vtk_realtime_visualiser import Visualiser
20
21class Weir:
22    """Set a bathymetry for simple weir with a hole.
23    x,y are assumed to be in the unit square
24    """
25
26    def __init__(self, stage):
27        self.inflow_stage = stage
28
29    def __call__(self, x, y):
30        from Numeric import zeros, Float
31
32        N = len(x)
33        assert N == len(y)
34
35        z = zeros(N, Float)
36        for i in range(N):
37            z[i] = -x[i]/20  #General slope
38
39            #Flattish bit to the left
40            if x[i] <= 0.3:
41                #z[i] = -x[i]/5
42                z[i] = -x[i]/20
43
44
45            #Weir
46            if x[i] > 0.3 and x[i] < 0.4:
47                z[i] = -x[i]/20+1.2
48
49            #Dip
50            #if x[i] > 0.6 and x[i] < 0.9:
51            #    z[i] = -x[i]/20-0.5  #-y[i]/5
52
53            #Hole in weir
54            #if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.2 and y[i] < 0.4:
55            if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.4 and y[i] < 0.6:
56                #z[i] = -x[i]/5
57                z[i] = -x[i]/20
58
59            #Poles
60            #if x[i] > 0.65 and x[i] < 0.8 and y[i] > 0.55 and y[i] < 0.65 or\
61            #       x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45:
62            #    z[i] = -x[i]/20+0.4
63
64            if (x[i] - 0.72)**2 + (y[i] - 0.6)**2 < 0.05**2:# or\
65                   #x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45:
66                z[i] = -x[i]/20+0.4
67
68
69            #Wall
70            if x[i] > 0.995:
71                z[i] = -x[i]/20+0.3
72
73        return z/2
74
75
76
77######################
78# Domain
79#
80
81
82N = 150 #size = 45000
83N = 130 #size = 33800
84N = 600 #Size = 720000
85N = 40
86
87
88
89#N = 15
90
91print 'Creating domain'
92#Create basic mesh
93points, elements, boundary = rectangular_cross(N, N)
94
95#Create shallow water domain
96domain = Domain(points, elements, boundary, use_inscribed_circle=True)
97
98domain.check_integrity()
99
100#Setup order and all the beta's for the limiters (these should become defaults
101domain.default_order = 2
102domain.beta_w      = 1.0
103domain.beta_w_dry  = 0.2
104domain.beta_uh     = 1.0
105domain.beta_uh_dry = 0.2
106domain.beta_vh     = 1.0
107domain.beta_vh_dry = 0.2
108
109domain.alpha_balance = 10.0
110
111#Output params
112domain.smooth = False
113domain.reduction = min  #Looks a lot better on top of steep slopes
114
115print "Number of triangles = ", len(domain)
116print "Extent = ", domain.get_extent()
117
118#Set bed-slope and friction
119inflow_stage = 0.5
120manning = 0.03
121Z = Weir(inflow_stage)
122
123if N > 150:
124    domain.visualise = False
125    domain.checkpoint = False
126    domain.store = True    #Store for visualisation purposes
127    domain.format = 'sww'   #Native netcdf visualisation format
128    import sys, os
129    #FIXME: This was os.path.splitext but caused weird filenames based on root
130    base = os.path.basename(sys.argv[0])
131    basename, _ = os.path.splitext(base)
132    domain.set_name(basename)
133else:
134    #domain.initialise_visualiser(rect=[0.0,0.0,1.0,1.0])
135    #domain.initialise_visualiser()
136    #domain.visualiser.coloring['stage'] = False
137    domain.visualise_timer = True
138    domain.checkpoint = False
139    domain.store = False
140    vis = Visualiser(domain,title="netherlands")
141    vis.setup['elevation'] = True
142    vis.updating['stage'] = True
143    vis.qcolor['stage'] = (0.0,0.0,0.8)
144    vis.coloring['stage']= False
145
146
147
148print 'Field values'
149domain.set_quantity('elevation', Z)
150domain.set_quantity('friction', manning)
151
152
153######################
154# Boundary conditions
155#
156print 'Boundaries'
157Br = Reflective_boundary(domain)
158Bt = Transmissive_boundary(domain)
159
160#Constant inflow
161Bd = Dirichlet_boundary([inflow_stage, 0.0, 0.0])
162
163
164#Set boundary conditions
165domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br})
166
167
168######################
169#Initial condition
170#
171print 'Initial condition'
172domain.set_quantity('stage', expression='elevation + 0.0')
173
174#Evolve
175import time
176t0 = time.time()
177
178
179#from realtime_visualisation_new import Visualiser
180#V = Visualiser(domain,title='netherlands')
181#V.update_quantity('stage')
182#V.update_quantity('elevation')
183
184
185
186
187for t in domain.evolve(yieldstep = 0.005, finaltime = None):
188    domain.write_time()
189    #domain.write_boundary()
190    vis.update()
191    print domain.quantities['stage'].get_values(location='centroids',
192                                                indices=[0])
193    #domain.visualiser.update_quantity('elevation')
194    #time.sleep(0.1)
195    #raw_input('pause>')
196    #V.update_quantity('stage')
197    #rpdb.set_active()
198    #domain.visualiser.scale_z = 1.0
199    #domain.visualiser.update_quantity_color('xmomentum',scale_z = 4.0)
200    #integral_label.text='Integral=%10.5e'%domain.quantities['stage'].get_integral()
201
202
203print 'That took %.2f seconds' %(time.time()-t0)
204vis.shutdown()
Note: See TracBrowser for help on using the repository browser.