Skip to content

Commit

Permalink
Remove hdf5p file format and force parallel I/O when using petclaw
Browse files Browse the repository at this point in the history
  • Loading branch information
aymkhalil committed Nov 5, 2015
1 parent 2fc6ca9 commit 04ca0a9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
6 changes: 6 additions & 0 deletions src/petclaw/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@ def __init__(self,geom):
elif isinstance(geom[0],pyclaw_geometry.Dimension):
self.patches = [Patch(geom)]

class Dimension(pyclaw_geometry.Dimension):
def __init__(self, lower, upper, num_cells, name='x',
on_lower_boundary=None,on_upper_boundary=None, units=None):
super(Dimension, self).__init__(lower, upper, num_cells, name,
on_lower_boundary,on_upper_boundary, units)


16 changes: 8 additions & 8 deletions src/petclaw/io/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import logging

from clawpack import pyclaw
from clawpack.petclaw import geometry
from clawpack import petclaw

logger = logging.getLogger('pyclaw.io')
Expand Down Expand Up @@ -198,11 +198,11 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=True,
dimensions = []
dim_names = patch.attrs['dimensions']
for dim_name in dim_names:
dim = pyclaw.solution.Dimension(
patch.attrs["%s.lower" % dim_name],
patch.attrs["%s.upper" % dim_name],
patch.attrs["%s.num_cells" % dim_name],
name = dim_name)
dim = geometry.Dimension(
patch.attrs["%s.lower" % dim_name],
patch.attrs["%s.upper" % dim_name],
patch.attrs["%s.num_cells" % dim_name],
name = dim_name)
# Optional attributes
for attr in ['units']:
attr_name = "%s.%s" % (dim_name,attr)
Expand All @@ -216,7 +216,7 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=True,
for attr in ['t','num_eqn','patch_index','level']:
setattr(pyclaw_patch,attr,patch.attrs[attr])

state = pyclaw.state.State(pyclaw_patch, \
state = petclaw.state.State(pyclaw_patch, \
patch.attrs['num_eqn'],patch.attrs['num_aux'])
state.t = patch.attrs['t']

Expand Down Expand Up @@ -248,7 +248,7 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=True,
solution.states.append(state)
patches.append(pyclaw_patch)

solution.domain = pyclaw.geometry.Domain(patches)
solution.domain = geometry.Domain(patches)

elif use_PyTables:
# f = tables.openFile(filename, mode = "r", title = options['title'])
Expand Down
20 changes: 20 additions & 0 deletions src/petclaw/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,23 @@ class Solution(Solution):
""" Parallel Solution class.
"""
__doc__ += pyclaw.util.add_parent_doc(pyclaw.Solution)

def get_read_func(self, file_format):
from clawpack.petclaw import io
if file_format == 'petsc':
return io.petsc.read
elif file_format == 'hdf5':
return io.hdf5.read
else:
raise ValueError("File format %s not supported." % file_format)

def get_write_func(self, file_format):
from clawpack.petclaw import io
if 'petsc' in file_format:
return io.petsc.write
elif 'hdf5' in file_format:
return io.hdf5.write
else:
raise ValueError("File format %s not supported." % file_format)


48 changes: 19 additions & 29 deletions src/pyclaw/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def start_frame(self):
object is initialized by loading frame from file"""
return self._start_frame
_start_frame = 0


# ========== Class Methods ===============================================
def __init__(self,*arg,**kargs):
Expand Down Expand Up @@ -286,16 +286,7 @@ def write(self,frame,path='./',file_format='ascii',file_prefix=None,

# Loop over list of formats requested
for form in format_list:
if 'petsc' in form:
from clawpack.petclaw import io
write_func = io.petsc.write
elif 'hdf5p' in form:
from clawpack.petclaw import io
write_func = io.hdf5.write
else:
from clawpack.pyclaw import io
write_func = getattr(getattr(io,form),'write')

write_func = self.get_write_func(form)

if file_prefix is None:
write_func(self,frame,path,write_aux=write_aux,
Expand Down Expand Up @@ -340,23 +331,7 @@ def read(self, frame, path='./_output', file_format='ascii',
- (bool) - True if read was successful, False otherwise
"""

if file_format == 'petsc':
from clawpack.petclaw import io
read_func = io.petsc.read
elif file_format == 'binary':
from clawpack.pyclaw import io
read_func = io.binary.read
elif file_format == 'ascii':
from clawpack.pyclaw import io
read_func = io.ascii.read
elif file_format in ('hdf','hdf5'):
from clawpack.pyclaw import io
read_func = io.hdf5.read
elif file_format == 'hdf5p':
from clawpack.petclaw import io
read_func = io.hdf5.read
else:
raise ValueError("File format %s not supported." % file_format)
read_func = self.get_read_func(file_format)

path = os.path.expandvars(os.path.expanduser(path))
if file_prefix is None:
Expand All @@ -365,7 +340,22 @@ def read(self, frame, path='./_output', file_format='ascii',
read_func(self,frame,path,file_prefix=file_prefix,
read_aux=read_aux,options=options)
logging.getLogger('pyclaw.io').info("Read in solution for time t=%s" % self.t)


def get_read_func(self, file_format):
from clawpack.pyclaw import io
if file_format == 'binary':
return io.binary.read
elif file_format == 'ascii':
return io.ascii.read
elif file_format in ('hdf','hdf5'):
return io.hdf5.read
else:
raise ValueError("File format %s not supported." % file_format)

def get_write_func(self, file_format):
from clawpack.pyclaw import io
return getattr(getattr(io,file_format),'write')


def plot(self):
r"""
Expand Down

0 comments on commit 04ca0a9

Please sign in to comment.