diff --git a/src/petclaw/io/petsc.py b/src/petclaw/io/petsc.py index 217d0dff3..f89f5a45e 100644 --- a/src/petclaw/io/petsc.py +++ b/src/petclaw/io/petsc.py @@ -176,7 +176,7 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=False,options={}): dimensions = [] for i in xrange(num_dim): dimensions.append( - petclaw.Dimension(names[i],lower[i],lower[i] + n[i]*d[i],n[i])) + petclaw.Dimension(lower[i],lower[i] + n[i]*d[i],n[i],name=names[i])) patch = petclaw.Patch(dimensions) patch.level = level state = petclaw.State(patch,num_eqn,num_aux) diff --git a/src/pyclaw/geometry.py b/src/pyclaw/geometry.py index 20212d7c1..f509d0645 100644 --- a/src/pyclaw/geometry.py +++ b/src/pyclaw/geometry.py @@ -49,8 +49,8 @@ class Grid(object): A PyClaw grid is usually constructed from a tuple of PyClaw Dimension objects: >>> from clawpack.pyclaw.geometry import Dimension, Grid - >>> x = Dimension('x',0.,1.,10) - >>> y = Dimension('y',-1.,1.,25) + >>> x = Dimension(0.,1.,10,name='x') + >>> y = Dimension(-1.,1.,25,name='y') >>> grid = Grid((x,y)) >>> print grid 2-dimensional domain (x,y) @@ -71,7 +71,7 @@ class Grid(object): A grid can be extended to higher dimensions using the add_dimension() method: - >>> z=Dimension('z',-2.0,2.0,21) + >>> z=Dimension(-2.0,2.0,21,name='z') >>> grid.add_dimension(z) >>> grid.num_dim 3 @@ -83,11 +83,13 @@ class Grid(object): We can get the x, y, and z-coordinate arrays of cell edges and centers from the grid. Properties beginning with 'c' refer to the computational (unmapped) domain, while properties beginning with 'p' refer to the physical (mapped) domain. For grids with - no mapping, the two are identical. Notice also the difference between 'center' and - 'centers': + no mapping, the two are identical. Also note the difference between 'center' and + 'centers'. - >>> grid.p_center([1,2,3]) - [0.15000000000000002, -0.80000000000000004, -1.3333333333333335] + >>> import numpy as np + >>> np.set_printoptions(precision=2) # avoid doctest issues with roundoff + >>> grid.c_center([1,2,3]) + array([ 0.15, -0.8 , -1.33]) >>> grid.p_edges[0][0,0,0] 0.0 >>> grid.p_edges[1][0,0,0] @@ -97,7 +99,7 @@ class Grid(object): It's also possible to get coordinates for ghost cell arrays: - >>> x = Dimension('x',0.,1.,5) + >>> x = Dimension(0.,1.,5,name='x') >>> grid1d = Grid([x]) >>> grid1d.c_centers [array([ 0.1, 0.3, 0.5, 0.7, 0.9])] @@ -110,7 +112,7 @@ class Grid(object): or to adjust the local spacing of grid cells. For instance, we can use smaller cells on the left and larger cells on the right by doing: - >>> double = lambda x : x[0]**2 + >>> double = lambda xarr : np.array([x**2 for x in xarr]) >>> grid1d.mapc2p = double >>> grid1d.p_centers array([ 0.01, 0.09, 0.25, 0.49, 0.81]) @@ -222,8 +224,6 @@ def __init__(self,dimensions): for dim in dimensions: self.add_dimension(dim) - self.mapc2p = identity_map[str(self.num_dim)] - super(Grid,self).__init__() def _clear_cached_values(self): @@ -250,6 +250,8 @@ def add_dimension(self,dimension): self._dimensions.append(dimension.name) setattr(self,dimension.name,dimension) self._clear_cached_values() + # Reset mapping as it presumably makes no sense now + self.mapc2p = identity_map[str(self.num_dim)] def get_dim_attribute(self,attr): @@ -264,7 +266,7 @@ def __copy__(self): def __str__(self): output = "%s-dimensional domain " % str(self.num_dim) output += "("+",".join([dim.name for dim in self.dimensions])+")\n" - if self.mapc2p == identity_map: + if self.mapc2p in identity_map.values(): output += "No mapping\n" output += "Extent: " else: @@ -331,7 +333,7 @@ def c_center(self,ind): r"""Compute center of computational cell with index ind.""" index = [np.array(i) for i in ind] - return [self.c_centers[i][index] for i in range(self.num_dim)] + return np.array([self.c_centers[i][index] for i in range(self.num_dim)]) def p_center(self,ind): r"""Compute center of physical cell with index ind.""" diff --git a/src/pyclaw/io/ascii.py b/src/pyclaw/io/ascii.py index d2176b8ba..adf3162eb 100755 --- a/src/pyclaw/io/ascii.py +++ b/src/pyclaw/io/ascii.py @@ -225,7 +225,8 @@ def read(solution,frame,path='./',file_prefix='fort',read_aux=False, names = ['x','y','z'] import clawpack.pyclaw as pyclaw Dim = pyclaw.Dimension - dimensions = [Dim(names[i],lower[i],lower[i] + n[i]*d[i],n[i]) for i in xrange(num_dim)] + dimensions = [Dim(lower[i],lower[i] + n[i]*d[i],n[i],name=names[i]) \ + for i in xrange(num_dim)] patch = pyclaw.geometry.Patch(dimensions) state= pyclaw.state.State(patch,num_eqn,num_aux) state.t = t diff --git a/src/pyclaw/io/binary.py b/src/pyclaw/io/binary.py index 7f2d6103d..837fac215 100755 --- a/src/pyclaw/io/binary.py +++ b/src/pyclaw/io/binary.py @@ -97,7 +97,7 @@ def read(solution,frame,path='./',file_prefix='fort',read_aux=False, dimensions = [] for i in xrange(num_dim): dimensions.append( - pyclaw.geometry.Dimension(names[i],lower[i],lower[i] + n[i]*d[i],n[i])) + pyclaw.geometry.Dimension(lower[i],lower[i] + n[i]*d[i],n[i]),name=names[i]) patch = pyclaw.geometry.Patch(dimensions) state= pyclaw.state.State(patch,num_eqn,num_aux) state.t = t diff --git a/src/pyclaw/io/hdf5.py b/src/pyclaw/io/hdf5.py index 0f87ba155..cdfc1660e 100644 --- a/src/pyclaw/io/hdf5.py +++ b/src/pyclaw/io/hdf5.py @@ -210,10 +210,11 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=True, dim_names = patch.attrs['dimensions'] for dim_name in dim_names: # Create dimension - dim = pyclaw.solution.Dimension(dim_name, + dim = pyclaw.solution.Dimension( patch.attrs["%s.lower" % dim_name], patch.attrs["%s.upper" % dim_name], - patch.attrs["%s.num_cells" % dim_name]) + patch.attrs["%s.num_cells" % dim_name], + name = dim_name) # Optional attributes for attr in ['bc_lower','bc_upper','units']: attr_name = "%s.%s" % (dim_name,attr) diff --git a/src/pyclaw/io/netcdf.py b/src/pyclaw/io/netcdf.py index 0fd9ec488..803225947 100644 --- a/src/pyclaw/io/netcdf.py +++ b/src/pyclaw/io/netcdf.py @@ -280,10 +280,11 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=True, # Read in dimension attribute to keep dimension order dim_names = getattr(subgroup,'dim_names') for dim_name in dim_names: - dim = pyclaw.solution.Dimension(dim_name, + dim = pyclaw.solution.Dimension( getattr(subgroup,'%s.lower' % dim_name), getattr(subgroup,'%s.upper' % dim_name), - getattr(subgroup,'%s.n' % dim_name)) + getattr(subgroup,'%s.n' % dim_name), + name = dim_name) # Optional attributes for attr in ['bc_lower','bc_upper','units']: attr_name = "%s.%s" % (dim_name,attr)