Example #1
0
 def plot_function_xt_phase(plot_1_chars=False, plot_2_chars=False):
     plt.figure(figsize=(7, 2))
     ax = plt.subplot(121)
     riemann_tools.plot_waves(states,
                              speeds,
                              reval,
                              wave_types,
                              t=0,
                              ax=ax,
                              color='multi')
     if plot_1_chars:
         riemann_tools.plot_characteristics(reval,
                                            shallow_water.lambda_1,
                                            axes=ax,
                                            extra_lines=extra_lines)
     if plot_2_chars:
         riemann_tools.plot_characteristics(reval,
                                            shallow_water.lambda_2,
                                            axes=ax,
                                            extra_lines=extra_lines)
     ax = plt.subplot(122)
     shallow_water.phase_plane_plot(q_l,
                                    q_r,
                                    g,
                                    ax=ax,
                                    force_waves=force_waves,
                                    y_axis='u')
     plt.title('Phase plane')
     plt.show()
Example #2
0
def plot_waves(f,q_left, q_right, xi_left, xi_right, n=1000, axes=None, t=0.2):
    qtilde = nonconvex.osher_solution(f, q_left, q_right, 1000)
    xi = np.linspace(xi_left, xi_right, n)
    qvals = qtilde(xi)
    fvals = f(qvals)
    dxi = xi[1]-xi[0]
    smoothness = riemann_tools.detect_smoothness(qvals,dxi,dmax=10)
    values, ranges = riemann_tools.intervals(smoothness)
    
    # filter out extraneous constant states between rarefactions:
    # For complicated nonconvex fluxes, 
    # values tend to contain sequences [1,0,1] indicating a constant
    # state between two rarefaction waves, which shouldn't happen,
    # so merge such ranges into a single rarefaction wave.
    
    jd = []
    for j in range(len(values)):
        try:
            if values[j]==0 and values[j+1]==1 and values[j-1]==1:
                jd.append(j)         
        except:
            pass
    jd.reverse()
    for j in jd:
        ranges[j-1] = (ranges[j-1][0], ranges[j+1][1])  # merge
        values.pop(j+1)
        values.pop(j)
        ranges.pop(j+1)
        ranges.pop(j)  

    wave_types, speeds = riemann_tools.make_waves(values, ranges, xi)
    riemann_tools.plot_waves(None,speeds,None,wave_types,ax=axes,
                             t_pointer=False,t=t)
    #plt.xlim(xi_left, xi_right)
    plt.xlabel('x')
Example #3
0
 def plot_function_xt_phase(plot_1_chars=False,plot_2_chars=False,plot_tracer_chars=False):
     plt.figure(figsize=(7,2))
     ax = plt.subplot(121)
     riemann_tools.plot_waves(states, speeds, reval, wave_types, t=0,
                              ax=ax, color='multi')
     if plot_1_chars:
         riemann_tools.plot_characteristics(reval,lambda_1,
                                            axes=ax,extra_lines=extra_lines)
     if plot_2_chars:
         riemann_tools.plot_characteristics(reval,lambda_2,
                                            axes=ax,extra_lines=extra_lines)
     if plot_tracer_chars:
         riemann_tools.plot_characteristics(reval,lambda_tracer,
                                            axes=ax,extra_lines=extra_lines)
     ax = plt.subplot(122)
     phase_plane_plot(q_l,q_r,g,ax=ax,
                                    force_waves=force_waves,y_axis='u')
     plt.title('Phase plane')
     plt.show()