diff --git a/examples/psystem_2d/psystem_2d.py b/examples/psystem_2d/psystem_2d.py index 9d9b67ea7..fdb46040b 100755 --- a/examples/psystem_2d/psystem_2d.py +++ b/examples/psystem_2d/psystem_2d.py @@ -141,8 +141,8 @@ def setup(kernel_language='Fortran', x_lower=0.25; x_upper=20.25 y_lower=0.25; y_upper=20.25 # cells per layer - mx=(x_upper-x_lower)*cells_per_layer; - my=(y_upper-y_lower)*cells_per_layer + mx=int((x_upper-x_lower)*cells_per_layer) + my=int((y_upper-y_lower)*cells_per_layer) # Initial condition parameters initial_amplitude=10. x0=0.25 # Center of initial perturbation diff --git a/src/pyclaw/geometry.py b/src/pyclaw/geometry.py index efd6152ca..1430daa02 100644 --- a/src/pyclaw/geometry.py +++ b/src/pyclaw/geometry.py @@ -470,7 +470,7 @@ class Dimension(object): :Initialization: - Required arguments, order: + Required arguments, in order: - *lower* - (float) Lower extent of dimension - *upper* - (float) Upper extent of dimension - *num_cells* - (int) Number of cells @@ -578,52 +578,36 @@ def edges_with_ghost(self,num_ghost): return np.hstack((pre,edges,post)) - def __init__(self, *args, **kargs): + def __init__(self, lower, upper, num_cells, name='x', + on_lower_boundary=None,on_upper_boundary=None, units=None): r""" Create a Dimension object. - + See :class:`Dimension` for full documentation """ - - # ========== Class Data Attributes =================================== - self.name = 'x' - r"""(string) Name of this coordinate dimension (e.g. 'x')""" - self.on_lower_boundary = None - r"""(bool) - Whether the dimension is touching a lower boundary.""" - self.on_upper_boundary = None - r"""(bool) - Whether the dimension is touching an upper boundary.""" - self.units = None - r"""(string) Corresponding physical units of this dimension (e.g. - 'm/s'), ``default = None``""" + if isinstance(lower,basestring): + raise Exception('Passing dimension name as first argument is deprecated. \ + Pass it as a keyword argument instead.') self._edges = None self._centers = None self._centers_with_ghost = None self._edges_with_ghost = None - # Parse args - if isinstance(args[0],basestring): - import warnings - warnings.warn('Passing dimension name as first argument is deprecated. \ - Pass it as a keyword argument instead.') - self.name = args[0] - self._lower = float(args[1]) - self._upper = float(args[2]) - self._num_cells = int(args[3]) - else: - self._lower = float(args[0]) - self._upper = float(args[1]) - self._num_cells = int(args[2]) - - for (k,v) in kargs.iteritems(): - setattr(self,k,v) + self._lower = float(lower) + self._upper = float(upper) + self._num_cells = int(num_cells) + self.name = name + self.on_lower_boundary = on_lower_boundary + self.on_upper_boundary = on_upper_boundary + self.units = units self._check_validity() def _check_validity(self): - assert type(self.num_cells) is int, 'Dimension.num_cells must be an integer' - assert type(self.lower) is float, 'Dimension.lower must be a float' - assert type(self.upper) is float, 'Dimension.upper must be a float' + assert isinstance(self.num_cells,int), 'Dimension.num_cells must be an integer; got %s' % type(self.num_cells) + assert isinstance(self.lower,float), 'Dimension.lower must be a float' + assert isinstance(self.upper,float), 'Dimension.upper must be a float' assert self.num_cells>0, 'Dimension.num_cells must be positive' assert self.upper > self.lower, 'Dimension.upper must be greater than lower' diff --git a/src/pyclaw/io/ascii.py b/src/pyclaw/io/ascii.py index 428310451..c4d2e581e 100755 --- a/src/pyclaw/io/ascii.py +++ b/src/pyclaw/io/ascii.py @@ -168,7 +168,7 @@ def read(solution,frame,path='./',file_prefix='fort',read_aux=False, [t,num_eqn,nstates,num_aux,num_dim] = read_t(frame,path,file_prefix) patches = [] - n = np.zeros((num_dim)) + n = np.zeros((num_dim),dtype=int) d = np.zeros((num_dim)) lower = np.zeros((num_dim)) # Since we do not have names here, we will construct each patch with diff --git a/src/pyclaw/io/binary.py b/src/pyclaw/io/binary.py index 6342e1adf..9e2c7594c 100755 --- a/src/pyclaw/io/binary.py +++ b/src/pyclaw/io/binary.py @@ -58,7 +58,7 @@ def read(solution,frame,path='./',file_prefix='fort',read_aux=False, qdata = np.fromfile(file=b_file, dtype=np.float64) i_start_patch = 0 # index into qdata for start of next patch - n = np.zeros((num_dim)) + n = np.zeros((num_dim),dtype=int) lower = np.zeros((num_dim)) d = np.zeros((num_dim)) # Since we do not have dimension names here, we will construct diff --git a/src/pyclaw/util.py b/src/pyclaw/util.py index 78d926584..510f82f55 100755 --- a/src/pyclaw/util.py +++ b/src/pyclaw/util.py @@ -536,12 +536,12 @@ def read_data_line(inputfile,num_entries=1,data_type=float): while l==[]: # skip over blank lines line = inputfile.readline() l = line.split() + if num_entries == 1: # This is a convenience for calling functions + return data_type(l[0]) val = np.empty(num_entries,data_type) if num_entries > len(l): print 'Error in read_data_line: num_entries = ', num_entries print ' is larger than length of l = ',l - if num_entries == 1: # This is a convenience for calling functions - return data_type(l[0]) val = [data_type(entry) for entry in l[:num_entries]] return val