source: anuga_core/documentation/user_manual/demos/channel2.py @ 7064

Last change on this file since 7064 was 7064, checked in by rwilson, 15 years ago

Fiddling with layout of user guide.

File size: 2.5 KB
Line 
1"""Simple water flow example using ANUGA
2
3Water flowing down a channel with changing boundary conditions
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
15#------------------------------------------------------------------------------
16# Setup computational domain
17#------------------------------------------------------------------------------
18length = 10.
19width = 5.
20dx = dy = 1           # Resolution: Length of subdivisions on both axes
21
22points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
23                                               len1=length, len2=width)
24domain = Domain(points, vertices, boundary)   
25domain.set_name('channel2')                 # Output name
26
27#------------------------------------------------------------------------------
28# Setup initial conditions
29#------------------------------------------------------------------------------
30def topography(x,y):
31    return -x/10                             # linear bed slope
32
33domain.set_quantity('elevation', topography) # Use function for elevation
34domain.set_quantity('friction', 0.01)        # Constant friction
35domain.set_quantity('stage',
36                    expression='elevation')  # Dry initial condition
37
38#------------------------------------------------------------------------------
39# Setup boundary conditions
40#------------------------------------------------------------------------------
41Bi = Dirichlet_boundary([0.4, 0, 0])         # Inflow
42Br = Reflective_boundary(domain)             # Solid reflective wall
43Bo = Dirichlet_boundary([-5, 0, 0])          # Outflow
44
45domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
46
47#------------------------------------------------------------------------------
48# Evolve system through time
49#------------------------------------------------------------------------------
50for t in domain.evolve(yieldstep=0.2, finaltime=40.0):
51    print domain.timestepping_statistics()
52
53    if domain.get_quantity('stage').\
54           get_values(interpolation_points=[[10, 2.5]]) > 0:       
55        print 'Stage > 0: Changing to outflow boundary'
56        domain.set_boundary({'right': Bo})
Note: See TracBrowser for help on using the repository browser.