source: anuga_core/documentation/user_manual/demos/channel_variable.py @ 7346

Last change on this file since 7346 was 7346, checked in by ole, 15 years ago

Verified that variable elevation can be stored as a time dependent quantity.
Also, ensured backwards compatibility with old viewer.

File size: 4.1 KB
Line 
1"""Simple water flow example using ANUGA
2
3Water flowing down a channel with a topography that varies with time
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 #.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('channel_variable')                  # Output name
26print domain.statistics()
27domain.set_quantities_to_be_stored({'elevation': 1, #2,
28                                    'stage': 2})
29
30#------------------------------------------------------------------------------
31# Setup initial conditions
32#------------------------------------------------------------------------------
33def topography(x,y):
34    """Complex topography defined by a function of vectors x and y."""
35
36    z = -x/100
37
38    N = len(x)
39    for i in range(N):
40        # Step
41        if 10 < x[i] < 12:
42            z[i] += 0.4 - 0.05*y[i]
43
44        # Constriction
45        #if 27 < x[i] < 29 and y[i] > 3:
46        #    z[i] += 2
47
48        # Pole
49        #if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2:
50        #    z[i] += 2
51
52    return z
53
54def pole_increment(x,y):
55    """This provides a small increment to a pole located mid stream
56    For use with variable elevation data
57    """
58   
59    z = 0.0*x
60
61    N = len(x)
62    for i in range(N):
63        # Pole
64        if (x[i] - 20)**2 + (y[i] - 2)**2 < 0.4**2:
65            z[i] += 0.05
66    return z
67   
68   
69domain.set_quantity('elevation', topography)           # elevation is a function
70domain.set_quantity('friction', 0.01)                  # Constant friction
71domain.set_quantity('stage', expression='elevation')   # Dry initial condition
72
73#------------------------------------------------------------------------------
74# Setup boundary conditions
75#------------------------------------------------------------------------------
76Bi = Dirichlet_boundary([0.4, 0, 0])          # Inflow
77Br = Reflective_boundary(domain)              # Solid reflective wall
78Bo = Dirichlet_boundary([-5, 0, 0])           # Outflow
79
80domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})
81
82#------------------------------------------------------------------------------
83# Evolve system through time
84#------------------------------------------------------------------------------
85
86growing = False
87shrinking = False
88done = False
89for t in domain.evolve(yieldstep=0.1, finaltime=30.0):
90    print domain.timestepping_statistics()
91
92    #w = domain.get_quantity('stage').\
93    #    get_values(interpolation_points=[[18, 2.5]])
94    #print 'Level at gauge point = %.2fm' % w
95           
96    z = domain.get_quantity('elevation').\
97        get_values(interpolation_points=[[20, 2]])           
98    print 'Elevation at pole location = %.2fm' % z           
99
100    # Start variable elevation after 10 seconds   
101    if t > 10 and not (shrinking or growing or done):
102        growing = True
103           
104    # Turn around when pole has reached a height of 2 m
105    if z >= 2 and growing:
106        growing = False
107        shrinking = True
108       
109    # Stop changing when pole has shrunk to 1 m
110    if z <= 1 and shrinking:
111        done = True
112        shrinking = growing = False
113
114    # Grow or shrink               
115    if growing:       
116        domain.add_quantity('elevation', pole_increment)
117       
118    if shrinking:   
119        domain.add_quantity('elevation', lambda x,y: -pole_increment(x,y))   
120       
Note: See TracBrowser for help on using the repository browser.