[2813] | 1 | #!/usr/bin/env python |
---|
| 2 | ######################################################### |
---|
| 3 | # |
---|
| 4 | # Main file for parallel mesh testing. |
---|
| 5 | # |
---|
| 6 | # This is a modification of the run_parallel_advection.py |
---|
| 7 | # file. |
---|
| 8 | # |
---|
| 9 | # |
---|
| 10 | # Authors: Linda Stals, Steve Roberts and Matthew Hardy, |
---|
| 11 | # June 2005 |
---|
| 12 | # |
---|
| 13 | # |
---|
| 14 | # |
---|
| 15 | ######################################################### |
---|
| 16 | import sys |
---|
| 17 | import pypar # The Python-MPI interface |
---|
| 18 | import time |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | from os import sep |
---|
| 22 | sys.path.append('..'+sep+'pyvolution') |
---|
| 23 | |
---|
| 24 | from Numeric import array |
---|
| 25 | # pmesh |
---|
| 26 | |
---|
| 27 | from print_stats import print_test_stats, build_full_flag |
---|
| 28 | |
---|
| 29 | from shallow_water import Domain |
---|
| 30 | from parallel_shallow_water import Parallel_Domain |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | # mesh partition routines |
---|
| 34 | from parallel_meshes import parallel_rectangle |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | numprocs = pypar.size() |
---|
| 38 | myid = pypar.rank() |
---|
| 39 | processor_name = pypar.Get_processor_name() |
---|
| 40 | |
---|
[2814] | 41 | M = 22 |
---|
[2813] | 42 | N = M*numprocs |
---|
| 43 | |
---|
| 44 | if myid == 0: |
---|
| 45 | print 'N == %d' %N |
---|
| 46 | |
---|
| 47 | points, vertices, boundary, full_send_dict, ghost_recv_dict = \ |
---|
| 48 | parallel_rectangle(N, M, len1_g=1.0*numprocs, len2_g = 1.0) |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | domain = Parallel_Domain(points, vertices, boundary, |
---|
| 53 | full_send_dict = full_send_dict, |
---|
| 54 | ghost_recv_dict = ghost_recv_dict) |
---|
| 55 | |
---|
| 56 | # Make a notes of which triangles are full and which are ghost |
---|
| 57 | |
---|
| 58 | tri_full_flag = build_full_flag(domain, ghost_recv_dict) |
---|
| 59 | |
---|
| 60 | print 'number of triangles = ', domain.number_of_elements |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | rect = [ 0.0, 0.0, 1.0*numprocs, 1.0] |
---|
| 64 | ## try: |
---|
| 65 | ## domain.initialise_visualiser(rect=rect) |
---|
| 66 | ## domain.visualiser.qcolor['stage'] = (0.0, 0.0, 0.8) |
---|
| 67 | ## domain.visualiser.scale_z['stage'] = 1.0 |
---|
| 68 | ## domain.visualiser.scale_z['elevation'] = 0.05 |
---|
| 69 | ## except: |
---|
| 70 | ## print 'No visualiser' |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | domain.default_order = 1 |
---|
| 76 | |
---|
| 77 | #Boundaries |
---|
| 78 | from parallel_shallow_water import Transmissive_boundary, Reflective_boundary |
---|
| 79 | |
---|
| 80 | T = Transmissive_boundary(domain) |
---|
| 81 | R = Reflective_boundary(domain) |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R, 'ghost': None} ) |
---|
| 85 | domain.check_integrity() |
---|
| 86 | |
---|
| 87 | class Set_Stage: |
---|
| 88 | """Set an initial condition with constant water height, for x<x0 |
---|
| 89 | """ |
---|
| 90 | |
---|
| 91 | def __init__(self, x0=0.25, x1=0.75, y0=0.0, y1=1.0, h=5.0): |
---|
| 92 | self.x0 = x0 |
---|
| 93 | self.x1 = x1 |
---|
| 94 | self.y0 = y0 |
---|
| 95 | self.y1 = y1 |
---|
| 96 | self.h = h |
---|
| 97 | |
---|
| 98 | def __call__(self, x, y): |
---|
| 99 | return self.h*((x>self.x0)&(x<self.x1)&(y>self.y0)&(y<self.y1)) |
---|
| 100 | |
---|
| 101 | domain.set_quantity('stage', Set_Stage(0.2,0.4,0.25, 0.75, 1.0)) |
---|
| 102 | |
---|
| 103 | if myid == 0: |
---|
| 104 | import time |
---|
| 105 | t0 = time.time() |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | # Turn on the visualisation |
---|
| 109 | |
---|
| 110 | rect = [0.0, 0.0, 1.0, 1.0] |
---|
| 111 | domain.initialise_visualiser() |
---|
| 112 | |
---|
| 113 | yieldstep = 0.005 |
---|
| 114 | finaltime = 1.0 |
---|
| 115 | |
---|
| 116 | #Check that the boundary value gets propagated to all elements |
---|
| 117 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
| 118 | if myid == 0: |
---|
| 119 | domain.write_time() |
---|
| 120 | #print_test_stats(domain, tri_full_flag) |
---|
| 121 | |
---|
| 122 | if myid == 0: |
---|
| 123 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 124 | print 'Communication time %.2f seconds'%domain.communication_time |
---|
| 125 | print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time |
---|
| 126 | print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | pypar.finalize() |
---|