source: trunk/anuga_core/demos/channel3_parallel.py @ 9072

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

Adding in usermanual and demos

File size: 3.2 KB
RevLine 
[8728]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
11import anuga_parallel
12
13
14#------------------------------------------------------------------------------
15# Setup some initial info
16#------------------------------------------------------------------------------
17def topography(x,y):
18    """Complex topography defined by a function of vectors x and y."""
19
20    z = -x/10
21
22    N = len(x)
23    for i in range(N):
24        # Step
25        if 10 < x[i] < 12:
26            z[i] += 0.4 - 0.05*y[i]
27
28        # Constriction
29        if 27 < x[i] < 29 and y[i] > 3:
30            z[i] += 2
31
32        # Pole
33        if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2:
34            z[i] += 2
35
36    return z
37
38
39
40#------------------------------------------------------------------------------
41# Setup computational domain on one processor
42#------------------------------------------------------------------------------
43length = 40.
44width = 5.
45dx = dy = .1           # Resolution: Length of subdivisions on both axes
46
47
48if anuga_parallel.myid == 0:
49    points, vertices, boundary = anuga.rectangular_cross(int(length/dx),
50                                         int(width/dy), len1=length, len2=width)
51    domain = anuga.Domain(points, vertices, boundary)
52    domain.set_name('channel3')                  # Output name
53    print domain.statistics()
54
55
56   
57    domain.set_quantity('elevation', topography)           # elevation is a function
58    domain.set_quantity('friction', 0.01)                  # Constant friction
59    domain.set_quantity('stage', expression='elevation')   # Dry initial condition
60else:
61    domain = None
62
63#------------------------------------------------------------------------------
64# Distribute domain on processor 0 to to other processors
65#------------------------------------------------------------------------------
66parameters = dict(ghost_layer_width=3)
67domain = anuga_parallel.distribute(domain, verbose= True, parameters=parameters)
68
69
70#------------------------------------------------------------------------------
71# Setup boundary conditions
72#------------------------------------------------------------------------------
73Bi = anuga.Dirichlet_boundary([0.4, 0, 0])          # Inflow
74Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
75Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
76
77domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})
78
79#------------------------------------------------------------------------------
80# Evolve system through time
81#------------------------------------------------------------------------------
82for t in domain.evolve(yieldstep=0.1, finaltime=16.0):
83    if anuga_parallel.myid == 0:
84        print domain.timestepping_statistics()
85
86
87    ## if domain.get_quantity('stage').\
88    ##        get_values(interpolation_points=[[10, 2.5]]) > 0:
89    ##     print 'Stage > 0: Changing to outflow boundary'
90    ##     domain.set_boundary({'right': Bo})
91
92
93domain.sww_merge(verbose=True)
94
95anuga_parallel.finalize()
96       
Note: See TracBrowser for help on using the repository browser.