source: anuga_core/source/anuga_parallel/test_parallel_sw_runup.py @ 3776

Last change on this file since 3776 was 3776, checked in by ole, 17 years ago

Made parallel abstraction work on sequential machine without pypar.
Work on simple parallel example (plotting)

File size: 3.7 KB
Line 
1#!/usr/bin/env python
2
3
4"""Simple water flow example using ANUGA
5
6Water driven up a linear slope and time varying boundary,
7similar to a beach environment
8
9This is a very simple test of the parallel algorithm using the simplified parallel API
10"""
11
12
13#------------------------------------------------------------------------------
14# Import necessary modules
15#------------------------------------------------------------------------------
16
17from anuga.pmesh.mesh_interface import create_mesh_from_regions
18from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
19from anuga.shallow_water import Domain
20from anuga.shallow_water import Reflective_boundary
21from anuga.shallow_water import Dirichlet_boundary
22from anuga.shallow_water import Time_boundary
23from anuga.shallow_water import Transmissive_boundary
24
25from parallel_api import distribute, myid
26
27
28#--------------------------------------------------------------------------
29# Setup computational domain
30#--------------------------------------------------------------------------
31points, vertices, boundary = rectangular_cross(10, 10) # Basic mesh
32domain = Domain(points, vertices, boundary) # Create domain
33domain.set_name('runup')                    # Set sww filename
34domain.set_datadir('.')                     # Set output dir
35
36
37#--------------------------------------------------------------------------
38# Setup initial conditions
39#--------------------------------------------------------------------------
40
41def topography(x,y): 
42    return -x/2                              # linear bed slope
43
44domain.set_quantity('elevation', topography) # Use function for elevation
45domain.set_quantity('friction', 0.1)         # Constant friction
46domain.set_quantity('stage', -.4)            # Constant initial stage
47
48
49#------------------------------------------------------------------------------
50# Setup boundary conditions
51#------------------------------------------------------------------------------
52
53Br = Reflective_boundary(domain)      # Solid reflective wall
54Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values
55
56# Associate boundary tags with boundary objects
57domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br})
58
59
60#--------------------------------------------------------------------------
61# Create the parallel domain
62#--------------------------------------------------------------------------
63domain = distribute(domain, verbose=True)
64
65
66#------------------------------------------------------------------------------
67# Evolve system through time
68#------------------------------------------------------------------------------
69
70interpolation_points = [[0.4,0.5], [0.6,0.5], [0.8,0.5], [0.9,0.5]]
71gauge_values = []
72for _ in interpolation_points:
73    gauge_values.append([])
74
75time = []
76
77for t in domain.evolve(yieldstep = 0.1, finaltime = 5.0):
78    domain.write_time()
79
80   
81    # Record time series at known points
82    time.append(domain.get_time())
83   
84    stage = domain.get_quantity('stage')
85    w = stage.get_values(interpolation_points=interpolation_points)
86   
87    for i, _ in enumerate(interpolation_points):
88        gauge_values[i].append(w[i])
89
90
91print
92print time
93print
94for i, (x,y) in enumerate(interpolation_points):
95    print i, gauge_values[i]
96    print 
97
98       
99    try:
100        from pylab import *
101    except:
102        pass
103    else:
104        ion()
105        hold(False)
106        plot(time, gauge_values[i], 'r.-')
107        #time, predicted_gauge_values[i], 'k-')
108       
109        title('Gauge %d (%f,%f)' %(i,x,y))
110        xlabel('time(s)')
111        ylabel('stage (m)')   
112        #legend(('Observed', 'Modelled'), shadow=True, loc='upper left')
113        #savefig('Gauge_%d.png' %i, dpi = 300)
114   
115        raw_input('Next')
116       
117
118
Note: See TracBrowser for help on using the repository browser.