Skip to content

Commit

Permalink
Merge branch 'master' into dev-poly
Browse files Browse the repository at this point in the history
* master:
  update petsc reader with new dimension syntax
  use keyword for name argument in doctests
  tweaks to geometry modifications
  Update I/O routines to reflect new Dimension initialization syntax.
  Update I/O routines to reflect new Dimension initialization syntax.
  • Loading branch information
ketch committed Dec 30, 2014
2 parents 05f70bc + e20a787 commit 5f6ee25
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/petclaw/io/petsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 15 additions & 13 deletions src/pyclaw/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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])]
Expand All @@ -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])
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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."""
Expand Down
3 changes: 2 additions & 1 deletion src/pyclaw/io/ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pyclaw/io/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/pyclaw/io/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/pyclaw/io/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5f6ee25

Please sign in to comment.