source: anuga_core/source/anuga/examples/channel_2.py @ 3740

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

Channel examples (developed at SUT, September 2006)

File size: 3.0 KB
Line 
1"""Simple water flow example using ANUGA
2
3Water flowing down a channel
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#------------------------------------------------------------------------------
17# Setup computational domain
18#------------------------------------------------------------------------------
19length = 10.
20width = 5.
21dx = dy = 1           # Resolution: Length of subdivisions on both axes
22
23points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width)
24domain = Domain(points, vertices, boundary)   
25domain.set_name('channel_2')                  # Output name
26
27
28#------------------------------------------------------------------------------
29# Setup initial conditions
30#------------------------------------------------------------------------------
31def topography(x,y):
32    return -x/10                             # linear bed slope
33
34domain.set_quantity('elevation', topography)            # Use function for elevation
35domain.set_quantity('friction', 0.01)                   # Constant friction
36domain.set_quantity('stage', expression='elevation')    # Dry
37
38
39#------------------------------------------------------------------------------
40# Setup boundary conditions
41#------------------------------------------------------------------------------
42Bi = Dirichlet_boundary([0.4, 0, 0])                            # Inflow
43Br = Reflective_boundary(domain)                                # Solid reflective wall
44Bo = Dirichlet_boundary([-5, 0, 0])                             # Outflow
45
46domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
47
48
49#------------------------------------------------------------------------------
50# Evolve system through time
51#------------------------------------------------------------------------------
52for t in domain.evolve(yieldstep = 0.2, finaltime = 40.0):
53    domain.write_time()
54
55    #print 'Stage(10,2.5) = ', domain.get_quantity('stage').get_values(interpolation_points=[[10, 2.5]])
56   
57    from Numeric import allclose
58    #if allclose(t, 20):
59    if domain.get_quantity('stage').get_values(interpolation_points=[[10, 2.5]]) > 0:       
60        print 'Stage > 0: Changing boundary'
61        domain.modify_boundary({'right': Bo})
62
63
64import sys; sys.exit() 
65
66import time
67t0 = time.time()
68
69
70s = 'for t in domain.evolve(yieldstep = 0.2, finaltime = 40.0): domain.write_time(); domain.get_quantity("stage").get_values(interpolation_points=[[10, 2.5]])'
71
72import profile, pstats
73FN = 'profile.dat'
74
75profile.run(s, FN)
76
77print 'That took %.2f seconds' %(time.time()-t0)
78
79S = pstats.Stats(FN)
80#S.sort_stats('time').print_stats(20)
81s = S.sort_stats('cumulative').print_stats(30)
82
83print s
84
Note: See TracBrowser for help on using the repository browser.