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