Navigation Menu

Skip to content

Commit

Permalink
Allow specification of Riemann solver at Solver initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
ketch committed Apr 1, 2012
1 parent b0b9cea commit e56dfe4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
8 changes: 2 additions & 6 deletions apps/euler_2d/euler_2d.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/euler_2d/setplot.py
Expand Up @@ -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?
Expand Down
16 changes: 8 additions & 8 deletions src/pyclaw/clawpack/clawpack.py
Expand Up @@ -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.
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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 =====================================
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions src/pyclaw/sharpclaw/sharpclaw.py
Expand Up @@ -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__().
"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion src/pyclaw/solver.py
Expand Up @@ -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
Expand Down Expand Up @@ -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__()
Expand Down

0 comments on commit e56dfe4

Please sign in to comment.