Skip to content

Commit

Permalink
Merge pull request #636 from ketch/sol_init
Browse files Browse the repository at this point in the history
Improvements to Solution initialization.
  • Loading branch information
mandli authored Nov 10, 2019
2 parents eaec788 + 098dc3b commit 36df2b7
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/pyclaw/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Solution(object):
- (:class:`~pyclaw.geometry.Dimension`) - A domain and
patch is created with the dimensions or list of
dimensions provided.
3. `args` is a variable number of arguments that describes the
3. `args` is a variable number of keyword arguments that describes the
location of a file to be read in to initialize the object
:Examples:
Expand Down Expand Up @@ -140,17 +140,14 @@ def get_clawpack_dot_xxx(modname): return modname.rpartition('.')[0]
frame = arg[0]
if not isinstance(frame,int):
raise Exception('Invalid pyclaw.Solution object initialization')
if 'count_from_zero' in list(kargs.keys()) and\
kargs['count_from_zero'] == True:
self._start_frame = 0
else:
self._start_frame = frame
try:
if ('count_from_zero' in kargs):
if (kargs['count_from_zero'] == True):
self._start_frame = 0
else:
self._start_frame = frame
kargs.pop('count_from_zero')
except KeyError:
pass

self.read(frame,**kargs)

elif len(arg) == 2:
#Set domain
if isinstance(arg[1],Domain):
Expand All @@ -163,7 +160,7 @@ def get_clawpack_dot_xxx(modname): return modname.rpartition('.')[0]
elif isinstance(arg[1][0],Patch):
self.domain = Domain(arg[1])
else:
raise Exception("Invalid argument list")
raise Exception("Invalid arguments for Solution initialization.")

#Set state
if isinstance(arg[0],State):
Expand All @@ -176,11 +173,21 @@ def get_clawpack_dot_xxx(modname): return modname.rpartition('.')[0]
elif isinstance(arg[0][0],int):
self.states = State(self.domain,arg[0][0],arg[0][1])
else:
raise Exception("Invalid argument list")
raise Exception("Invalid arguments for Solution initialization.")
elif isinstance(arg[0],int):
self.states.append(State(self.domain,arg[0]))
if self.states == [] or self.domain is None:
raise Exception("Invalid argument list")
raise Exception("Invalid arguments for Solution initialization.")
elif len(arg) == 0:
if 'frame' in kargs:
frame = kargs.pop('frame')
self.read(frame,**kargs)
elif not kargs:
pass # With no arguments, initialize empty solution
else:
raise Exception("Invalid arguments for Solution initialization.")
else:
raise Exception("Invalid arguments for Solution initialization.")


def is_valid(self):
Expand Down

0 comments on commit 36df2b7

Please sign in to comment.