from anuga_parallel import distribute, myid, numprocs, finalize, barrier

from anuga_parallel.sequential_distribute import sequential_distribute_load

#--------------------------------------------------------------------------
# Setup parameters
#--------------------------------------------------------------------------
yieldstep = 50
finaltime = 1500
verbose = True

#-------------------------------------------------------------------------------
# Read in cPickled distribute mesh data
#-------------------------------------------------------------------------------
domain = sequential_distribute_load(filename='merimbula_new', verbose=True)

#--------------------------------------------------------------------------
# On all processors, setup evolve parameters for domains on all processors
# (all called "domain"
#--------------------------------------------------------------------------

domain.set_flow_algorithm('DE0')

#------------------------------------------------------------------------------
# Setup boundary conditions
# This must currently happen *after* domain has been distributed
#------------------------------------------------------------------------------
Br = Reflective_boundary(domain)  # Solid reflective wall

domain.set_boundary({
#import cPickle
#pickle_name = pickle_base+'_P%g_%g.pickle'% (numprocs,myid)
#f = file(pickle_name, 'rb')
# = cPickle.load(f)
#f.close()

t1 = time.time()

if myid == 0 and verbose:
    print 'Loading DISTRIBUTING DOMAIN'
    sys.stdout.flush()

#-------------------------------------------------------------------------
# Distribute domain
#-------------------------------------------------------------------------
domain = sequential_distribute_load(filename=basename, verbose=verbose)

t2 = time.time()

if myid == 0:
    print 'Load Distribute domain ', t2 - t1

if myid == 0: print 'after parallel domain'

#Boundaries
T = anuga.Transmissive_boundary(domain)
R = anuga.Reflective_boundary(domain)
D = anuga.Dirichlet_boundary([-0.1 * scale_me, 0., 0.])

domain.set_boundary({
    'left': R,
#pickle_name = pickle_base+'_P%g_%g.pickle'% (numprocs,myid)
#f = file(pickle_name, 'rb')
# = cPickle.load(f)
#f.close()


t1 = time.time()

if myid == 0 and verbose:
    print 'Loading DISTRIBUTING DOMAIN'
    sys.stdout.flush()

#-------------------------------------------------------------------------
# Distribute domain
#-------------------------------------------------------------------------
domain = sequential_distribute_load(filename = basename, verbose=verbose)


t2 = time.time()

if myid == 0 :
    print 'Load Distribute domain ',t2-t1
    
if myid == 0 : print 'after parallel domain'


#Boundaries
T = anuga.Transmissive_boundary(domain)
R = anuga.Reflective_boundary(domain)
D = anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.])
from anuga_parallel.sequential_distribute import sequential_distribute_load

#--------------------------------------------------------------------------
# Setup parameters
#--------------------------------------------------------------------------
yieldstep = 50
finaltime = 1500
verbose = True



#-------------------------------------------------------------------------------
# Read in cPickled distribute mesh data
#-------------------------------------------------------------------------------
domain = sequential_distribute_load(filename='merimbula_new', verbose = True)

#--------------------------------------------------------------------------
# On all processors, setup evolve parameters for domains on all processors
# (all called "domain"
#--------------------------------------------------------------------------

domain.set_flow_algorithm('DE0')



#------------------------------------------------------------------------------
# Setup boundary conditions
# This must currently happen *after* domain has been distributed
#------------------------------------------------------------------------------
Br = Reflective_boundary(domain)      # Solid reflective wall