Skip to content

Commit 6de8e6e

Browse files
committed
Improvements to Solution initialization.
See clawpack#635.
1 parent eaec788 commit 6de8e6e

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/pyclaw/solution.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Solution(object):
5656
- (:class:`~pyclaw.geometry.Dimension`) - A domain and
5757
patch is created with the dimensions or list of
5858
dimensions provided.
59-
3. `args` is a variable number of arguments that describes the
59+
3. `args` is a variable number of keyword arguments that describes the
6060
location of a file to be read in to initialize the object
6161
6262
:Examples:
@@ -140,17 +140,14 @@ def get_clawpack_dot_xxx(modname): return modname.rpartition('.')[0]
140140
frame = arg[0]
141141
if not isinstance(frame,int):
142142
raise Exception('Invalid pyclaw.Solution object initialization')
143-
if 'count_from_zero' in list(kargs.keys()) and\
144-
kargs['count_from_zero'] == True:
145-
self._start_frame = 0
146-
else:
147-
self._start_frame = frame
148-
try:
143+
if ('count_from_zero' in kargs):
144+
if (kargs['count_from_zero'] == True):
145+
self._start_frame = 0
146+
else:
147+
self._start_frame = frame
149148
kargs.pop('count_from_zero')
150-
except KeyError:
151-
pass
152-
153149
self.read(frame,**kargs)
150+
154151
elif len(arg) == 2:
155152
#Set domain
156153
if isinstance(arg[1],Domain):
@@ -163,7 +160,7 @@ def get_clawpack_dot_xxx(modname): return modname.rpartition('.')[0]
163160
elif isinstance(arg[1][0],Patch):
164161
self.domain = Domain(arg[1])
165162
else:
166-
raise Exception("Invalid argument list")
163+
raise Exception("Invalid arguments for Solution initialization.")
167164

168165
#Set state
169166
if isinstance(arg[0],State):
@@ -176,11 +173,16 @@ def get_clawpack_dot_xxx(modname): return modname.rpartition('.')[0]
176173
elif isinstance(arg[0][0],int):
177174
self.states = State(self.domain,arg[0][0],arg[0][1])
178175
else:
179-
raise Exception("Invalid argument list")
176+
raise Exception("Invalid arguments for Solution initialization.")
180177
elif isinstance(arg[0],int):
181178
self.states.append(State(self.domain,arg[0]))
182179
if self.states == [] or self.domain is None:
183-
raise Exception("Invalid argument list")
180+
raise Exception("Invalid arguments for Solution initialization.")
181+
elif len(arg) == 0 and 'frame' in kargs:
182+
frame = kargs.pop('frame')
183+
self.read(frame,**kargs)
184+
else:
185+
raise Exception("Invalid arguments for Solution initialization.")
184186

185187

186188
def is_valid(self):

0 commit comments

Comments
 (0)