@@ -49,8 +49,8 @@ class Grid(object):
49
49
A PyClaw grid is usually constructed from a tuple of PyClaw Dimension objects:
50
50
51
51
>>> 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' )
54
54
>>> grid = Grid((x,y))
55
55
>>> print grid
56
56
2-dimensional domain (x,y)
@@ -71,7 +71,7 @@ class Grid(object):
71
71
72
72
A grid can be extended to higher dimensions using the add_dimension() method:
73
73
74
- >>> z=Dimension('z', -2.0,2.0,21)
74
+ >>> z=Dimension(-2.0,2.0,21,name='z' )
75
75
>>> grid.add_dimension(z)
76
76
>>> grid.num_dim
77
77
3
@@ -83,11 +83,13 @@ class Grid(object):
83
83
We can get the x, y, and z-coordinate arrays of cell edges and centers from the grid.
84
84
Properties beginning with 'c' refer to the computational (unmapped) domain, while
85
85
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'.
88
88
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])
91
93
>>> grid.p_edges[0][0,0,0]
92
94
0.0
93
95
>>> grid.p_edges[1][0,0,0]
@@ -97,7 +99,7 @@ class Grid(object):
97
99
98
100
It's also possible to get coordinates for ghost cell arrays:
99
101
100
- >>> x = Dimension('x', 0.,1.,5)
102
+ >>> x = Dimension(0.,1.,5,name='x' )
101
103
>>> grid1d = Grid([x])
102
104
>>> grid1d.c_centers
103
105
[array([ 0.1, 0.3, 0.5, 0.7, 0.9])]
@@ -110,7 +112,7 @@ class Grid(object):
110
112
or to adjust the local spacing of grid cells. For instance, we can
111
113
use smaller cells on the left and larger cells on the right by doing:
112
114
113
- >>> double = lambda x : x[0] **2
115
+ >>> double = lambda xarr : np.array([x **2 for x in xarr])
114
116
>>> grid1d.mapc2p = double
115
117
>>> grid1d.p_centers
116
118
array([ 0.01, 0.09, 0.25, 0.49, 0.81])
@@ -222,8 +224,6 @@ def __init__(self,dimensions):
222
224
for dim in dimensions :
223
225
self .add_dimension (dim )
224
226
225
- self .mapc2p = identity_map [str (self .num_dim )]
226
-
227
227
super (Grid ,self ).__init__ ()
228
228
229
229
def _clear_cached_values (self ):
@@ -250,6 +250,8 @@ def add_dimension(self,dimension):
250
250
self ._dimensions .append (dimension .name )
251
251
setattr (self ,dimension .name ,dimension )
252
252
self ._clear_cached_values ()
253
+ # Reset mapping as it presumably makes no sense now
254
+ self .mapc2p = identity_map [str (self .num_dim )]
253
255
254
256
255
257
def get_dim_attribute (self ,attr ):
@@ -264,7 +266,7 @@ def __copy__(self):
264
266
def __str__ (self ):
265
267
output = "%s-dimensional domain " % str (self .num_dim )
266
268
output += "(" + "," .join ([dim .name for dim in self .dimensions ])+ ")\n "
267
- if self .mapc2p == identity_map :
269
+ if self .mapc2p in identity_map . values () :
268
270
output += "No mapping\n "
269
271
output += "Extent: "
270
272
else :
@@ -331,7 +333,7 @@ def c_center(self,ind):
331
333
r"""Compute center of computational cell with index ind."""
332
334
333
335
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 )])
335
337
336
338
def p_center (self ,ind ):
337
339
r"""Compute center of physical cell with index ind."""
0 commit comments