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 = 25 |
---|
22 | M = 25 |
---|
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 | #domain.initialise_visualiser() |
---|
33 | |
---|
34 | #Boundaries |
---|
35 | T = Transmissive_boundary(domain) |
---|
36 | D = Dirichlet_boundary(array([1.0])) |
---|
37 | |
---|
38 | domain.default_order = 2 |
---|
39 | |
---|
40 | |
---|
41 | domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T} ) |
---|
42 | domain.check_integrity() |
---|
43 | |
---|
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 | |
---|
56 | if myid == 0: |
---|
57 | domain.set_quantity('stage', Set_Stage(0.2,0.4,1.0)) |
---|
58 | import time |
---|
59 | t0 = time.time() |
---|
60 | |
---|
61 | #Check that the boundary value gets propagated to all elements |
---|
62 | for t in domain.evolve(yieldstep = 0.1, finaltime = 2.0): |
---|
63 | if myid == 0: |
---|
64 | domain.write_time() |
---|
65 | |
---|
66 | if myid == 0: |
---|
67 | print 'That took %.2f seconds' %(time.time()-t0) |
---|