[2090] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | import sys |
---|
| 4 | from os import sep |
---|
| 5 | sys.path.append('..'+sep+'pyvolution') |
---|
| 6 | |
---|
| 7 | #======================================================================== |
---|
| 8 | from config import g, epsilon |
---|
| 9 | from Numeric import allclose, array, zeros, ones, Float |
---|
| 10 | from parallel_meshes import parallel_rectangle |
---|
| 11 | |
---|
| 12 | from advection import Domain |
---|
| 13 | from parallel_advection import Parallel_Domain |
---|
| 14 | from parallel_advection import Transmissive_boundary, Dirichlet_boundary |
---|
| 15 | |
---|
| 16 | import pypar |
---|
| 17 | |
---|
| 18 | numprocs = pypar.size() |
---|
| 19 | myid = pypar.rank() |
---|
| 20 | processor_name = pypar.Get_processor_name() |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | #N = 50 |
---|
| 25 | N = 20 |
---|
| 26 | M = 20 |
---|
| 27 | |
---|
| 28 | points, vertices, boundary, full_send_dict, ghost_recv_dict = \ |
---|
| 29 | parallel_rectangle(N, M, len1_g=1.0) |
---|
| 30 | |
---|
| 31 | #Create advection domain with direction (1,-1) |
---|
| 32 | domain = Parallel_Domain(points, vertices, boundary, |
---|
| 33 | full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0]) |
---|
| 34 | |
---|
| 35 | # Initial condition is zero by default |
---|
| 36 | |
---|
| 37 | #turn on the visualisation |
---|
| 38 | rect = [0.0, 0.0, 1.0, 1.0] |
---|
| 39 | domain.initialise_visualiser(rect=rect) |
---|
| 40 | |
---|
| 41 | #Boundaries |
---|
| 42 | T = Transmissive_boundary(domain) |
---|
| 43 | D = Dirichlet_boundary(array([1.0])) |
---|
| 44 | |
---|
| 45 | domain.default_order = 2 |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T} ) |
---|
| 49 | domain.check_integrity() |
---|
| 50 | |
---|
| 51 | class Set_Stage: |
---|
| 52 | """Set an initial condition with constant water height, for x<x0 |
---|
| 53 | """ |
---|
| 54 | |
---|
| 55 | def __init__(self, x0=0.25, x1=0.5, h=1.0): |
---|
| 56 | self.x0 = x0 |
---|
| 57 | self.x1 = x1 |
---|
| 58 | self.h = h |
---|
| 59 | |
---|
| 60 | def __call__(self, x, y): |
---|
| 61 | return self.h*((x>self.x0)&(x<self.x1)) |
---|
| 62 | |
---|
| 63 | domain.set_quantity('stage', Set_Stage(0.2,0.4,1.0)) |
---|
| 64 | |
---|
| 65 | if myid == 0: |
---|
| 66 | import time |
---|
| 67 | t0 = time.time() |
---|
| 68 | |
---|
| 69 | #Check that the boundary value gets propagated to all elements |
---|
| 70 | for t in domain.evolve(yieldstep = 0.1, finaltime = 3.0): |
---|
| 71 | if myid == 0: |
---|
| 72 | domain.write_time() |
---|
| 73 | |
---|
| 74 | if myid == 0: |
---|
| 75 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 76 | print 'Communication time %.2f seconds'%domain.communication_time |
---|
| 77 | print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time |
---|