source: trunk/anuga_core/documentation/user_manual/demos/channel2.py @ 7806

Last change on this file since 7806 was 7806, checked in by hudson, 13 years ago

Channel examples run with new API.

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