[2767] | 1 | #!/usr/bin/env python |
---|
| 2 | ### |
---|
| 3 | ######################################################### |
---|
| 4 | # |
---|
| 5 | # Main file for parallel mesh testing. Runs an advection |
---|
| 6 | # flow simulation using a rectangular mesh |
---|
| 7 | # |
---|
| 8 | # |
---|
| 9 | # Authors: Steve Roberts June 2005 |
---|
| 10 | # Modified by Linda Stals April 2006 |
---|
| 11 | # |
---|
| 12 | # |
---|
| 13 | ######################################################### |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | import sys |
---|
| 17 | from os import sep |
---|
| 18 | sys.path.append('..'+sep+'pyvolution') |
---|
[2909] | 19 | sys.path.append('..'+sep+'parallel') |
---|
[2767] | 20 | |
---|
| 21 | # Parallel communication routines |
---|
| 22 | |
---|
| 23 | import pypar |
---|
| 24 | |
---|
| 25 | # Mesh partition routines |
---|
| 26 | |
---|
[3184] | 27 | from parallel.parallel_meshes import parallel_rectangle |
---|
[2767] | 28 | |
---|
| 29 | # Parallel Domain |
---|
| 30 | |
---|
[3184] | 31 | from parallel.parallel_advection import Parallel_Domain |
---|
| 32 | from parallel.parallel_advection import Transmissive_boundary |
---|
[2767] | 33 | |
---|
| 34 | ############################ |
---|
| 35 | # Set the initial conditions |
---|
| 36 | ############################ |
---|
| 37 | class Set_Stage: |
---|
| 38 | """Set an initial condition with constant water height, for x<x0 |
---|
| 39 | """ |
---|
| 40 | |
---|
| 41 | def __init__(self, x0=0.25, x1=0.5, h=1.0): |
---|
| 42 | self.x0 = x0 |
---|
| 43 | self.x1 = x1 |
---|
| 44 | self.h = h |
---|
| 45 | |
---|
| 46 | def __call__(self, x, y): |
---|
| 47 | return self.h*((x>self.x0)&(x<self.x1)) |
---|
| 48 | |
---|
| 49 | ############################### |
---|
| 50 | # Read in processor information |
---|
| 51 | ############################### |
---|
| 52 | |
---|
| 53 | numprocs = pypar.size() |
---|
| 54 | myid = pypar.rank() |
---|
| 55 | processor_name = pypar.Get_processor_name() |
---|
| 56 | |
---|
| 57 | ####################### |
---|
[2906] | 58 | # Partition the mesh |
---|
[2767] | 59 | ####################### |
---|
[3168] | 60 | N = 20 |
---|
| 61 | M = 20 |
---|
[2767] | 62 | |
---|
| 63 | # Build a unit mesh, subdivide it over numproces processors with each |
---|
| 64 | # submesh containing M*N nodes |
---|
| 65 | |
---|
| 66 | points, vertices, boundary, full_send_dict, ghost_recv_dict = \ |
---|
| 67 | parallel_rectangle(N, M, len1_g=1.0) |
---|
| 68 | |
---|
| 69 | ########################################### |
---|
| 70 | # Start the computations on each subpartion |
---|
| 71 | ########################################### |
---|
| 72 | |
---|
| 73 | # Create advection domain with direction (1,-1) |
---|
| 74 | # Initial condition is zero by default |
---|
| 75 | |
---|
| 76 | domain = Parallel_Domain(points, vertices, boundary, |
---|
| 77 | full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0]) |
---|
| 78 | |
---|
| 79 | # Turn on the visualisation |
---|
| 80 | |
---|
| 81 | rect = [0.0, 0.0, 1.0, 1.0] |
---|
| 82 | domain.initialise_visualiser(rect=rect) |
---|
| 83 | |
---|
| 84 | # Boundaries |
---|
| 85 | |
---|
| 86 | T = Transmissive_boundary(domain) |
---|
| 87 | domain.default_order = 2 |
---|
[2786] | 88 | domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T, \ |
---|
| 89 | 'ghost': None} ) |
---|
[2767] | 90 | |
---|
| 91 | # Ensure that the domain definitions make sense |
---|
| 92 | |
---|
| 93 | domain.check_integrity() |
---|
| 94 | |
---|
| 95 | # Set the inititial conditions |
---|
| 96 | |
---|
| 97 | domain.set_quantity('stage', Set_Stage(0.2,0.4,1.0)) |
---|
| 98 | |
---|
| 99 | # Let processor 0 output some timing information |
---|
| 100 | |
---|
| 101 | if myid == 0: |
---|
| 102 | import time |
---|
| 103 | t0 = time.time() |
---|
| 104 | |
---|
| 105 | # Start the evolve computions |
---|
| 106 | |
---|
| 107 | for t in domain.evolve(yieldstep = 0.1, finaltime = 3.0): |
---|
| 108 | if myid == 0: |
---|
| 109 | domain.write_time() |
---|
| 110 | |
---|
| 111 | # Output some computation statistics |
---|
| 112 | |
---|
| 113 | if myid == 0: |
---|
| 114 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
[2786] | 115 | print 'Communication time %.2f seconds'\ |
---|
| 116 | %domain.communication_time |
---|
| 117 | print 'Reduction Communication time %.2f seconds'\ |
---|
| 118 | %domain.communication_reduce_time |
---|
[3184] | 119 | |
---|
| 120 | |
---|