# source:anuga_core/documentation/user_manual/demos/channel3.py@7064

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

Fiddling with layout of user guide.

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