source: trunk/anuga_work/development/Rudy_vandrie_2007/kitchen_sink_1.py @ 7924

Last change on this file since 7924 was 4440, checked in by ole, 18 years ago

Examples prepared for Rudy

File size: 3.7 KB
Line 
1"""Example of shallow water wave equation.
2
3Specific methods pertaining to the 2D shallow water equation
4are imported from shallow_water
5for use with the generic finite volume framework
6
7Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the
8numerical vector named conserved_quantities.
9"""
10
11#------------------------------------------------------------------------------
12# Import necessary modules
13#------------------------------------------------------------------------------
14from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular
15from anuga.shallow_water import Domain
16from anuga.shallow_water.shallow_water_domain import Reflective_boundary
17from anuga.shallow_water.shallow_water_domain import Dirichlet_boundary
18
19
20
21#from Numeric import array
22#from math import sin, pi
23
24#------------------------------------------------------------------------------
25# Setup computational domain
26#------------------------------------------------------------------------------
27
28#N = 120
29N = 40
30points, vertices, boundary = rectangular(N, N)
31domain = Domain(points, vertices, boundary)   
32domain.set_name('kitchen_sink')                 # Output name
33print 'Size', len(domain)
34
35
36#------------------------------------------------------------------------------
37# Setup initial conditions
38#------------------------------------------------------------------------------
39
40domain.set_quantity('elevation', 0.0)  # Zero bed elevation
41domain.set_quantity('stage', 0.015)    # Constant stage
42domain.set_quantity('friction', 0.005) # Constant friction
43
44
45#------------------------------------------------------------------------------
46# Setup specialised forcing terms
47#------------------------------------------------------------------------------
48   
49def tap(domain):
50    """Implement forcing function for "water tap" in the center
51    """
52   
53    flow = min(4*domain.get_time(), 5) # Turn tap up gradually
54    stage_update = domain.quantities['stage'].explicit_update
55
56    # Determine indices in tap area
57    if not hasattr(domain,'tap_indices'):
58        N = len(domain)   
59        domain.tap_indices = []
60        coordinates = domain.get_centroid_coordinates() 
61        for k in range(N):
62            x, y = coordinates[k,:] # Centroid
63            if ((x-0.5)**2+(y-0.5)**2) < 0.001:     
64                domain.tap_indices.append(k)   
65
66    # Update inflow
67    for k in domain.tap_indices:
68        stage_update[k] += flow                 
69
70
71def sink(domain):
72    """ Implement forcing function for "water sink"
73    """
74   
75    flow = min(2*domain.get_time(), 0.2) # Turn drain up gradually
76    stage_update = domain.quantities['stage'].explicit_update   
77
78    # Determine indices in sink area
79    if not hasattr(domain,'sink_indices'):
80        N = len(domain)   
81        domain.sink_indices = []
82        coordinates = domain.get_centroid_coordinates() 
83        for k in range(N):
84            x, y = coordinates[k,:] # Centroid
85            if ((x-0.7)**2+(y-0.4)**2) < 0.005:     
86                domain.sink_indices.append(k)   
87               
88    # Update outflow
89    for k in domain.sink_indices:
90        stage_update[k] -= flow                 
91
92domain.forcing_terms.append(tap)
93domain.forcing_terms.append(sink)
94
95#------------------------------------------------------------------------------
96# Setup boundary conditions
97#------------------------------------------------------------------------------
98
99Br = Reflective_boundary(domain)              # Solid reflective wall
100domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
101
102#------------------------------------------------------------------------------
103# Evolve system through time
104#------------------------------------------------------------------------------
105for t in domain.evolve(yieldstep = 0.01, finaltime = 14):
106    domain.write_time()
107   
108   
Note: See TracBrowser for help on using the repository browser.