Skip to content

Commit

Permalink
Merge cd64883 into 5f54fe1
Browse files Browse the repository at this point in the history
  • Loading branch information
ketch committed Dec 30, 2014
2 parents 5f54fe1 + cd64883 commit 8f73cd8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/pyclaw/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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

0 comments on commit 8f73cd8

Please sign in to comment.