setplot.py.html clawcode2html   
 Source file:   setplot.py
 Directory:   /Users/rjl/rjlsvn/papers/pathconwb10/code
 Converted:   Mon Jan 18 2010 at 10:11:18
 This documentation file will not reflect any later changes in the source file.

 

""" 
Set up the plot figures, axes, and items to be done for each frame.

This module is imported by the plotting routines and then the
function setplot is called to set the plot parameters.
    
""" 

# Set advection velocity:

import os
from pyclaw.data import Data

try:
    probdata = Data('setprob.data')
    u = probdata.u
except:
    print "*** Error reading u from setprob.data in ", os.getcwd()

# Import fcns module that should have been created using f2py and
# that defines the function qtrue for the true solution:

try:
    import fcns
    reload(fcns)  # in case user changed values
    qtrue = fcns.qtrue
except:
    print "*** Cannot evaluate qtrue.... "
    print "*** Module fcns missing, need to execute:"
    print "    f2py -c fcns.f -m fcns"

#--------------------------
def setplot(plotdata):
#--------------------------
    
    """ 
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of pyclaw.plotters.data.ClawPlotData.
    Output: a modified version of plotdata.
    
    """ 

    plotdata.clearfigures()  # clear any old figures,axes,items data

    # Figure for q[0]
    plotfigure = plotdata.new_plotfigure(name='Solution', figno=1)
    plotfigure.kwargs={'figsize': (8,4)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = [-0.2, 2.0]
    plotaxes.title = 'Solution'

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 0
    plotitem.plotstyle = '-o'
    plotitem.color = 'b'
    plotitem.kwargs = {'linewidth':2}
    plotitem.show = True       # show on plot?

    #------------------------------------------

    # Error plot:
    plotfigure = plotdata.new_plotfigure(name='Error', figno=2)
    plotfigure.kwargs={'figsize': (8,4)}
    #plotfigure.show = False
    plotaxes.afteraxes = add_true

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    #plotaxes.axescmd = 'subplot(212)'
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = [1e-18,1.]
    plotaxes.title = 'Max(Error, 1e-17)'

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d_semilogy')

    plotitem.plot_var = abserror
    plotitem.plotstyle = '-'
    plotitem.color = 'r'
    plotitem.kwargs = {'linewidth':2}
    plotitem.show = True       # show on plot?

    #------------------------------------------
    
    
    # Parameters used only when creating html and/or latex hardcopy
    # e.g., via pyclaw.plotters.frametools.printframes:

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    plotdata.html_homelink = '../README.html'
    plotdata.latex = True                    # create latex file of plots?
    plotdata.latex_figsperline = 2           # layout of plots
    plotdata.latex_framesperline = 1         # layout of plots
    plotdata.latex_makepdf = False           # also run pdflatex?

    return plotdata

    
def error(current_data):
    q0 = current_data.q[:,0]
    qt = current_data.q[:,1]
    return q0-qt
    
def abserror(current_data):
    """
    Return abs(error) or 1e-17 where error=0
    """
    q0 = current_data.q[:,0]
    qt = current_data.q[:,1]
    err = q0-qt
    abserr = [max(1e-17,abs(err[i])) for i in range(len(q0))]
    return abserr
    

def plot_x_axis(current_data):
    from pylab import hold,plot
    xlower = current_data.xlower
    xupper = current_data.xupper
    plot([xlower,xupper], [0.,0.], 'k')

def add_true(current_data):
    from pylab import hold,plot,linspace,array,text
    xlower = current_data.xlower
    xupper = current_data.xupper
    t = current_data.t
    x = linspace(xlower,xupper,1001)

    qt = []
    for i in range(len(x)):
        qt.append(qtrue(x[i],t,u))
    qt = array(qt)
    plot(x,qt,'r',linewidth=2)
    plot_x_axis(current_data)

    err = error(current_data)  # pointwise error on grid
    errmax = max(abs(err))
    dx = current_data.x[1] - current_data.x[0]
    err1 = dx * sum(abs(err))

    text(1,1.6,'Max Error = %9.3e' % errmax, fontsize=20)
    text(1,1.3,'L1  Error = %9.3e' % err1, fontsize=20)