Permalink
Browse files

Merge pull request #159 from ketch/init-solver

Allow specification of Riemann solver at Solver initialization.
  • Loading branch information...
2 parents b0b9cea + e56dfe4 commit aa1248d6af388a3b54be5d17372562fa0f3237ba @ketch ketch committed Apr 1, 2012
@@ -7,17 +7,13 @@
import pyclaw
import riemann
-solver = pyclaw.ClawSolver2D()
-solver.rp = riemann.rp2_euler_4wave
-solver.num_waves = 4
-num_eqn = 4
+solver = pyclaw.ClawSolver2D(riemann.rp2_euler_4wave)
solver.all_bcs = pyclaw.BC.extrap
domain = pyclaw.Domain([0.,0.],[1.,1.],[100,100])
-solution = pyclaw.Solution(num_eqn,domain)
+solution = pyclaw.Solution(solver.num_eqn,domain)
gamma = 1.4
solution.problem_data['gamma'] = gamma
-solution.problem_data['gamma1'] = gamma - 1
# Set initial data
xx,yy = domain.grid.p_centers
View
@@ -61,7 +61,7 @@ def setplot(plotdata):
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
plotitem.pcolor_cmin = 0.
plotitem.pcolor_cmax=1.0
- plotitem.plot_var = 4
+ plotitem.plot_var = 3
plotitem.pcolor_cmap = colormaps.yellow_red_blue
plotitem.add_colorbar = False
plotitem.show = True # show on plot?
@@ -75,7 +75,7 @@ def before_step(solver,solution)
- (:class:`ClawSolver`) - Initialized clawpack solver
"""
# ========== Generic Init Routine ========================================
- def __init__(self,claw_package=None):
+ def __init__(self,riemann_solver=None,claw_package=None):
r"""
See :class:`ClawSolver` for full documentation.
"""
@@ -94,7 +94,7 @@ def __init__(self,claw_package=None):
self._method = None
# Call general initialization function
- super(ClawSolver,self).__init__(claw_package)
+ super(ClawSolver,self).__init__(riemann_solver,claw_package)
# ========== Time stepping routines ======================================
def step(self,solution):
@@ -264,15 +264,15 @@ class ClawSolver1D(ClawSolver):
- (:class:`ClawSolver1D`) - Initialized 1d clawpack solver
"""
- def __init__(self):
+ def __init__(self,riemann_solver=None):
r"""
Create 1d Clawpack solver
See :class:`ClawSolver1D` for more info.
"""
self.num_dim = 1
- super(ClawSolver1D,self).__init__()
+ super(ClawSolver1D,self).__init__(riemann_solver)
# ========== Homogeneous Step =====================================
@@ -429,7 +429,7 @@ class ClawSolver2D(ClawSolver):
trans_inc = 1
trans_cor = 2
- def __init__(self):
+ def __init__(self,riemann_solver=None):
r"""
Create 2d Clawpack solver
@@ -445,7 +445,7 @@ def __init__(self):
self.aux3 = None
self.work = None
- super(ClawSolver2D,self).__init__()
+ super(ClawSolver2D,self).__init__(riemann_solver)
def check_cfl_settings(self):
if (not self.dimensional_split) and (self.transverse_waves==0):
@@ -583,7 +583,7 @@ class ClawSolver3D(ClawSolver):
trans_inc = 11
trans_cor = 22
- def __init__(self):
+ def __init__(self,riemann_solver=None):
r"""
Create 3d Clawpack solver
@@ -600,7 +600,7 @@ def __init__(self):
self.aux3 = None
self.work = None
- super(ClawSolver3D,self).__init__()
+ super(ClawSolver3D,self).__init__(riemann_solver)
# ========== Setup routine =============================
def allocate_workspace(self,solution):
@@ -118,7 +118,7 @@ def before_step(solver,solution)
# ========================================================================
# Initialization routines
# ========================================================================
- def __init__(self):
+ def __init__(self,riemann_solver=None,claw_package=None):
r"""
Set default options for SharpClawSolvers and call the super's __init__().
"""
@@ -141,7 +141,7 @@ def __init__(self):
self._rk_stages = None
# Call general initialization function
- super(SharpClawSolver,self).__init__()
+ super(SharpClawSolver,self).__init__(riemann_solver,claw_package)
def setup(self,solution):
"""
@@ -344,12 +344,12 @@ class SharpClawSolver1D(SharpClawSolver):
Used to solve 1D hyperbolic systems using the SharpClaw algorithms,
which are based on WENO reconstruction and Runge-Kutta time stepping.
"""
- def __init__(self):
+ def __init__(self,riemann_solver=None,claw_package=None):
r"""
See :class:`SharpClawSolver1D` for more info.
"""
self.num_dim = 1
- super(SharpClawSolver1D,self).__init__()
+ super(SharpClawSolver1D,self).__init__(riemann_solver,claw_package)
def teardown(self):
@@ -484,15 +484,15 @@ class SharpClawSolver2D(SharpClawSolver):
This class represents the 2D SharpClaw solver. Note that there are
routines here for interfacing with the fortran time stepping routines only.
"""
- def __init__(self):
+ def __init__(self,riemann_solver=None,claw_package=None):
r"""
Create 2D SharpClaw solver
See :class:`SharpClawSolver2D` for more info.
"""
self.num_dim = 2
- super(SharpClawSolver2D,self).__init__()
+ super(SharpClawSolver2D,self).__init__(riemann_solver,claw_package)
def teardown(self):
View
@@ -138,7 +138,7 @@ def all_bcs(self,all_bcs):
# ======================================================================
# Initialization routines
# ======================================================================
- def __init__(self,claw_package=None):
+ def __init__(self,riemann_solver=None,claw_package=None):
r"""
Initialize a Solver object
@@ -202,6 +202,13 @@ def __init__(self,claw_package=None):
r""" Array to hold ghost cell values. This is the one that gets passed
to the Fortran code. """
+ if riemann_solver is not None:
+ self.rp = riemann_solver
+ rp_name = riemann_solver.__name__.split('.')[-1]
+ import riemann
+ self.num_eqn = riemann.static.num_eqn[rp_name]
+ self.num_waves = riemann.static.num_waves[rp_name]
+
self._isinitialized = True
super(Solver,self).__init__()

0 comments on commit aa1248d

Please sign in to comment.