Skip to content

Commit

Permalink
Merge 414250e into 9426db9
Browse files Browse the repository at this point in the history
  • Loading branch information
memmett committed Nov 10, 2014
2 parents 9426db9 + 414250e commit 157e235
Show file tree
Hide file tree
Showing 27 changed files with 783 additions and 25 deletions.
27 changes: 15 additions & 12 deletions examples/acoustics_1d_homogeneous/acoustics_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Solve the (linear) acoustics equations:
.. math::
p_t + K u_x & = 0 \\
.. math::
p_t + K u_x & = 0 \\
u_t + p_x / \rho & = 0.
Here p is the pressure, u is the velocity, K is the bulk modulus,
Expand All @@ -18,16 +18,19 @@
The final solution is identical to the initial data because both waves have
crossed the domain exactly once.
"""

from numpy import sqrt, exp, cos
from clawpack import riemann
def setup(use_petsc=False, kernel_language='Fortran', solver_type='classic',
outdir='./_output', ptwise=False, weno_order=5,
time_integrator='SSP104',

def setup(use_petsc=False, use_boxlib=False, kernel_language='Fortran', solver_type='classic',
outdir='./_output', ptwise=False, weno_order=5,
time_integrator='SSP104',
disable_output=False):

if use_petsc:
import clawpack.petclaw as pyclaw
elif use_boxlib:
import clawpack.boxclaw as pyclaw
else:
from clawpack import pyclaw

Expand All @@ -37,7 +40,7 @@ def setup(use_petsc=False, kernel_language='Fortran', solver_type='classic',
else:
riemann_solver = riemann.acoustics_1D

elif kernel_language=='Python':
elif kernel_language=='Python':
riemann_solver = riemann.acoustics_1D_py.acoustics_1D

if solver_type=='classic':
Expand Down Expand Up @@ -66,7 +69,7 @@ def setup(use_petsc=False, kernel_language='Fortran', solver_type='classic',
state.problem_data['bulk']=bulk
state.problem_data['zz']=sqrt(rho*bulk) # Impedance
state.problem_data['cc']=sqrt(bulk/rho) # Sound speed

xc=domain.grid.x.centers
beta=100; gamma=0; x0=0.75
state.q[0,:] = exp(-beta * (xc-x0)**2) * cos(gamma * (xc - x0))
Expand All @@ -89,11 +92,11 @@ def setup(use_petsc=False, kernel_language='Fortran', solver_type='classic',


def setplot(plotdata):
"""
"""
Specify what is to be plotted at each frame.
Input: plotdata, an instance of visclaw.data.ClawPlotData.
Output: a modified version of plotdata.
"""
"""
plotdata.clearfigures() # clear any old figures,axes,items data

# Figure for pressure
Expand All @@ -111,7 +114,7 @@ def setplot(plotdata):
plotitem.plotstyle = '-o'
plotitem.color = 'b'
plotitem.kwargs = {'linewidth':2,'markersize':5}

# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
plotaxes.axescmd = 'subplot(212)'
Expand All @@ -125,7 +128,7 @@ def setplot(plotdata):
plotitem.plotstyle = '-'
plotitem.color = 'b'
plotitem.kwargs = {'linewidth':3,'markersize':5}

return plotdata


Expand Down
14 changes: 11 additions & 3 deletions examples/acoustics_1d_homogeneous/test_acoustics.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def acoustics_verify(claw):
yield test


if __name__=="__main__":
import nose
nose.main()
if __name__=='__main__':
for test in test_1d_acoustics():
test()

# monkey patch util.build_variant_arg_dicts and rerun tests
import clawpack.pyclaw.util
import clawpack.boxclaw.util
clawpack.pyclaw.util.build_variant_arg_dicts = clawpack.boxclaw.util.boxlib_build_variant_arg_dicts

for test in test_1d_acoustics():
test()
6 changes: 4 additions & 2 deletions examples/acoustics_3d_variable/acoustics_3d_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
This example shows how to solve a problem with variable coefficients.
The left and right halves of the domain consist of different materials.
"""

import numpy as np

def setup(use_petsc=False,outdir='./_output',solver_type='classic',
def setup(use_petsc=False,use_boxlib=False,outdir='./_output',solver_type='classic',
mx=30,my=30,mz=30,disable_output=False,problem='heterogeneous',**kwargs):
"""
Example python script for solving the 3d acoustics equations.
Expand All @@ -30,6 +30,8 @@ def setup(use_petsc=False,outdir='./_output',solver_type='classic',

if use_petsc:
import clawpack.petclaw as pyclaw
elif use_boxlib:
import clawpack.boxclaw as pyclaw
else:
from clawpack import pyclaw

Expand Down
4 changes: 3 additions & 1 deletion examples/advection_1d/advection_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import numpy as np
from clawpack import riemann

def setup(nx=100, kernel_language='Python', use_petsc=False, solver_type='classic', weno_order=5,
def setup(nx=100, kernel_language='Python', use_petsc=False, use_boxlib=False, solver_type='classic', weno_order=5,
time_integrator='SSP104', outdir='./_output'):

if use_petsc:
import clawpack.petclaw as pyclaw
elif use_boxlib:
import clawpack.boxclaw as pyclaw
else:
from clawpack import pyclaw

Expand Down
16 changes: 12 additions & 4 deletions examples/advection_1d/test_advection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def advection_verify(claw):
solver_type='sharpclaw',time_integrator='SSPMS32', outdir=None)

weno_tests = gen_variants(advection_1d.setup, verify_expected(7.489618e-06),
kernel_languages=('Fortran',), solver_type='sharpclaw',
kernel_languages=('Fortran',), solver_type='sharpclaw',
time_integrator='SSP104', weno_order=17,
outdir=None)

Expand All @@ -46,6 +46,14 @@ def advection_verify(claw):
yield test


if __name__=="__main__":
import nose
nose.main()
if __name__=='__main__':
for test in test_1d_advection():
test()

# monkey patch util.build_variant_arg_dicts and rerun tests
import clawpack.pyclaw.util
import clawpack.boxclaw.util
clawpack.pyclaw.util.build_variant_arg_dicts = clawpack.boxclaw.util.boxlib_build_variant_arg_dicts

for test in test_1d_advection():
test()
6 changes: 4 additions & 2 deletions examples/advection_2d/advection_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def qinit(state):
"""
X, Y = state.grid.p_centers
state.q[0,:,:] = 0.9*(0.1<X)*(X<0.6)*(0.1<Y)*(Y<0.6) + 0.1


def setup(use_petsc=False,outdir='./_output',solver_type='classic'):

def setup(use_petsc=False,use_boxlib=False,outdir='./_output',solver_type='classic'):

if use_petsc:
import clawpack.petclaw as pyclaw
elif use_boxlib:
import clawpack.boxclaw as pyclaw
else:
from clawpack import pyclaw

Expand Down
17 changes: 17 additions & 0 deletions src/boxclaw/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

BoxLib backend for PyClaw
=========================

This backend uses the C++ version of the CCSE BoxLib_ library. To
install BoxLib, `download BoxLib`_ and

.. code-block:: sh
git clone https://ccse.lbl.gov/pub/Downloads/BoxLib.git
cd BoxLib/Src/Python
python setup.py install --user
.. _BoxLib: https://ccse.lbl.gov/BoxLib/index.html
.. _`download BoxLib`: https://ccse.lbl.gov/Downloads/downloadBoxLib.html

37 changes: 37 additions & 0 deletions src/boxclaw/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Main boxclaw package"""

import os
import logging, logging.config

# Default logging configuration file
_DEFAULT_LOG_CONFIG_PATH = os.path.join(os.path.dirname(__file__),'log.config')
del os

# Setup loggers
logging.config.fileConfig(_DEFAULT_LOG_CONFIG_PATH)

__all__ = []

# Module imports
__all__.extend(['Controller','Dimension','Patch','Domain','Solution','State','CFL','riemann'])
from .controller import Controller
from clawpack.boxclaw.geometry import Patch, Domain
from clawpack.pyclaw.geometry import Dimension
from .solution import Solution
from .state import State
from .cfl import CFL

__all__.extend(['ClawSolver1D','ClawSolver2D','ClawSolver3D','SharpClawSolver1D','SharpClawSolver2D','SharpClawSolver3D'])
from .classic.solver import ClawSolver1D,ClawSolver2D,ClawSolver3D
from .sharpclaw.solver import SharpClawSolver1D,SharpClawSolver2D,SharpClawSolver3D

__all__.append('BC')
from clawpack.pyclaw.solver import BC

# Sub-packages
import limiters
from limiters import *
__all__.extend(limiters.__all__)

import plot
__all__.append('plot')
32 changes: 32 additions & 0 deletions src/boxclaw/cfl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

class CFL(object):
"""Parallel CFL object, responsible for computing the
Courant-Friedrichs-Lewy condition across all processes.
"""

def __init__(self, global_max):
self._local_max = global_max
self._global_max = global_max

def get_global_max(self):
r"""
Compute the maximum CFL number over all processes for the current step.
This is used to determine whether the CFL condition was
violated and adjust the timestep.
"""
import boxlib
self._reduce_vec.array = self._local_max
self._global_max = boxlib.bl[0].ReduceRealMax(self._local_max)
return self._global_max

def get_cached_max(self):
return self._global_max

def set_local_max(self,new_local_max):
self._local_max = new_local_max

def update_global_max(self,new_local_max):
import boxlib
self._global_max = boxlib.bl[0].ReduceRealMax(new_local_max)

Empty file added src/boxclaw/classic/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions src/boxclaw/classic/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python

def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('classic', parent_package, top_path)
return config

if __name__ == '__main__':
from numpy.distutils.core import setup
setup(**configuration(top_path='').todict())
31 changes: 31 additions & 0 deletions src/boxclaw/classic/solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
r"""
Module containing the PetClaw solvers
This file currently only exists so that these solvers have a different
__module__ property, used by pyclaw.solver.Solver.__init__ to
determine the containing claw_package to use.
"""

from __future__ import absolute_import
from clawpack import pyclaw

class ClawSolver1D(pyclaw.ClawSolver1D):
r"""
Parallel solver for 1D problems using classic Clawpack algorithms.
"""

__doc__ += pyclaw.util.add_parent_doc(pyclaw.ClawSolver1D)

class ClawSolver2D(pyclaw.ClawSolver2D):
r"""
Parallel solver for 2D problems using classic Clawpack algorithms.
"""

__doc__ += pyclaw.util.add_parent_doc(pyclaw.ClawSolver2D)

class ClawSolver3D(pyclaw.ClawSolver3D):
r"""
Parallel solver for 3D problems using classic Clawpack algorithms.
"""

__doc__ += pyclaw.util.add_parent_doc(pyclaw.ClawSolver3D)
25 changes: 25 additions & 0 deletions src/boxclaw/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Module for BoxClaw controller class.
"""

from clawpack import pyclaw

class Controller(pyclaw.controller.Controller):
"""Parallel Controller Class"""

__doc__ += pyclaw.util.add_parent_doc(pyclaw.controller.Controller)

def __init__(self):
super(Controller,self).__init__()
self.output_format = 'multifab'

def is_proc_0(self):
import boxlib
return boxlib.rank() == 0

def log_info(self, str):
import logging
if self.is_proc_0():
logging.info(str)
else:
pass
Loading

0 comments on commit 157e235

Please sign in to comment.