source: inundation/ga/storm_surge/pyvolution/netherlands.py @ 1453

Last change on this file since 1453 was 1404, checked in by steve, 20 years ago
File size: 4.1 KB
RevLine 
[1266]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#
11from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
[1387]12     Transmissive_boundary, Constant_height, Constant_stage
[1266]13
14from mesh_factory import rectangular
15from Numeric import array
16
17
18class Weir:
19    """Set a bathymetry for simple weir with a hole.
20    x,y are assumed to be in the unit square
21    """
22
23    def __init__(self, stage):
24        self.inflow_stage = stage
25
26    def __call__(self, x, y):
27        from Numeric import zeros, Float
28
29        N = len(x)
30        assert N == len(y)
31
32        z = zeros(N, Float)
33        for i in range(N):
34            z[i] = -x[i]/20  #General slope
35
36            #Flattish bit to the left
37            if x[i] <= 0.3:
38                #z[i] = -x[i]/5
39                z[i] = -x[i]/20
40
41
42            #Weir
43            if x[i] > 0.3 and x[i] < 0.4:
44                z[i] = -x[i]/20+1.2
45
46            #Dip
47            #if x[i] > 0.6 and x[i] < 0.9:
48            #    z[i] = -x[i]/20-0.5  #-y[i]/5
49
50            #Hole in weir
51            #if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.2 and y[i] < 0.4:
52            if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.4 and y[i] < 0.6:
53                #z[i] = -x[i]/5
54                z[i] = -x[i]/20
55
56            #Poles
57            #if x[i] > 0.65 and x[i] < 0.8 and y[i] > 0.55 and y[i] < 0.65 or\
58            #       x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45:
59            #    z[i] = -x[i]/20+0.4
60
61            if (x[i] - 0.72)**2 + (y[i] - 0.6)**2 < 0.05**2:# or\
62                   #x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45:
63                z[i] = -x[i]/20+0.4
64
[1295]65
[1266]66            #Wall
[1393]67            if x[i] > 0.995:
68                z[i] = -x[i]/20+0.3
[1266]69
70        return z/2
71
72
73
74######################
75# Domain
76#
77
78
79N = 150 #size = 45000
80N = 130 #size = 33800
81N = 600 #Size = 720000
[1392]82N = 30
[1266]83
[1392]84
[1266]85#N = 15
86
87print 'Creating domain'
88#Create basic mesh
[1392]89points, vertices, boundary = rectangular(N, N)
[1266]90
91#Create shallow water domain
[1360]92domain = Domain(points, vertices, boundary, use_inscribed_circle=True)
[1266]93
94domain.check_integrity()
95domain.default_order = 2
96#domain.beta_h=0
97
98#Output params
99domain.smooth = False
100domain.reduction = min  #Looks a lot better on top of steep slopes
101
102print "Number of triangles = ", len(domain)
103
[1295]104#Set bed-slope and friction
[1393]105inflow_stage = 0.1
106manning = 0.03
[1295]107Z = Weir(inflow_stage)
[1266]108
109if N > 150:
110    domain.visualise = False
111    domain.checkpoint = False
112    domain.store = True    #Store for visualisation purposes
113    domain.format = 'sww'   #Native netcdf visualisation format
114    import sys, os
115    #FIXME: This was os.path.splitext but caused weird filenames based on root
116    base = os.path.basename(sys.argv[0])
117    domain.filename, _ = os.path.splitext(base)
118else:
119    domain.visualise = True
[1360]120    domain.visualise_color_stage = False
[1295]121    domain.visualise_timer = True
[1266]122    domain.checkpoint = False
123    domain.store = False
124
125
[1360]126
[1266]127print 'Field values'
128domain.set_quantity('elevation', Z)
129domain.set_quantity('friction', manning)
130
131
132######################
133# Boundary conditions
134#
135print 'Boundaries'
136Br = Reflective_boundary(domain)
137Bt = Transmissive_boundary(domain)
138
139#Constant inflow
[1295]140Bd = Dirichlet_boundary([inflow_stage, 0.0, 0.0])
[1266]141
142
143#Set boundary conditions
144domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br})
145
146
147######################
148#Initial condition
149#
150print 'Initial condition'
[1387]151domain.set_quantity('stage', Constant_height(Z, 0.0))
152#domain.set_quantity('stage', Constant_stage(-1.0))
[1266]153
154#Evolve
155import time
156t0 = time.time()
157
[1393]158
159for t in domain.evolve(yieldstep = 0.1, finaltime = 15.0):
[1266]160    domain.write_time()
[1387]161    #domain.visualiser.scale_z = 1.0
[1393]162    #domain.visualiser.update_quantity_color('xmomentum',scale_z = 4.0)
163    #integral_label.text='Integral=%10.5e'%domain.quantities['stage'].get_integral()
[1266]164
165
166print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracBrowser for help on using the repository browser.