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

Last change on this file since 451 was 451, checked in by ole, 20 years ago

Good example using pyvolution mark 3

File size: 3.8 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#
11from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
12     Transmissive_boundary, Constant_height
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
65            #Wall
66            if x[i] > 0.995:
67                z[i] = -x[i]/20+0.3               
68
69        return z/2
70       
71   
72   
73######################
74# Domain
75#
76
77N = 250
78#N= 8
79N = 16
80#N = 4
81#N = 102
82N = 25
83N = 16
84N = 60
85N = 150 #size = 45000
86N = 130 #size = 33800
87#N = 60
88#N = 40
89N = 260
90#N = 150
91N = 264
92
93N = 600 #Size = 720000
94N = 20
95#N = 150
96N = 110
97#N = 60
98
99print 'Creating domain'
100#Create basic mesh
101points, vertices, boundary = rectangular(N, N)
102
103#Create shallow water domain
104domain = Domain(points, vertices, boundary)
105   
106domain.check_integrity()
107domain.default_order = 2
108
109#Output params
110domain.smooth = True
111domain.reduction = min  #Looks a lot better on top of steep slopes
112
113print "Number of triangles = ", len(domain)
114
115
116if N > 40:
117    domain.visualise = False
118    domain.checkpoint = False
119    domain.store = True    #Store for visualisation purposes
120    domain.format = 'sww'   #Native netcdf visualisation format
121    import sys, os
122    root, ext = os.path.splitext(sys.argv[0])
123    if domain.smooth is True:
124        s = 'smooth'
125    else:
126        s = 'nonsmooth'       
127    domain.filename = root + '_py3_' + s
128else:
129    domain.visualise = True
130    domain.checkpoint = False
131    domain.store = False   
132
133   
134#Set bed-slope and friction
135inflow_stage = 0.08
136manning = 0.02
137Z = Weir(inflow_stage)
138
139print 'Field values'
140domain.set_quantity('elevation', Z)
141domain.set_quantity('friction', manning)
142
143
144######################
145# Boundary conditions
146#
147print 'Boundaries'
148Br = Reflective_boundary(domain)
149Bt = Transmissive_boundary(domain)
150
151#Constant inflow
152Bd = Dirichlet_boundary([2*inflow_stage, 0.0, 0.0])
153
154
155#Set boundary conditions
156domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br})
157                 
158
159######################
160#Initial condition
161#
162print 'Initial condition'
163domain.set_quantity('level', Constant_height(Z, 0.))
164
165#Evolve
166import time
167t0 = time.time()
168
169for t in domain.evolve(yieldstep = 0.1, finaltime = 10.0):
170    domain.write_time()
171   
172print 'That took %.2f seconds' %(time.time()-t0)   
173   
Note: See TracBrowser for help on using the repository browser.