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