source: trunk/anuga_core/demos/channel3.py @ 8966

Last change on this file since 8966 was 8728, checked in by steve, 12 years ago

Adding in usermanual and demos

File size: 2.6 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#------------------------------------------------------------------------------
9import anuga
10
11#------------------------------------------------------------------------------
12# Setup computational domain
13#------------------------------------------------------------------------------
14length = 40.
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)
20domain = anuga.Domain(points, vertices, boundary)
21domain.set_name('channel3')                  # Output name
22print domain.statistics()
23
24#------------------------------------------------------------------------------
25# Setup initial conditions
26#------------------------------------------------------------------------------
27def topography(x,y):
28    """Complex topography defined by a function of vectors x and y."""
29
30    z = -x/10
31
32    N = len(x)
33    for i in range(N):
34        # Step
35        if 10 < x[i] < 12:
36            z[i] += 0.4 - 0.05*y[i]
37
38        # Constriction
39        if 27 < x[i] < 29 and y[i] > 3:
40            z[i] += 2
41
42        # Pole
43        if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2:
44            z[i] += 2
45
46    return z
47
48domain.set_quantity('elevation', topography)           # elevation is a function
49domain.set_quantity('friction', 0.01)                  # Constant friction
50domain.set_quantity('stage', expression='elevation')   # Dry initial condition
51
52#------------------------------------------------------------------------------
53# Setup boundary conditions
54#------------------------------------------------------------------------------
55Bi = anuga.Dirichlet_boundary([0.4, 0, 0])          # Inflow
56Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
57Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
58
59domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})
60
61#------------------------------------------------------------------------------
62# Evolve system through time
63#------------------------------------------------------------------------------
64for t in domain.evolve(yieldstep=0.1, finaltime=16.0):
65    print domain.timestepping_statistics()
66
67    if domain.get_quantity('stage').\
68           get_values(interpolation_points=[[10, 2.5]]) > 0:
69        print 'Stage > 0: Changing to outflow boundary'
70        domain.set_boundary({'right': Bo})
71       
Note: See TracBrowser for help on using the repository browser.