source: anuga_core/source/anuga_parallel/run_parallel_advection.py @ 7400

Last change on this file since 7400 was 7400, checked in by steve, 15 years ago

Commit a working copy of numpy version of build_commun

File size: 3.5 KB
Line 
1#!/usr/bin/env python
2#########################################################
3#
4#  Main file for parallel mesh testing. Runs an advection
5# flow simulation using a rectangular mesh
6#
7#
8#  Authors: Steve Roberts June 2005
9#  Modified by Linda Stals April 2006
10#
11#
12#########################################################
13
14
15
16# Parallel communication routines
17
18import pypar
19
20#  Mesh partition routines
21
22from parallel_meshes import parallel_rectangle
23
24# Parallel Domain
25 
26from parallel_advection import Parallel_Domain
27from parallel_advection import Transmissive_boundary
28
29############################
30# Set the initial conditions
31############################
32class Set_Stage:
33    """Set an initial condition with constant water height, for x<x0
34    """
35
36    def __init__(self, x0=0.25, x1=0.5, h=1.0):
37        self.x0 = x0
38        self.x1 = x1
39        self.= h
40
41    def __call__(self, x, y):
42        return self.h*((x>self.x0)&(x<self.x1))
43
44###############################
45# Read in processor information
46###############################
47
48numprocs = pypar.size()
49myid = pypar.rank()
50processor_name = pypar.get_processor_name()
51
52N = 5
53M = 2
54
55N = 10
56M = 5
57
58#######################
59# Partition the mesh
60#######################
61
62# Build a unit mesh, subdivide it over numproces processors with each
63# submesh containing M*N nodes
64
65points, vertices, boundary, full_send_dict, ghost_recv_dict =  \
66    parallel_rectangle(N, M, len1_g=1.0)
67
68#print 'ghost ',ghost_recv_dict
69#print 'full  ',full_send_dict
70
71
72
73print "Myid = ", myid, "no points = ", len(points), \
74      "no vertices = ", len(vertices), "no boundaries = ", len(boundary)
75
76###########################################
77# Start the computations on each subpartion
78###########################################
79
80# Create advection domain with direction (1,-1)
81# Initial condition is zero by default
82
83domain = Parallel_Domain(points, vertices, boundary,
84                         full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0])
85
86#print 'ghost ',ghost_recv_dict
87#print 'full  ',full_send_dict
88
89
90# Boundaries
91
92T = Transmissive_boundary(domain)
93
94
95
96
97domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T, \
98                      'ghost': None} )
99
100
101# Set Evolve parameters
102domain.set_default_order(2)
103domain.set_timestepping_method('rk2')
104
105print domain.get_timestepping_method()
106
107#domain.use_edge_limiter = True
108#domain.tight_slope_limiters = True
109#domain.use_centroid_velocities = False
110
111domain.CFL = 1.0
112
113domain.set_beta(0.8)
114
115
116# Ensure that the domain definitions make sense
117
118domain.check_integrity()
119
120# Set the inititial conditions
121
122domain.set_quantity('stage', Set_Stage(0.2,0.4,1.0))
123
124# Let processor 0 output some timing information
125
126visualise = False
127if visualise:
128    from anuga.visualiser import RealtimeVisualiser
129    vis = RealtimeVisualiser(domain)
130    vis.render_quantity_height("stage", zScale = 5.0, dynamic=True)
131    vis.colour_height_quantity('stage', (0.2, 0.2, 0.8))
132    vis.start()
133    import time
134    time.sleep(2.0)
135   
136
137
138if myid == 0:
139    import time
140    t0 = time.time()
141
142for t in domain.evolve(yieldstep = 0.1, finaltime = 30.0):
143    if myid == 0:
144        domain.write_time()
145       
146    if visualise:
147        vis.update()                                           
148
149       
150
151if visualise: vis.evolveFinished()
152   
153
154# Output some computation statistics
155
156if myid == 0:
157    print 'That took %.2f seconds' %(time.time()-t0)
158    print 'Communication time %.2f seconds'\
159          %domain.communication_time
160    print 'Reduction Communication time %.2f seconds'\
161          %domain.communication_reduce_time
162       
163 
164if visualise: vis.join()
Note: See TracBrowser for help on using the repository browser.