Skip to content

Commit 5f6ee25

Browse files
committed
Merge branch 'master' into dev-poly
* 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.
2 parents 05f70bc + e20a787 commit 5f6ee25

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

src/petclaw/io/petsc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=False,options={}):
176176
dimensions = []
177177
for i in xrange(num_dim):
178178
dimensions.append(
179-
petclaw.Dimension(names[i],lower[i],lower[i] + n[i]*d[i],n[i]))
179+
petclaw.Dimension(lower[i],lower[i] + n[i]*d[i],n[i],name=names[i]))
180180
patch = petclaw.Patch(dimensions)
181181
patch.level = level
182182
state = petclaw.State(patch,num_eqn,num_aux)

src/pyclaw/geometry.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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."""

src/pyclaw/io/ascii.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ def read(solution,frame,path='./',file_prefix='fort',read_aux=False,
225225
names = ['x','y','z']
226226
import clawpack.pyclaw as pyclaw
227227
Dim = pyclaw.Dimension
228-
dimensions = [Dim(names[i],lower[i],lower[i] + n[i]*d[i],n[i]) for i in xrange(num_dim)]
228+
dimensions = [Dim(lower[i],lower[i] + n[i]*d[i],n[i],name=names[i]) \
229+
for i in xrange(num_dim)]
229230
patch = pyclaw.geometry.Patch(dimensions)
230231
state= pyclaw.state.State(patch,num_eqn,num_aux)
231232
state.t = t

src/pyclaw/io/binary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def read(solution,frame,path='./',file_prefix='fort',read_aux=False,
9797
dimensions = []
9898
for i in xrange(num_dim):
9999
dimensions.append(
100-
pyclaw.geometry.Dimension(names[i],lower[i],lower[i] + n[i]*d[i],n[i]))
100+
pyclaw.geometry.Dimension(lower[i],lower[i] + n[i]*d[i],n[i]),name=names[i])
101101
patch = pyclaw.geometry.Patch(dimensions)
102102
state= pyclaw.state.State(patch,num_eqn,num_aux)
103103
state.t = t

src/pyclaw/io/hdf5.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=True,
210210
dim_names = patch.attrs['dimensions']
211211
for dim_name in dim_names:
212212
# Create dimension
213-
dim = pyclaw.solution.Dimension(dim_name,
213+
dim = pyclaw.solution.Dimension(
214214
patch.attrs["%s.lower" % dim_name],
215215
patch.attrs["%s.upper" % dim_name],
216-
patch.attrs["%s.num_cells" % dim_name])
216+
patch.attrs["%s.num_cells" % dim_name],
217+
name = dim_name)
217218
# Optional attributes
218219
for attr in ['bc_lower','bc_upper','units']:
219220
attr_name = "%s.%s" % (dim_name,attr)

src/pyclaw/io/netcdf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,11 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=True,
280280
# Read in dimension attribute to keep dimension order
281281
dim_names = getattr(subgroup,'dim_names')
282282
for dim_name in dim_names:
283-
dim = pyclaw.solution.Dimension(dim_name,
283+
dim = pyclaw.solution.Dimension(
284284
getattr(subgroup,'%s.lower' % dim_name),
285285
getattr(subgroup,'%s.upper' % dim_name),
286-
getattr(subgroup,'%s.n' % dim_name))
286+
getattr(subgroup,'%s.n' % dim_name),
287+
name = dim_name)
287288
# Optional attributes
288289
for attr in ['bc_lower','bc_upper','units']:
289290
attr_name = "%s.%s" % (dim_name,attr)

0 commit comments

Comments
 (0)