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

Last change on this file since 5762 was 5762, checked in by steve, 16 years ago
File size: 3.3 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 = 80
53M = 80
54
55#######################
56# Partition the mesh
57#######################
58
59# Build a unit mesh, subdivide it over numproces processors with each
60# submesh containing M*N nodes
61
62points, vertices, boundary, full_send_dict, ghost_recv_dict =  \
63    parallel_rectangle(N, M, len1_g=1.0)
64
65print "Myid = ", myid, "no points = ", len(points), \
66      "no vertices = ", len(vertices), "no boundaries = ", len(boundary)
67
68###########################################
69# Start the computations on each subpartion
70###########################################
71
72# Create advection domain with direction (1,-1)
73# Initial condition is zero by default
74
75domain = Parallel_Domain(points, vertices, boundary,
76                         full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0])
77
78# Turn on the visualisation
79
80
81
82
83# rect = [0.0, 0.0, 1.0, 1.0]
84# domain.initialise_visualiser(rect=rect)
85
86# Boundaries
87
88T = Transmissive_boundary(domain)
89domain.default_order = 2
90domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T, \
91                      'ghost': None} )
92
93# Ensure that the domain definitions make sense
94
95domain.check_integrity()
96
97# Set the inititial conditions
98
99domain.set_quantity('stage', Set_Stage(0.2,0.4,1.0))
100
101# Let processor 0 output some timing information
102
103visualise = True
104if visualise:
105    from anuga.visualiser import RealtimeVisualiser
106    vis = RealtimeVisualiser(domain)
107    vis.render_quantity_height("elevation", offset=0.01, dynamic=False)
108    vis.render_quantity_height("stage", dynamic=True)
109    vis.colour_height_quantity('stage', (0.2, 0.2, 0.8))
110    vis.start()
111    import time
112    time.sleep(2.0)
113   
114
115
116if myid == 0:
117    import time
118    t0 = time.time()
119
120for t in domain.evolve(yieldstep = 0.1, finaltime = 3.0):
121    if myid == 0:
122        domain.write_time()
123       
124    if visualise:
125        vis.update()                                           
126
127       
128
129if visualise: vis.evolveFinished()
130   
131
132# Output some computation statistics
133
134if myid == 0:
135    print 'That took %.2f seconds' %(time.time()-t0)
136    print 'Communication time %.2f seconds'\
137          %domain.communication_time
138    print 'Reduction Communication time %.2f seconds'\
139          %domain.communication_reduce_time
140       
141 
142vis.join()     
Note: See TracBrowser for help on using the repository browser.