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

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

Added other mesh types to test

File size: 5.6 KB
Line 
1"""Simple water flow example using ANUGA
2
3Water driven up a linear slope and time varying boundary,
4similar to a beach environment
5
6This is a very simple test of the parallel algorithm
7"""
8
9
10#------------------------------------------------------------------------------
11# Import necessary modules
12#------------------------------------------------------------------------------
13
14from anuga.pmesh.mesh_interface import create_mesh_from_regions
15from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
16from anuga.shallow_water import Domain
17from anuga.shallow_water import Reflective_boundary
18from anuga.shallow_water import Dirichlet_boundary
19from anuga.shallow_water import Time_boundary
20from anuga.shallow_water import Transmissive_boundary
21
22from parallel_api import *
23
24#------------------------------------------------------------------------------
25# Read in processor information
26#------------------------------------------------------------------------------
27
28numprocs = pypar.size()
29myid = pypar.rank()
30processor_name = pypar.Get_processor_name()
31print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name)
32
33
34#------------------------------------------------------------------------------
35# Initialise
36#------------------------------------------------------------------------------
37
38if myid == 0:
39    #--------------------------------------------------------------------------
40    # Setup computational domain
41    #--------------------------------------------------------------------------
42
43
44    points, vertices, boundary = rectangular_cross(10, 10) # Basic mesh
45    domain = Domain(points, vertices, boundary) # Create domain
46
47
48    # Unstructured mesh
49    #polygon = [[1,1],[0,1],[0,0],[1,0]]
50    #meshname = 'runup.msh'
51    #create_mesh_from_regions(polygon,
52    #                         boundary_tags={'top': [0],
53    #                                        'left': [1],
54    #                                        'bottom': [2],
55    #                                        'right': [3]},
56    #                         maximum_triangle_area=0.01,
57    #                         filename=meshname)
58    #domain = Domain(meshname, use_cache=True, verbose = True)
59
60
61   
62    domain.set_name('runup')                    # Set sww filename
63   
64
65    #------------ -------------------------------------------------------------
66    # Setup initial conditions
67    #--------------------------------------------------------------------------
68
69    def topography(x,y): 
70        return -x/2                              # linear bed slope
71
72    domain.set_quantity('elevation', topography) # Use function for elevation
73    domain.set_quantity('friction', 0.1)         # Constant friction
74    domain.set_quantity('stage', -.4)            # Constant initial stage
75
76
77    #------------ -------------------------------------------------------------
78    # Distribute the domain
79    #--------------------------------------------------------------------------
80   
81    # Subdivide the mesh
82    print 'Subdivide mesh'
83    nodes, triangles, boundary, triangles_per_proc, quantities = \
84           pmesh_divide_metis(domain, numprocs)
85
86    # Build the mesh that should be assigned to each processor,
87    # this includes ghost nodes and the communicaiton pattern
88    print 'Build submeshes'   
89    submesh = build_submesh(nodes, triangles, boundary,\
90                            quantities, triangles_per_proc)
91
92    # Send the mesh partition to the appropriate processor
93    print 'Distribute submeshes'       
94    for p in range(1, numprocs):
95      send_submesh(submesh, triangles_per_proc, p)
96
97    # Build the local mesh for processor 0
98    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \
99              extract_hostmesh(submesh, triangles_per_proc)
100
101    print 'Communication done'       
102   
103else:
104    # Read in the mesh partition that belongs to this
105    # processor (note that the information is in the
106    # correct form for the GA data structure)
107
108    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict, \
109            = rec_submesh(0)
110
111
112
113#------------------------------------------------------------------------------
114# Start the computations on each subpartion
115#------------------------------------------------------------------------------
116
117# Build the domain for this processor
118domain = Parallel_Domain(points, vertices, boundary,
119                         full_send_dict  = full_send_dict,
120                         ghost_recv_dict = ghost_recv_dict)
121
122
123# Name and dir, etc currently has to be set here as they are not
124# transferred from the original domain
125domain.set_name('runup')                    # Set sww filename
126
127
128#------------------------------------------------------------------------------
129# Setup initial conditions
130#------------------------------------------------------------------------------
131for q in quantities:
132    domain.set_quantity(q, quantities[q]) # Distribute all quantities   
133
134
135
136#------------------------------------------------------------------------------
137# Setup parallel boundary conditions
138#------------------------------------------------------------------------------
139
140Br = Reflective_boundary(domain)      # Solid reflective wall
141Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values
142
143# Associate boundary tags with boundary objects
144domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br,
145                     'ghost': None, 'exterior': Bd})
146
147
148
149#------------------------------------------------------------------------------
150# Evolve system through time
151#------------------------------------------------------------------------------
152
153for t in domain.evolve(yieldstep = 0.1, finaltime = 10.0):
154    domain.write_time()
155   
156
157
Note: See TracBrowser for help on using the repository browser.