source: inundation/parallel/run_parallel_advection.py @ 2654

Last change on this file since 2654 was 2654, checked in by linda, 18 years ago

Added routines to print domain stats in parallel

File size: 2.3 KB
Line 
1#!/usr/bin/env python
2
3import sys
4from os import sep
5sys.path.append('..'+sep+'pyvolution')
6
7
8#========================================================================
9
10import pypar
11
12from print_stats import print_test_stats, build_full_flag
13
14from parallel_meshes import parallel_rectangle
15
16from parallel_advection import Parallel_Domain
17from parallel_advection import Transmissive_boundary
18
19# Define the inititial conditions
20
21class Set_Stage:
22    """Set an initial condition with constant water height, for x<x0
23    """
24
25    def __init__(self, x0=0.25, x1=0.5, h=1.0):
26        self.x0 = x0
27        self.x1 = x1
28        self.= h
29
30    def __call__(self, x, y):
31        return self.h*((x>self.x0)&(x<self.x1))
32
33# Get information about the parallel set-up
34
35numprocs = pypar.size()
36myid = pypar.rank()
37processor_name = pypar.Get_processor_name()
38
39N = 20
40M = 20
41
42# Build 1*1 domain containing M*N nodes split over numprocs * 1 processors
43
44points, vertices, boundary, full_send_dict, ghost_recv_dict =  \
45    parallel_rectangle(N, M, len1_g=1.0)
46
47# Create advection domain with direction (1,-1)
48# Initial condition is zero by default
49
50domain = Parallel_Domain(points, vertices, boundary,
51                         full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0])
52
53# Make a notes of which triangles are full and which are ghost
54
55tri_full_flag = build_full_flag(domain, ghost_recv_dict)
56
57# Turn on the visualisation
58
59rect = [0.0, 0.0, 1.0, 1.0]
60domain.initialise_visualiser(rect=rect)
61
62# Boundaries
63
64T = Transmissive_boundary(domain)
65domain.default_order = 2
66domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T, 'ghost': None} )
67
68# Ensure that the domain definitions make sense
69
70domain.check_integrity()
71
72# Set the inititial conditions
73
74domain.set_quantity('stage', Set_Stage(0.2,0.4,1.0))
75
76# Let processor 0 output some timing information
77
78if myid == 0:
79    import time
80    t0 = time.time()
81
82# Start the parallel computions
83
84for t in domain.evolve(yieldstep = 0.1, finaltime = 3.0):
85    if myid == 0:
86        domain.write_time()
87    print_test_stats(domain, tri_full_flag)
88
89# Output some computation statistics
90
91if myid == 0:
92    print 'That took %.2f seconds' %(time.time()-t0)
93    print 'Communication time %.2f seconds'%domain.communication_time
94    print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time
Note: See TracBrowser for help on using the repository browser.