@@ -49,8 +49,8 @@ class Grid(object):
4949 A PyClaw grid is usually constructed from a tuple of PyClaw Dimension objects:
5050
5151 >>> from clawpack.pyclaw.geometry import Dimension, Grid
52- >>> x = Dimension('x', 0.,1.,10)
53- >>> y = Dimension('y', -1.,1.,25)
52+ >>> x = Dimension(0.,1.,10,name='x' )
53+ >>> y = Dimension(-1.,1.,25,name='y' )
5454 >>> grid = Grid((x,y))
5555 >>> print grid
5656 2-dimensional domain (x,y)
@@ -71,7 +71,7 @@ class Grid(object):
7171
7272 A grid can be extended to higher dimensions using the add_dimension() method:
7373
74- >>> z=Dimension('z', -2.0,2.0,21)
74+ >>> z=Dimension(-2.0,2.0,21,name='z' )
7575 >>> grid.add_dimension(z)
7676 >>> grid.num_dim
7777 3
@@ -83,11 +83,13 @@ class Grid(object):
8383 We can get the x, y, and z-coordinate arrays of cell edges and centers from the grid.
8484 Properties beginning with 'c' refer to the computational (unmapped) domain, while
8585 properties beginning with 'p' refer to the physical (mapped) domain. For grids with
86- no mapping, the two are identical. Notice also the difference between 'center' and
87- 'centers':
86+ no mapping, the two are identical. Also note the difference between 'center' and
87+ 'centers'.
8888
89- >>> grid.p_center([1,2,3])
90- [0.15000000000000002, -0.80000000000000004, -1.3333333333333335]
89+ >>> import numpy as np
90+ >>> np.set_printoptions(precision=2) # avoid doctest issues with roundoff
91+ >>> grid.c_center([1,2,3])
92+ array([ 0.15, -0.8 , -1.33])
9193 >>> grid.p_edges[0][0,0,0]
9294 0.0
9395 >>> grid.p_edges[1][0,0,0]
@@ -97,7 +99,7 @@ class Grid(object):
9799
98100 It's also possible to get coordinates for ghost cell arrays:
99101
100- >>> x = Dimension('x', 0.,1.,5)
102+ >>> x = Dimension(0.,1.,5,name='x' )
101103 >>> grid1d = Grid([x])
102104 >>> grid1d.c_centers
103105 [array([ 0.1, 0.3, 0.5, 0.7, 0.9])]
@@ -110,7 +112,7 @@ class Grid(object):
110112 or to adjust the local spacing of grid cells. For instance, we can
111113 use smaller cells on the left and larger cells on the right by doing:
112114
113- >>> double = lambda x : x[0] **2
115+ >>> double = lambda xarr : np.array([x **2 for x in xarr])
114116 >>> grid1d.mapc2p = double
115117 >>> grid1d.p_centers
116118 array([ 0.01, 0.09, 0.25, 0.49, 0.81])
@@ -222,8 +224,6 @@ def __init__(self,dimensions):
222224 for dim in dimensions :
223225 self .add_dimension (dim )
224226
225- self .mapc2p = identity_map [str (self .num_dim )]
226-
227227 super (Grid ,self ).__init__ ()
228228
229229 def _clear_cached_values (self ):
@@ -250,6 +250,8 @@ def add_dimension(self,dimension):
250250 self ._dimensions .append (dimension .name )
251251 setattr (self ,dimension .name ,dimension )
252252 self ._clear_cached_values ()
253+ # Reset mapping as it presumably makes no sense now
254+ self .mapc2p = identity_map [str (self .num_dim )]
253255
254256
255257 def get_dim_attribute (self ,attr ):
@@ -264,7 +266,7 @@ def __copy__(self):
264266 def __str__ (self ):
265267 output = "%s-dimensional domain " % str (self .num_dim )
266268 output += "(" + "," .join ([dim .name for dim in self .dimensions ])+ ")\n "
267- if self .mapc2p == identity_map :
269+ if self .mapc2p in identity_map . values () :
268270 output += "No mapping\n "
269271 output += "Extent: "
270272 else :
@@ -331,7 +333,7 @@ def c_center(self,ind):
331333 r"""Compute center of computational cell with index ind."""
332334
333335 index = [np .array (i ) for i in ind ]
334- return [self .c_centers [i ][index ] for i in range (self .num_dim )]
336+ return np . array ( [self .c_centers [i ][index ] for i in range (self .num_dim )])
335337
336338 def p_center (self ,ind ):
337339 r"""Compute center of physical cell with index ind."""
0 commit comments