Skip to content

Commit

Permalink
Merge bfdec82 into 03dc682
Browse files Browse the repository at this point in the history
  • Loading branch information
stoiver committed Sep 4, 2018
2 parents 03dc682 + bfdec82 commit 98848dc
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 467 deletions.
64 changes: 33 additions & 31 deletions anuga/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
the user's code:
import anuga
This usage pattern abstracts away the internal heirarchy of the ANUGA
system, allowing the user to concentrate on writing simulations without
searching through the ANUGA source tree for the functions that they need.
Also, it isolates the user from "under-the-hood" refactorings.
"""

Expand All @@ -34,8 +34,8 @@
__ANUGA_SETUP__
except NameError:
__ANUGA_SETUP__ = False


if __ANUGA_SETUP__:
import sys as _sys
_sys.stderr.write('Running from anuga source directory.\n')
Expand All @@ -49,20 +49,20 @@
its source directory; please exit the anuga source tree, and relaunch
your python interpreter from there."""
raise ImportError(msg)

#---------------------------------
# NetCDF changes stdout to terminal\
# Causes trouble when using jupyter
#---------------------------------
import sys
_stdout = sys.stdout
_stdout = sys.stdout

#---------------------------------
# Setup the nose tester from numpy
#---------------------------------
from numpy.testing import Tester
test = Tester().test

#--------------------------------
# Important basic classes
#--------------------------------
Expand All @@ -77,9 +77,9 @@

from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain
from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Miscellaneous
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
from anuga.abstract_2d_finite_volumes.util import file_function, \
sww2timeseries, sww2csv_gauges, \
csv2timeseries_graphs
Expand All @@ -99,15 +99,15 @@
from anuga.geometry.polygon import inside_polygon
from anuga.geometry.polygon import polygon_area
from anuga.geometry.polygon_function import Polygon_function

from anuga.coordinate_transforms.lat_long_UTM_conversion import LLtoUTM, UTMtoLL

from anuga.abstract_2d_finite_volumes.pmesh2domain import \
pmesh_to_domain_instance

from anuga.fit_interpolate.fit import fit_to_mesh_file
from anuga.fit_interpolate.fit import fit_to_mesh

from anuga.utilities.system_tools import file_length
from anuga.utilities.sww_merge import sww_merge_parallel as sww_merge
from anuga.utilities.file_utils import copy_code_files
Expand All @@ -118,11 +118,11 @@
from anuga.caching import cache
from os.path import join
from anuga.config import indent

from anuga.utilities.parse_time import parse_time

#----------------------------
# Parallel api
# Parallel api
#----------------------------
## from anuga_parallel.parallel_api import distribute
## from anuga_parallel.parallel_api import myid, numprocs, get_processor_name
Expand Down Expand Up @@ -205,14 +205,14 @@
from anuga.file_conversion.file_conversion import timefile2netcdf
from anuga.file_conversion.file_conversion import tsh2sww
from anuga.file_conversion.urs2nc import urs2nc
from anuga.file_conversion.urs2sww import urs2sww
from anuga.file_conversion.urs2sww import urs2sww
from anuga.file_conversion.urs2sts import urs2sts
from anuga.file_conversion.dem2pts import dem2pts
from anuga.file_conversion.esri2sww import esri2sww
from anuga.file_conversion.sww2dem import sww2dem, sww2dem_batch
from anuga.file_conversion.dem2pts import dem2pts
from anuga.file_conversion.esri2sww import esri2sww
from anuga.file_conversion.sww2dem import sww2dem, sww2dem_batch
from anuga.file_conversion.asc2dem import asc2dem
from anuga.file_conversion.xya2pts import xya2pts
from anuga.file_conversion.ferret2sww import ferret2sww
from anuga.file_conversion.xya2pts import xya2pts
from anuga.file_conversion.ferret2sww import ferret2sww
from anuga.file_conversion.dem2dem import dem2dem
from anuga.file_conversion.sww2array import sww2array

Expand All @@ -237,6 +237,10 @@ def get_args():
#-----------------------------
from anuga.utilities.run_anuga_script import run_script as run_anuga_script

#---------------------------
# Simulation and Excel mesh_interface
#---------------------------
from anuga.simulation.simulation import Simulation

#-----------------------------
# Mesh API
Expand All @@ -254,12 +258,12 @@ def get_args():
from anuga.operators.kinematic_viscosity_operator import Kinematic_viscosity_operator

from anuga.operators.rate_operators import Rate_operator
from anuga.operators.set_friction_operators import Depth_friction_operator
from anuga.operators.set_friction_operators import Depth_friction_operator

from anuga.operators.set_elevation_operator import Set_elevation_operator
from anuga.operators.set_quantity_operator import Set_quantity_operator
from anuga.operators.set_stage_operator import Set_stage_operator


from anuga.operators.set_elevation import Set_elevation
from anuga.operators.set_quantity import Set_quantity
Expand All @@ -268,7 +272,10 @@ def get_args():
from anuga.operators.erosion_operators import Bed_shear_erosion_operator
from anuga.operators.erosion_operators import Flat_slice_erosion_operator
from anuga.operators.erosion_operators import Flat_fill_slice_erosion_operator





#---------------------------
# Structure Operators
#---------------------------
Expand All @@ -295,7 +302,7 @@ def get_args():


#----------------------------
#
#
#Added by Petar Milevski 10/09/2013
#import time, os

Expand Down Expand Up @@ -333,21 +340,16 @@ def get_args():
from anuga.extras import create_domain_from_file
from anuga.extras import rectangular_cross_domain


#import logging as log
from anuga.utilities import log

from anuga.config import g
from anuga.config import velocity_protection

#--------------------------------------
# NetCDF changes stdout to the terminal
# This resets it
#--------------------------------------
reload(sys)
sys.stdout = _stdout





9 changes: 5 additions & 4 deletions anuga/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ def configuration(parent_package='',top_path=None):
config.add_subpackage('parallel')
config.add_subpackage('pmesh')
config.add_subpackage('pymetis')
config.add_subpackage('simulation')
config.add_subpackage('shallow_water')
config.add_subpackage('structures')
config.add_subpackage('tsunami_source')
config.add_subpackage('utilities')
config.add_subpackage('validation_utilities')


try:
import vtk
config.add_subpackage('visualiser')
except:
pass

config.make_config_py()

return config

if __name__ == '__main__':
Expand Down
56 changes: 29 additions & 27 deletions anuga/shallow_water/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
Setup with domain.set_checkpointing(checkpoint_step, checkpoint_dir)
checkpoint_step: the number of yieldsteps between saving a checkpoint file
checkpoint_dir: the name of the directory where teh checkpoint files are stored.
checkpoint_dir: the name of the directory where teh checkpoint files are stored.
But if we are restarting a calculation there is no domain yet available, so we must
But if we are restarting a calculation there is no domain yet available, so we must
read in the last stored domain. Do that via
domain = load_last_checkpoint_file(domain_name, checkpoint_dir)
Expand All @@ -22,12 +22,12 @@


def load_checkpoint_file(domain_name = 'domain', checkpoint_dir = '.', time = None):

from os.path import join

if numprocs > 1:
domain_name = domain_name+'_P{}_{}'.format(numprocs,myid)

if time is None:
# will pull out the last available time
times = _get_checkpoint_times(domain_name, checkpoint_dir)
Expand All @@ -37,59 +37,62 @@ def load_checkpoint_file(domain_name = 'domain', checkpoint_dir = '.', time = No
#print times
else:
times = [float(time)]

if len(times) == 0: raise Exception, "Unable to open checkpoint file"

for time in reversed(times):

pickle_name = join(checkpoint_dir,domain_name)+'_'+str(time)+'.pickle'
#print pickle_name

try:
import cPickle
try:
import dill as cPickle
except:
import cPickle
domain = cPickle.load(open(pickle_name, 'rb'))
success = True
except:
success = False

#print success
overall = success
for cpu in range(numprocs):
if cpu != myid:
send(success,cpu)

for cpu in range(numprocs):
if cpu != myid:
overall = overall & receive(cpu)
barrier()

barrier()

#print myid, overall, success, time

if overall: break

if not overall: raise Exception, "Unable to open checkpoint file"

domain.last_walltime = walltime()
domain.communication_time = 0.0
domain.communication_reduce_time = 0.0
domain.communication_broadcast_time = 0.0

return domain


def _get_checkpoint_times(domain_name, checkpoint_dir):

import os
times = set()

for (path, directory, filenames) in os.walk(checkpoint_dir):
#print filenames
#print directory

if len(filenames) == 0:
return None
else:
else:
for filename in filenames:
filebase = os.path.splitext(filename)[0].rpartition("_")
time = filebase[-1]
Expand All @@ -101,18 +104,17 @@ def _get_checkpoint_times(domain_name, checkpoint_dir):

#times.sort()
#times = set(times)

#print times
combined = times
for cpu in range(numprocs):
if myid != cpu:
send(times,cpu)
rec = receive(cpu)
rec = receive(cpu)
#print rec
combined = combined & rec
combined = combined & rec

#combined = list(combined).sort()
#print combined

return combined

0 comments on commit 98848dc

Please sign in to comment.