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