source: anuga_work/publications/demos/year9_siemens_science_demo.py @ 7613

Last change on this file since 7613 was 5721, checked in by ole, 17 years ago

Demo for Fiona to use with year9 siemens science students in October 2008

File size: 4.4 KB
Line 
1"""Simple water flow example using ANUGA
2
3Water flowing down a channel with more complex topography
4"""
5
6#------------------------------------------------------------------------------
7# Import necessary modules
8#------------------------------------------------------------------------------
9from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
10from anuga.shallow_water import Domain
11from anuga.shallow_water import Reflective_boundary
12from anuga.shallow_water import Dirichlet_boundary
13from anuga.shallow_water import Time_boundary
14
15from math import cos, sin, pi, sqrt
16
17#------------------------------------------------------------------------------
18# Setup computational domain
19#------------------------------------------------------------------------------
20length = 40.
21width = 5.
22#dx = dy = .05           # Resolution: Length of subdivisions on both axes
23dx = dy = .5           # Resolution: Length of subdivisions on both axes
24
25points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
26                                               len1=length, len2=width)
27domain = Domain(points, vertices, boundary)   
28domain.set_name('channel3')                  # Output name
29print domain.statistics()
30
31
32#------------------------------------------------------------------------------
33# Setup initial conditions
34#------------------------------------------------------------------------------
35def topography(x,y):
36    """Complex topography defined by a function of vectors x and y
37    """
38
39    # Geometric parameters
40    gradient = 0.02 
41    weir_height = 0.5
42    obstruction_height = 0.0
43    pole_height = 0.0
44
45    # Upward slope   
46    z = gradient*x
47
48    N = len(x)
49    for i in range(N):
50   
51        # Weir
52        if 10 < x[i] < 12:
53            z[i] += weir_height
54
55        # Obstruction
56        if 27 < x[i] < 29 and y[i] > 3:
57            z[i] += obstruction_height       
58       
59        # Pole
60        if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2:
61            z[i] += pole_height
62
63       
64
65
66
67    return z
68
69
70domain.set_quantity('elevation', topography)  # Use function for elevation
71domain.set_quantity('friction', 0.01)         # Constant friction
72domain.set_quantity('stage',
73                    expression='elevation')   # Dry initial condition
74
75
76#------------------------------------------------------------------------------
77# Setup boundary conditions
78#------------------------------------------------------------------------------
79Bi = Dirichlet_boundary([1.0, 0, 0])          # Inflow
80Br = Reflective_boundary(domain)              # Solid reflective wall
81Bo = Dirichlet_boundary([-1, 0, 0])           # Outflow
82
83def wave(t):
84
85    A = 1.5 # Amplitude [m] (Wave height)
86    T = 30  # Wave period [s]
87
88    if t < 120:
89        return [A*sin(2*pi*t/T) + 1, 0, 0] 
90    else:
91        return [0.0, 0, 0]
92
93Bt = Time_boundary(domain, f=wave)
94
95domain.set_boundary({'left': Bt, 'right': Bo, 'top': Br, 'bottom': Br})
96
97       
98
99#------------------------------------------------------------------------------
100# Evolve system through time
101#------------------------------------------------------------------------------
102
103washed_away = False
104
105for t in domain.evolve(yieldstep = 0.1, finaltime = 120.0):
106    print domain.timestepping_statistics()
107
108    S = domain.get_quantity('stage').get_values(interpolation_points=[[40, 2.5]])
109    E = domain.get_quantity('elevation').get_values(interpolation_points=[[40, 2.5]])
110   
111    depth = S-E
112
113    print '-------------'
114    print 'depth', depth
115    print '-------------'   
116   
117    #print 'elevation', E
118   
119    if depth > 1.63/3:
120
121        print 'Water level will sweep Fiona away',
122        if washed_away is True:
123            print ' - AGAIN!'
124        else:
125            print
126
127        if washed_away is False:
128
129            washaway_time = t
130            print 'Getting momentum'           
131            uh = domain.get_quantity('xmomentum').get_values(interpolation_points=[[40, 2.5]])
132            vh = domain.get_quantity('ymomentum').get_values(interpolation_points=[[40, 2.5]])
133
134            print 'Computing velocity'           
135            u = uh/depth
136            v = vh/depth
137            print 'velocity: (%f, %f' %(u,v)
138            washaway_velocity = sqrt(u*u + v*v)           
139            print 'done'
140           
141        washed_away = True
142        #raw_input('press key')
143
144if washed_away is True:
145    print 'Fiona got swept away at time = %.1f sec with a velocity of %.2f m/s'\
146          %(washaway_time, washaway_velocity)   
147   
Note: See TracBrowser for help on using the repository browser.