Skip to content

Instantly share code, notes, and snippets.

@ketch
Created June 7, 2015 11:23
Show Gist options
  • Save ketch/7ed022939faf47f00e9a to your computer and use it in GitHub Desktop.
Save ketch/7ed022939faf47f00e9a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
import numpy as np
def setup(use_petsc=False,outdir='./_output',solver_type='classic'):
from clawpack import riemann
from clawpack import pyclaw
#solver = pyclaw.ClawSolver2D(riemann.vc_advection_2D)
solver = pyclaw.SharpClawSolver2D(riemann.vc_advection_2D)
solver.bc_lower[0] = pyclaw.BC.extrap
solver.bc_upper[0] = pyclaw.BC.extrap
solver.bc_lower[1] = pyclaw.BC.extrap
solver.bc_upper[1] = pyclaw.BC.extrap
solver.aux_bc_lower[0] = pyclaw.BC.extrap
solver.aux_bc_upper[0] = pyclaw.BC.extrap
solver.aux_bc_lower[1] = pyclaw.BC.extrap
solver.aux_bc_upper[1] = pyclaw.BC.extrap
domain = pyclaw.Domain([-1,-1],[1,1],[100,100])
num_eqn = 1
num_aux = 3
state = pyclaw.State(domain,num_eqn,num_aux)
x0 = -0.3
y0 = -0.2
X, Y = domain.grid.p_centers
state.q[0,:,:] = np.exp(-100*((X-x0)**2+(Y-y0)**2))
X, Y = domain.grid.p_nodes
state.aux[0,:,:] = -Y[:-1,:-1]
state.aux[1,:,:] = X[:-1,:-1]
state.aux[2,:,:] = 1.
claw = pyclaw.Controller()
claw.tfinal = 2*np.pi
claw.num_output_times = 30
claw.solution = pyclaw.Solution(state,domain)
claw.solver = solver
claw.outdir = outdir
claw.setplot = setplot
claw.keep_copy = True
return claw
def setplot(plotdata):
"""
Plot solution using VisClaw.
"""
import numpy as np
from clawpack.visclaw import colormaps
plotdata.clearfigures() # clear any old figures,axes,items data
# Figure for contour plot
plotfigure = plotdata.new_plotfigure(name='contour', figno=0)
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
plotaxes.xlimits = 'auto'
plotaxes.ylimits = 'auto'
plotaxes.title = 'q[0]'
plotaxes.scaled = True
# Set up for item on these axes:
plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
plotitem.plot_var = 0
plotitem.contour_levels = np.linspace(-0.9, 0.9, 10)
plotitem.contour_colors = 'k'
plotitem.patchedges_show = 1
# Figure for pcolor plot
plotfigure = plotdata.new_plotfigure(name='q[0]', figno=1)
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
plotaxes.xlimits = 'auto'
plotaxes.ylimits = 'auto'
plotaxes.title = 'q[0]'
plotaxes.scaled = True
# Set up for item on these axes:
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
plotitem.plot_var = 0
plotitem.pcolor_cmap = colormaps.red_yellow_blue
plotitem.pcolor_cmin = -1.
plotitem.pcolor_cmax = 1.
plotitem.add_colorbar = True
return plotdata
if __name__=="__main__":
from clawpack.pyclaw.util import run_app_from_main
output = run_app_from_main(setup,setplot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment