source: inundation/parallel/run_parallel_merimbula_test.py @ 3033

Last change on this file since 3033 was 3033, checked in by linda, 18 years ago

Further testing on time calculation in parallel computation

File size: 4.5 KB
Line 
1#!/usr/bin/env python
2#########################################################
3#
4#  Main file for parallel mesh testing. Runs an advection
5# flow simulation using a rectangular mesh
6#
7#  This is a modification of the run_parallel_advection.py
8# file
9#
10#
11# *) The (new) files that have been added to manage the
12# grid partitioning are
13#    +) pmesh_divide_metis.py: subdivide a pmesh
14#    +) build_submesh.py: build the submeshes on the host
15# processor.
16#    +) build_local.py: build the GA mesh datastructure
17# on each processor.
18#    +) build_commun.py: handle the communication between
19# the host and processors
20#
21#  Authors: Linda Stals, Steve Roberts and Matthew Hardy,
22# June 2005
23#
24#
25#
26#########################################################
27import sys
28import pypar    # The Python-MPI interface
29import time
30
31
32from os import sep
33sys.path.append('..'+sep+'pyvolution')
34
35# Numeric arrays
36
37from Numeric import array, zeros, Float
38# pmesh
39
40#from shallow_water import Domain
41
42from print_stats import print_test_stats, build_full_flag
43
44from pmesh2domain import pmesh_to_domain_instance
45from advection import Domain as Advection_Domain
46from parallel_advection import Parallel_Domain
47
48from generic_boundary_conditions import Transmissive_boundary
49
50# mesh partition routines
51
52from pmesh_divide  import pmesh_divide_metis
53from build_submesh import build_submesh
54from build_local   import build_local_mesh
55from build_commun  import send_submesh, rec_submesh, extract_hostmesh
56
57
58class Set_Stage:
59    """Set an initial condition with constant water height, for x<x0
60    """
61
62    def __init__(self, x0=0.25, x1=0.5, h=1.0):
63        self.x0 = x0
64        self.x1 = x1
65        self.= h
66
67    def __call__(self, x, y):
68        return self.h*((x>self.x0)&(x<self.x1))
69
70# read in the processor information
71
72numprocs = pypar.size()
73myid = pypar.rank()
74processor_name = pypar.Get_processor_name()
75
76
77#-------
78# Domain
79rect = zeros( 4, Float) # Buffer for results
80
81if myid == 0:
82
83    # read in the test files
84
85    filename = 'test-100.tsh'
86#    filename = 'merimbula_10785.tsh'
87    nx = numprocs
88    ny = 1
89    if nx*ny != numprocs:
90        print "WARNING: number of subboxes is not equal to the number of proc"
91
92    domain_full = pmesh_to_domain_instance(filename, Advection_Domain)
93    domain_full.set_quantity('stage', Set_Stage(200.0,300.0,1.0))
94#    domain_full.set_quantity('stage', Set_Stage(756000.0,756500.0,4.0))
95
96    nodes, triangles, boundary, triangles_per_proc, quantities  =\
97            pmesh_divide_metis(domain_full, numprocs)
98   
99    # subdivide the mesh
100    rect = array(domain_full.xy_extent, Float)
101#    rect = array(rect, Float)
102
103    submesh = build_submesh(nodes, triangles, boundary, quantities, \
104                            triangles_per_proc)
105
106    # send the mesh partition to the appropriate processor
107
108    for p in range(1, numprocs):
109      send_submesh(submesh, triangles_per_proc, p)
110
111    # Build the local mesh for processor 0
112   
113    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \
114              extract_hostmesh(submesh, triangles_per_proc)
115
116# read in the mesh partition that belongs to this
117# processor (note that the information is in the
118# correct form for the GA data structure
119
120else:
121    [points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict] = \
122             rec_submesh(0)
123
124pypar.broadcast(rect,0)
125
126domain = Parallel_Domain(points, vertices, boundary,
127                                   full_send_dict  = full_send_dict,
128                                   ghost_recv_dict = ghost_recv_dict,
129                                   velocity = [0.1,0.0])
130
131# Make a notes of which triangles are full and which are ghost
132
133tri_full_flag = build_full_flag(domain, ghost_recv_dict)
134
135#domain.initialise_visualiser(rect=rect)
136
137#Boundaries
138
139T = Transmissive_boundary(domain)
140#R = Reflective_boundary(domain)
141domain.set_boundary( {'outflow': T, 'inflow': T, 'inner':T, 'exterior': T, 'open':T, 'ghost':None} )
142
143
144
145domain.set_quantity('stage', quantities['stage'])
146
147#---------
148# Evolution
149t0 = time.time()
150
151
152try:
153   # domain.initialise_visualiser(rect=rect)
154    #domain.visualiser.coloring['stage'] = True
155    #domain.visualiser.scale_z['stage'] = 0.2
156except:
157    print 'No visualiser'
158
159
160from norms import linf_norm
161
162yieldstep = 1
163finaltime = 200
164
165#yieldstep = 1000
166#finaltime = 50000
167
168for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
169    if myid == 0:
170        domain.write_time()
171    print_test_stats(domain, tri_full_flag)
172
173if myid == 0:
174    print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracBrowser for help on using the repository browser.