def entropy_condition_is_valid(cd,t,outdir,dx): index_t = t if index_t>0 : #entropy at t=0 doesn't exist (x,) = np.nonzero(np.all([h_1(cd)>dry_tolerance, h_2(cd)>dry_tolerance],axis=0)) len_x = len(x) delta_t = Solution(index_t, path=outdir,read_aux=True).t - Solution(index_t-1, path=outdir,read_aux=True).t delta_x = dx entropy_cond = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) for index_x in range(len_x-1): index_x_next = index_x + 1 entropy_flux_actual = entropy_flux(cd)[index_x] entropy_flux_prev = entropy_flux(cd)[index_x_next] entropy_next=entropy(cd)[index_x] entropy_actual=entropy(Solution(index_t-1, path=outdir,read_aux=True))[index_x] entropy_cond[index_x]= entropy_next-entropy_actual + (delta_t/delta_x)*(entropy_flux_actual-entropy_flux_prev) #print(eigenspace_velocity(cd)) return entropy_cond else : return([0]*500)
def test_forestclaw_input(): """Simple test to read in a ForestClaw ASCII file""" # Create test solution x = geometry.Dimension(0.0, 1.0, 100, name='x') state = State(geometry.Patch(x), 1) state.q = numpy.zeros((1, x.num_cells)) sol = Solution(state, geometry.Domain(x)) # Test specific extensions to Patch sol.domain.patches[0].block_number = 2 sol.domain.patches[0].mpi_rank = 2 # Create temporary directory to write to and read from try: temp_path = tempfile.mkdtemp() # Real test sol.write(0, path=temp_path) read_sol = Solution(0, path=temp_path, file_format='forestclaw') nose.tools.assert_equal(sol, read_sol, "ForestClaw IO read/write test failed, " + "solutions are not equal.") except: shutil.copy(os.path.join(temp_path, 'fort.q0000'), os.getcwd()) finally: shutil.rmtree(temp_path)
def create_resolution_plot(base_path, method=2, resolutions=[64, 128, 256, 512]): # Extract data from plot settings dict x_limits = plot_settings[base_path]["xlim"] y_limits = plot_settings[base_path]["ylim"] frame = plot_settings[base_path]["frame"] locations = plot_settings[base_path]["locs"] # Create figures and axes fig_list = [plt.figure() for n in xrange(3)] axes_list = [fig.add_subplot(111) for fig in fig_list] for (n, resolution) in enumerate(resolutions): # Load solution and extract data path = os.path.join(data_path, base_path, 'ml_e%s_n%s_output' % (method, resolution)) x, b, h, eta, u = extract_data( Solution(frame, path=path, read_aux=True)) # Plot data axes_list[0].plot(x, eta[0], styles[n], label='_nolegend_') axes_list[0].plot(x, eta[1], styles[n], label="N = %s" % resolution) axes_list[1].plot(x, u[0], styles[n], label="N = %s" % resolution) axes_list[2].plot(x, u[1], styles[n], label="N = %s" % resolution) # Plot reference solutions path = os.path.join(data_path, base_path, 'ml_e%s_n%s_output' % (base_method, base_resolution)) x, b, h, eta, u = extract_data(Solution(frame, path=path, read_aux=True)) axes_list[0].plot(x, eta[0], 'k', label='_nolegend_') axes_list[0].plot(x, eta[1], 'k', label='Base') # axes_list[0].plot(x,b,'k:',label="bathymetry") axes_list[1].plot(x, u[0], 'k', label='Base') axes_list[2].plot(x, u[1], 'k', label='Base') # Set legend, title and axis labels for (n, axes) in enumerate(axes_list): axes.set_xlim(x_limits) axes.set_ylim(y_limits[n]) axes.set_title("Comparison using the %s method" % eigen_labels[method - 1]) axes.set_xlabel('x') axes.set_ylabel(y_labels[n]) axes.legend(loc=locations[n]) out_path = os.path.join(os.curdir, 'comparison_plots', base_path) if not os.path.exists(out_path): os.makedirs(out_path) fig_list[0].savefig(os.path.join(out_path, 'surfaces_m%s.pdf' % method)) fig_list[1].savefig(os.path.join(out_path, 'u_top_m%s.pdf' % method)) fig_list[2].savefig(os.path.join(out_path, 'u_bottom_m%s.pdf' % method))
def error(out1, out2): frame1 = frame(out1) frame2 = frame(out2) sol1 = Solution() read(sol1, frame1, path=out1) sol2 = Solution() read(sol2, frame2, path=out2) return abs(sol2.q[0, :] - sol1.q[0, :]).max()
def entropy_condition_is_valid(cd): index_t = int(cd.frameno) if index_t > 0: #entropy at t=0 doesn't exist (x, ) = np.nonzero( np.all([h_1(cd) > dry_tolerance, h_2(cd) > dry_tolerance], axis=0)) len_x = len(x) delta_t = Solution( index_t, path=plotdata.outdir, read_aux=True).t - Solution( index_t - 1, path=plotdata.outdir, read_aux=True).t delta_x = cd.dx entropy_cond = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) for index_x in range(len_x - 1): index_x_next = index_x + 1 entropy_flux_actual = entropy_flux(cd)[index_x] entropy_flux_prev = entropy_flux(cd)[index_x_next] entropy_next = entropy(cd)[index_x] entropy_actual = entropy( Solution(index_t - 1, path=plotdata.outdir, read_aux=True))[index_x] entropy_cond[index_x] = entropy_next - entropy_actual + ( delta_t / delta_x) * (entropy_flux_actual - entropy_flux_prev) # if index_t == 67 or index_t==68 or index_t==69 or index_t==70 : # print('=======================================') # print(entropy_flux_actual) # print(entropy_flux_prev) # print(delta_t/delta_x) # print(entropy) # print(entropy_prev) # print(entropy_cond) return entropy_cond else: return ([0] * 500)
def create_convergence_plot(base_path, eigen_methods=[1, 2, 3, 4], resolutions=[64], table_file=None, latex_tables=False): r"""Create plots comparing each eigenspace method """ # Parameters fields = 4 plot_titles = [ "Top Layer Depths", "Top Layer Velocities", "Bottom Layer Depths", "Bottom Layer Velocities" ] file_names = [ 'convergence_top_surface', 'convergence_bot_surface', 'convergence_top_velocity', 'convergence_bot_velocity' ] # Extract data from plot settings dict frame = plot_settings[base_path]["frame"] # Calculate error # error[field,eigen_method,resolution] error = np.zeros((fields, len(eigen_methods), len(resolutions))) # Extract base solution path = os.path.join(data_path, base_path, 'ml_e%s_n%s_output' % (4, base_resolution)) x_base,b_base,h_base,eta_base,u_base = \ extract_data(Solution(frame,path=path,read_aux=True)) # Calculate errors for (m, method) in enumerate(eigen_methods): for (n, resolution) in enumerate(resolutions): # Load solution and extract data path = os.path.join(data_path, base_path, 'ml_e%s_n%s_output' % (method, resolution)) x, b, h, eta, u = extract_data( Solution(frame, path=path, read_aux=True)) error[0, m, n] = norm(h[0][:] - np.interp(x, x_base, h_base[0][:])) error[1, m, n] = norm(h[1][:] - np.interp(x, x_base, h_base[1][:])) error[2, m, n] = norm(u[0][:] - np.interp(x, x_base, u_base[0][:])) error[3, m, n] = norm(u[1][:] - np.interp(x, x_base, u_base[1][:])) # Calculate order order = [[] for i in xrange(fields)] for field in xrange(fields): for (m, method) in enumerate(eigen_methods): order[field].append(-polyfit(np.log(resolutions), np.log(error[field, m, :]), 1)[1]) # Create figures and axes figs_list = [plt.figure() for n in xrange(fields)] axes_list = [fig.add_subplot(111) for fig in figs_list] # Plot errors for (m, method) in enumerate(eigen_methods): for i in xrange(fields): # import pdb; pdb.set_trace() axes_list[i].loglog(resolutions, error[i, m, :], styles[m], label=eigen_labels[m]) # Set plot characteristics for (i, axes) in enumerate(axes_list): axes.legend() axes.set_title(plot_titles[i]) axes.set_xlim([resolutions[0] - 8, resolutions[-1] + 32]) axes.set_xlabel("Number of Cells") axes.set_ylabel("L^2 Error") axes.set_xticks(resolutions) axes.set_xticklabels(resolutions) # Save figures out_path = os.path.join(os.curdir, 'comparison_plots', base_path) if not os.path.exists(out_path): os.makedirs(out_path) for (i, fig) in enumerate(figs_list): fig.savefig(os.path.join(out_path, '.'.join((file_names[i], 'pdf')))) # Make table, latex is saved to a file if table_file: table_file.write( make_table(eigen_labels, plot_titles, order, base_path, latex_tables)) table_file.write("\n" * 2) else: print make_table(eigen_labels, plot_titles, order, base_path, latex_tables)
def plot_all(values_to_plot,nb_test,nb_frames,format='ascii',msgfile='',**kargs): # ============================ # = Create Initial Condition = # ============================ # Construct output and plot directory paths name = 'multilayer/dry_state_rarefaction_test' prefix = 'ml_e%s_m%s_fix_m%s_vel' % (2, 500, values_to_plot[0]) prefix = "".join((prefix, "F")) outdir,plotdir,log_path = runclaw.create_output_paths(name, prefix, **kargs) script_dir = os.path.dirname(__file__) plots_dir = os.path.join(script_dir, 'All_plots/') if not os.path.isdir(plots_dir): os.makedirs(plots_dir) # Set physics data global g g=Solution(0, path=outdir,read_aux=True).state.problem_data['g'] global manning manning=Solution(0, path=outdir,read_aux=True).state.problem_data['manning'] global rho_air rho_air=Solution(0, path=outdir,read_aux=True).state.problem_data['rho_air'] global rho rho=Solution(0, path=outdir,read_aux=True).state.problem_data['rho'] global r r=Solution(0, path=outdir,read_aux=True).state.problem_data['r'] global one_minus_r one_minus_r=Solution(0, path=outdir,read_aux=True).state.problem_data['one_minus_r'] global num_layers num_layers=Solution(0, path=outdir,read_aux=True).state.problem_data['num_layers'] global b b = Solution(0, path=outdir,read_aux=True).state.aux[bathy_index,:] # Set method parameters, this ensures it gets to the Fortran routines eigen_method=Solution(0, path=outdir,read_aux=True).state.problem_data['eigen_method'] dry_tolerance=Solution(0, path=outdir,read_aux=True).state.problem_data['dry_tolerance'] inundation_method=Solution(0, path=outdir,read_aux=True).state.problem_data['inundation_method'] entropy_fix=Solution(0, path=outdir,read_aux=True).state.problem_data['entropy_fix'] #num_cells=Solution(0,path=outdir,read_aux=True).state.problem_data['num_cells'] #does not work num_cells=500 plt.clf() # Load bathymetery #b = Solution(0, path=outdir,read_aux=True).state.aux[bathy_index,:] # Load gravitation #g = Solution(0, path=outdir,read_aux=True).state.problem_data['g'] # Load one minus r #one_minus_r=Solution(0, path=outdir,read_aux=True).state.problem_data['one_minus_r'] xlimits=[] for t in range(nb_frames): #Depths plotdata=ClawPlotData() plotfigure_depths = plotdata.new_plotfigure(name='Depths') plotfigure_depths.show=True plotaxes_depths = plotfigure_depths.new_plotaxes() plotaxes_depths.title = "Depths" plotaxes_depths.xlimits = xlimits plotaxes_depths.ylimits = 'auto' # fig2 = plt.figure(num=2) # plt.xlabel('x(m)') # plt.ylabel('Depths') # plt.title('Solution at t = %3.5f' % t) # plt.ylim(-1.1, 0.1) #Entropy fig7 = plt.figure(num=2) plt.xlabel('x(m)') plt.ylabel('Entropy') plt.title('Entropy as t = %3.5f' % t) #Composite Froude number fig12 = plt.figure(num=12) plt.xlabel('x(m)') plt.ylabel('Composite Froude number') plt.title('Composite Froude number at t = %3.5f' % t) plotdata.outdir = outdir plotdata.plotdir = plots_dir print(plotdir) Solutions_=[] x = [k/1000 for k in range(0,1000,2)] print('Plot the figures at frame %s' % t) for i in range(nb_test): # Construct output and plot directory paths name = 'multilayer/dry_state_rarefaction_test' prefix = 'ml_e%s_m%s_fix_m%s_vel' % (eigen_method, num_cells, values_to_plot[i]) if entropy_fix: prefix = "".join((prefix, "T")) else: prefix = "".join((prefix, "F")) outdir,plotdir,log_path = runclaw.create_output_paths(name, prefix, **kargs) #exec("cd_"+str(i)+"='"Solution(t,path=outdir,read_aux=True)+"'") cd = Solution(t,path=outdir,read_aux=True) Solutions_ += [Solution(t,path=outdir,read_aux=True)] #=====Plotting===== plot_color='g' plot_style='-' if values_to_plot[i] >= 3.9 : if values_to_plot[i] >= 8.0 : plot_color = 'r' plot_style = ':' else : plot_color = 'b' plot_style = '-.' #depth #plotdata.setplot = setplot plotdata.format = format plotdata.msgfile = msgfile plotitem_depths = plotaxes_depths.new_plotitem(plot_type='1d') plotitem_depths.plot_var = eta_1 plotitem_depths.plotstyle='k' plotitem_depths.color=plot_color plotitem_depths.show=True # plt.figure(num=2) # plt.plot(bathy(cd),'k') # plt.plot(eta_1(cd),'k',color=plot_color,linestyle=plot_style) # plt.plot(eta_2(cd),'k',color=plot_color,linestyle=plot_style) # depthname = 'frame00%sfig1002.png' % t # plt.savefig(plots_dir + depthname) #plt.close() #Entropy # plt.figure(num=7) # plt.plot(entropy(cd),'k',color=plot_color,linestyle=plot_style) # entropyname = 'frame00%sfig1007.png' % t # plt.savefig(plots_dir + entropyname) # # #Composite Froude number # plt.figure(num=12) # plt.plot(composite_Froude_nb(cd),'k',color=plot_color,linestyle=plot_style) # froudename = 'frame00%sfig1012.png' % ( t ) # plt.savefig(plots_dir + froudename) #plt.close() plt.close('all')
def kappa(cd): return Solution(cd.frameno,path=outdir,read_aux=True).state.aux[kappa_index,:]
def plot_contour(data_dir="./_output", out_dir='./', num_layers=2, num_frames=1000, ref_lines=[-130e3, -30e3], color=True): """Plot a contour plot of a shelf based simluation""" # Create plot data plot_data = data.ClawPlotData() plot_data.outdir = data_dir # Read in bathymetry sol = [Solution(0, path=data_dir, read_aux=True)] b = sol[0].state.aux[0, :] # Extract x coordinates, this assumes that these do not change through the # simluation (they should not) x = sol[0].state.grid.dimensions[0].centers # Read in all solutions print "Reading in solutions..." for frame in xrange(1, num_frames): try: sol.append(Solution(frame, path=data_dir)) except IOError: # We have reached the last frame before given num_frames reached num_frames = frame - 1 break print "Found %s frames to plot." % num_frames # Create plotting arrays print "Constructing plotting variables..." eta = np.ndarray((num_frames, num_layers, len(x))) t = np.ndarray((num_frames)) for frame in xrange(num_frames): # Append data to eta and t lists t[frame] = sol[frame].t / 3600.0 # Calculate from the bottom up layer_index = 2 * (num_layers - 1) eta[frame, num_layers - 1, :] = sol[frame].q[layer_index, :] / rho[-1] + b # Calculate the rest of the layers for layer in xrange(num_layers - 2, -1, -1): layer_index = 2 * layer eta[frame, layer, :] = sol[frame].q[layer_index, :] / rho[layer] + eta[ frame, layer + 1, :] # Create mesh grid for plot X, T = np.meshgrid(x, t) # Plot the contours of each layer clines = np.linspace(.025, .4, 8) title = ['top', 'internal'] print "Creating plots..." fig = plt.figure(figsize=[10, 8]) for layer in xrange(num_layers): axes = fig.add_subplot(1, num_layers, layer + 1) # Plot positive and negative contours eta_plot = eta[:, layer, :] - eta_init[layer] plot = axes.contour(X, T, eta_plot, clines, colors='r') plot = axes.contour(X, T, eta_plot, -clines, colors='b') for ref_line in ref_lines: axes.plot([ref_line, ref_line], [0, 2], 'k:') # X ticks and labels axes.set_xticks([-300e3, -200e3, -100e3, -30e3]) axes.set_xticklabels([300, 200, 100, 30], fontsize=15) axes.set_xlabel("Kilometers offshore", fontsize=15) axes.set_xlim([-200e3, 0.0]) # First plot from left to right, write y ticks if layer == 0: plt.yticks(fontsize=15) axes.set_ylabel("Hours", fontsize=20) else: # Remove tick labels axes.set_yticklabels(['' for label in axes.get_yticklabels()]) axes.set_title("Contours of %s surface" % title[layer], fontsize=15) file_name = os.path.join(out_dir, "contour.png") print "Writing out to %s" % file_name plt.savefig(file_name)
def setplot(plotdata,rho,dry_tolerance): #-------------------------- """ Specify what is to be plotted at each frame. Input: plotdata, an instance of pyclaw.plotters.data.ClawPlotData. Output: a modified version of plotdata. """ # Load bathymetry b = Solution(0,path=plotdata.outdir,read_aux=True).state.aux[bathy_index,:] def bathy(cd): return b def kappa(cd): return Solution(cd.frameno,path=plotdata.outdir,read_aux=True).state.aux[kappa_index,:] def wind(cd): return Solution(cd.frameno,path=plotdata.outdir,read_aux=True).state.aux[wind_index,:] def h_1(cd): return cd.q[0,:] / rho[0] def h_2(cd): return cd.q[2,:] / rho[1] def eta_2(cd): return h_2(cd) + bathy(cd) def eta_1(cd): return h_1(cd) + eta_2(cd) def u_1(cd): index = np.nonzero(h_1(cd) > dry_tolerance) u_1 = np.zeros(h_1(cd).shape) u_1[index] = cd.q[1,index] / cd.q[0,index] return u_1 def u_2(cd): index = np.nonzero(h_2(cd) > dry_tolerance) u_2 = np.zeros(h_2(cd).shape) u_2[index] = cd.q[3,index] / cd.q[2,index] return u_2 def jump_afteraxes(current_data): # Plot position of jump on plot mpl.hold(True) mpl.plot([0.5,0.5],[-10.0,10.0],'k--') mpl.plot([0.0,1.0],[0.0,0.0],'k--') mpl.hold(False) mpl.title('') plotdata.clearfigures() # clear any old figures,axes,items data # Window Settings xlimits = [0.0,10.0] ylimits_depth = [-10.5,0.5] # ======================================================================== # Function for doing depth drawing # ======================================================================== def fill_items(plotaxes): # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d_fill_between') plotitem.plot_var = eta_1 plotitem.plot_var2 = eta_2 plotitem.color = plot.top_color plotitem.plotstyle = plot.surface_linestyle plotitem.show = True # Bottom Layer plotitem = plotaxes.new_plotitem(plot_type='1d_fill_between') plotitem.plot_var = eta_2 plotitem.plot_var2 = bathy plotitem.color = plot.bottom_color plotitem.plotstyle = plot.internal_linestyle plotitem.show = True # Plot bathy plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = bathy plotitem.plotstyle = plot.bathy_linestyle plotitem.show = True # Plot line in between layers plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = eta_2 plotitem.color = 'k' plotitem.plotstyle = plot.internal_linestyle plotitem.show = True # Plot line on top layer plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = eta_1 plotitem.color = 'k' plotitem.plotstyle = plot.surface_linestyle plotitem.show = True # ======================================================================== # Full Depths # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Full Depths',figno=102) plotfigure.show = True def bathy_axes(cd): # km_labels(cd) mpl.xlabel('Depth (m)') mpl.ylabel('x (m)') mpl.title("Depths at t=%2.1f" % cd.t) # mpl.xticks([-300e3,-200e3,-100e3,-30e3],[300,200,100,30],fontsize=15) # mpl.xlabel('km') plotaxes = plotfigure.new_plotaxes() plotaxes.title = 'Full Depths' plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_depth plotaxes.afteraxes = bathy_axes fill_items(plotaxes) # 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 = [0,25,50] # list of frames to print 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' # pointer for top of index 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 plot_all(values_to_plot,nb_test,nb_frames,**kargs): # ============================ # = Create Initial Condition = # ============================ # Construct output and plot directory paths name = 'multilayer/dry_state_rarefaction_test' prefix = 'ml_e%s_m%s_fix_m%s_vel' % (2, 500, values_to_plot[0]) prefix = "".join((prefix, "F")) outdir,plotdir,log_path = runclaw.create_output_paths(name, prefix, **kargs) script_dir = os.path.dirname(__file__) plots_dir = os.path.join(script_dir, 'All_plots/') if not os.path.isdir(plots_dir): os.makedirs(plots_dir) # Set physics data global g g=Solution(0, path=outdir,read_aux=True).state.problem_data['g'] global manning manning=Solution(0, path=outdir,read_aux=True).state.problem_data['manning'] global rho_air rho_air=Solution(0, path=outdir,read_aux=True).state.problem_data['rho_air'] global rho rho=Solution(0, path=outdir,read_aux=True).state.problem_data['rho'] global r r=Solution(0, path=outdir,read_aux=True).state.problem_data['r'] global one_minus_r one_minus_r=Solution(0, path=outdir,read_aux=True).state.problem_data['one_minus_r'] global num_layers num_layers=Solution(0, path=outdir,read_aux=True).state.problem_data['num_layers'] global b b = Solution(0, path=outdir,read_aux=True).state.aux[bathy_index,:] # Set method parameters, this ensures it gets to the Fortran routines eigen_method=Solution(0, path=outdir,read_aux=True).state.problem_data['eigen_method'] dry_tolerance=Solution(0, path=outdir,read_aux=True).state.problem_data['dry_tolerance'] inundation_method=Solution(0, path=outdir,read_aux=True).state.problem_data['inundation_method'] entropy_fix=Solution(0, path=outdir,read_aux=True).state.problem_data['entropy_fix'] #num_cells=Solution(0,path=outdir,read_aux=True).state.problem_data['num_cells'] #does not work num_cells=500 import clawpack.pyclaw as pyclaw global x x = pyclaw.Dimension(0.0, 1.0, num_cells) print() plt.clf() # Load bathymetery #b = Solution(0, path=outdir,read_aux=True).state.aux[bathy_index,:] # Load gravitation #g = Solution(0, path=outdir,read_aux=True).state.problem_data['g'] # Load one minus r #one_minus_r=Solution(0, path=outdir,read_aux=True).state.problem_data['one_minus_r'] xlimits_zoom=(200, 300) #Little problem, need to check that ylimits=(-1.1,0.1) for t in range(nb_frames): #Depths # plotfigure_depths = cpd.new_plotfigure(name='Depths') # plotfigure_depths.show=True # plotaxes_depths = plotfigure_depths.new_plotaxes() # plotaxes_depths.title = "Depths" # plotaxes_depths.xlimis = xlimits # plotaxes_depths.ylimits = 'auto' fig2 = plt.figure(num=2) plt.xlabel('x(m)') plt.ylabel('Depths') plt.title('Solution at t = %3.5f' % t) plt.ylim(ylimits) #Depth zoom fig3 = plt.figure(num=3) plt.xlabel('x(m)') plt.ylabel('Depths') plt.title('Solution zoomed at t = %3.5f' % t ) plt.xlim(xlimits_zoom) plt.ylim(ylimits) #Entropy fig7 = plt.figure(num=7) plt.xlabel('x(m)') plt.ylabel('Entropy') plt.title('Entropy as t = %3.5f' % t) #Entropy flux fig8 = plt.figure(num=8) plt.xlabel('x(m)') plt.ylabel('Entropy flux') plt.title('Entropy flux at t = %3.5f' % t) #Entropy condition fig9 = plt.figure(num=9) plt.xlabel('x(m)') plt.ylabel('Value similar to entropy') plt.title('Entropy condition at t = %3.5f' % t) #Composite Froude number fig12 = plt.figure(num=12) plt.xlabel('x(m)') plt.ylabel('Composite Froude number') plt.title('Composite Froude number at t = %3.5f' % t) print('Plot the figures at frame %s' % t) for i in range(nb_test): # Construct output and plot directory paths name = 'multilayer/dry_state_rarefaction_test' prefix = 'ml_e%s_m%s_fix_m%s_vel' % (eigen_method, num_cells, values_to_plot[i]) if entropy_fix: prefix = "".join((prefix, "T")) else: prefix = "".join((prefix, "F")) outdir,plotdir,log_path = runclaw.create_output_paths(name, prefix, **kargs) cd = Solution(t,path=outdir,read_aux=True) #=====Plotting===== plot_color='g' plot_style='-' if values_to_plot[i] >= 3.9 : if values_to_plot[i] >= 8.0 : plot_color = 'r' plot_style = ':' else : plot_color = 'b' plot_style = '-.' #plt.close() #legend_to_show='velocity: ' + str(values_to_plot[i]) legend_to_show='Velocity: ' + str(values_to_plot[i]) #Depth # plotitem_depths = plotaxes_depths.new_plotitem(plot_type='1d') # plotitem_depths.plot_var = Solutions_[i] # plotitem_depths.plotstyle='k' # plotitem_depths.color=plot_color # plotitem_depths.show=True plt.figure(num=2) plt.plot(bathy(cd),'k') plt.plot(eta_1(cd),'k',color=plot_color,linestyle=plot_style,label=legend_to_show ) plt.plot(eta_2(cd),'k',color=plot_color,linestyle=plot_style) depthname = 'frame00%sfig1002.png' % t plt.legend() plt.savefig(plots_dir + depthname) #Depth zoom plt.figure(num=3) plt.plot(bathy(cd),'k') plt.plot(eta_1(cd),'k',color=plot_color,linestyle=plot_style,label=legend_to_show) plt.plot(eta_2(cd),'k',color=plot_color,linestyle=plot_style) depthzoomname = 'frame00%sfig1003.png' % t plt.legend() plt.savefig(plots_dir + depthzoomname) #Entropy plt.figure(num=7) plt.plot(entropy(cd),'k',color=plot_color,linestyle=plot_style,label=legend_to_show) entropyname = 'frame00%sfig1007.png' % t plt.legend() plt.savefig(plots_dir + entropyname) #Entropy flux plt.figure(num=8) plt.plot(entropy_flux(cd),'k',color=plot_color,linestyle=plot_style,label=legend_to_show) entropyfluxname='frame00%sfig1008.png' % t plt.legend() plt.savefig(plots_dir + entropyfluxname) #Entropy condition plt.figure(num=9) plt.plot(entropy_condition_is_valid(cd,t,outdir,x.delta),'k',color=plot_color,linestyle=plot_style,label=legend_to_show) entropycondname='frame00%sfig1009.png' % t plt.legend() plt.savefig(plots_dir + entropycondname) #Composite Froude number plt.figure(num=12) plt.plot(composite_Froude_nb(cd),'k',color=plot_color,linestyle=plot_style,label=legend_to_show) froudename = 'frame00%sfig1012.png' % ( t ) plt.legend() plt.savefig(plots_dir + froudename) #plt.close() plt.close('all')
def setplot(plotdata, xlower, xupper, rho, dry_tolerance): #-------------------------- """ Specify what is to be plotted at each frame. Input: plotdata, an instance of pyclaw.plotters.data.ClawPlotData. Output: a modified version of plotdata. """ # Load bathymetry b = Solution(0, path=plotdata.outdir, read_aux=True).state.aux[bathy_index, :] def hurricane_afterframe(current_data): # Draw line for eye of hurricane pass def bathy(cd): return b def kappa(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[kappa_index, :] def wind(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[wind_index, :] def h_1(cd): return cd.q[0, :] / rho[0] def h_2(cd): return cd.q[2, :] / rho[1] def eta_2(cd): return h_2(cd) + bathy(cd) def eta_1(cd): return h_1(cd) + eta_2(cd) def u_1(cd): index = np.nonzero(h_1(cd) > dry_tolerance) u_1 = np.zeros(h_1(cd).shape) u_1[index] = cd.q[1, index] / cd.q[0, index] return u_1 def u_2(cd): index = np.nonzero(h_2(cd) > dry_tolerance) u_2 = np.zeros(h_2(cd).shape) u_2[index] = cd.q[3, index] / cd.q[2, index] return u_2 plotdata.clearfigures() # clear any old figures,axes,items data xlimits = [xlower, xupper] ylimits_velocities = (-0.15, 0.15) ylimits_depth = [-1.0, 0.1] ylimits_wind = [-5, 5] ylimits_kappa = [0.0, 1.2] # ======================================================================== # Depth, Momenta, and Kappa # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Depth, Momenta, and Kappa', figno=14) def twin_axes(cd): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Draw fill plot depth_axes = fig.add_subplot(211) vel_axes = fig.add_subplot(212, sharex=depth_axes) # the velocity scale kappa_axes = vel_axes.twinx() # Bottom layer depth_axes.fill_between(x, bathy(cd), eta_1(cd), color=plot.bottom_color) # Top Layer depth_axes.fill_between(x, eta_1(cd), eta_2(cd), color=plot.top_color) # Plot bathy depth_axes.plot(x, bathy(cd), 'k', linestyle=plot.bathy_linestyle) # Plot internal layer depth_axes.plot(x, eta_2(cd), 'k', linestyle=plot.internal_linestyle) # Plot surface depth_axes.plot(x, eta_1(cd), 'k', linestyle=plot.surface_linestyle) # Remove ticks from top plot locs, labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs, labels) depth_axes.set_title('Oscillatory Wind at t = %3.2f' % cd.t) depth_axes.set_xlim(xlimits) depth_axes.set_ylim(ylimits_depth) depth_axes.set_ylabel('Depth (m)') # Draw velocity and kappa plot # Bottom layer velocity bottom_layer = vel_axes.plot(cd.x, u_2(cd), 'k-', label="Bottom Layer Velocity") # Top Layer velocity top_layer = vel_axes.plot(cd.x, u_1(cd), 'b--', label="Top Layer velocity") # Kappa kappa_line = kappa_axes.plot(cd.x, kappa(cd), 'r-.') kappa_axes.plot(cd.x, np.ones(cd.x.shape), 'r:') plot.add_legend(vel_axes, 'Kappa', color='r', linestyle='-.', location=4) vel_axes.set_xlim(xlimits) vel_axes.set_ylim(ylimits_velocities) kappa_axes.set_ylim(ylimits_kappa) vel_axes.set_title('') # vel_axes.set_title('Layer Velocities and Kappa') vel_axes.set_ylabel('Velocities (m/s)') kappa_axes.set_ylabel('Kappa') # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = twin_axes # ======================================================================== # Plot Wind Velocity # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Wind Field', figno=2) plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Wind Velocity" plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_wind def wind_afteraxes(cd): plt.xlabel("x (m)") plt.ylabel("Velocity (m/s)") plotaxes.afteraxes = wind_afteraxes plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = wind plotitem.color = 'r' plotitem.show = True # 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' # pointer for top of index 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 setplot(plotdata, eta=[0.0, -300.0], rho=[1025.0, 1045.0], g=9.81, dry_tolerance=1e-3, bathy_ref_lines=[-30e3]): """ Specify what is to be plotted at each frame. Input: plotdata, an instance of pyclaw.plotters.data.ClawPlotData. Output: a modified version of plotdata. """ # Fetch bathymetry once b = Solution(0, path=plotdata.outdir, read_aux=True).state.aux[bathy_index, :] # ======================================================================== # Plot variable functions def bathy(cd): return b def kappa(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[kappa_index, :] def wind(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[wind_index, :] def h_1(cd): return cd.q[0, :] / rho[0] def h_2(cd): return cd.q[2, :] / rho[1] def eta_2(cd): return h_2(cd) + bathy(cd) def eta_1(cd): return h_1(cd) + eta_2(cd) def u_1(cd): index = np.nonzero(h_1(cd) > dry_tolerance) u_1 = np.zeros(h_1(cd).shape) u_1[index] = cd.q[1, index] / cd.q[0, index] return u_1 def u_2(cd): index = np.nonzero(h_2(cd) > dry_tolerance) u_2 = np.zeros(h_2(cd).shape) u_2[index] = cd.q[3, index] / cd.q[2, index] return u_2 def hu_1(cd): index = np.nonzero(h_1(cd) > dry_tolerance) hu_1 = np.zeros(h_1(cd).shape) hu_1[index] = cd.q[1, index] / rho[0] return hu_1 def hu_2(cd): index = np.nonzero(h_2(cd) > dry_tolerance) hu_2 = np.zeros(h_2(cd).shape) hu_2[index] = cd.q[3, index] / rho[1] return hu_2 # ======================================================================== # Labels def add_bathy_dashes(current_data): mpl.hold(True) for ref_line in bathy_ref_lines: mpl.plot([ref_line, ref_line], [-10, 10], 'k--') mpl.hold(False) def add_horizontal_dashes(current_data): mpl.hold(True) mpl.plot([-400e3, 0.0], [0.0, 0.0], 'k--') mpl.hold(False) def km_labels(current_data): r"""Flips xaxis and labels with km""" mpl.xlabel('km') locs, labels = mpl.xticks() labels = np.flipud(locs) / 1.e3 mpl.xticks(locs, labels) def time_labels(current_data): r"""Convert time to hours""" pass # ======================================================================== # Limit Settings xlimits = [-400e3, 0.0] ylimits_depth = [-4000.0, 100.0] xlimits_zoomed = [-30e3 - 1e3, -30e3 + 1e3] ylimits_surface_zoomed = [eta[0] - 0.5, eta[0] + 0.5] ylimits_internal_zoomed = [eta[1] - 2.5, eta[1] + 2.5] ylimits_momentum = [-40, 10] # ylimits_velocities = [-1.0,1.0] ylimits_velocities = [-0.04, 0.04] ylimits_kappa = [0.0, 1.2] # Create data object plotdata.clearfigures() # clear any old figures,axes,items data # ======================================================================== # Function for doing depth drawing # ======================================================================== def fill_items(plotaxes): # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d_fill_between') plotitem.plot_var = eta_1 plotitem.plot_var2 = eta_2 plotitem.color = plot.top_color plotitem.plotstyle = plot.surface_linestyle plotitem.show = True # Bottom Layer plotitem = plotaxes.new_plotitem(plot_type='1d_fill_between') plotitem.plot_var = eta_2 plotitem.plot_var2 = bathy plotitem.color = plot.bottom_color plotitem.plotstyle = plot.internal_linestyle plotitem.show = True # Plot bathy plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = bathy plotitem.plotstyle = plot.bathy_linestyle plotitem.show = True # Plot line in between layers plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = eta_2 plotitem.color = 'k' plotitem.plotstyle = plot.internal_linestyle plotitem.show = True # Plot line on top layer plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = eta_1 plotitem.color = 'k' plotitem.plotstyle = plot.surface_linestyle plotitem.show = True # ======================================================================== # Full Depths # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Full Depths', figno=102) plotfigure.show = True def bathy_axes(cd): km_labels(cd) mpl.xticks([-300e3, -200e3, -100e3, -30e3], [300, 200, 100, 30], fontsize=15) mpl.xlabel('km') plotaxes = plotfigure.new_plotaxes() plotaxes.title = 'Full Depths' plotaxes.xlimits = xlimits plotaxes.ylimits = [-4100, 100] plotaxes.afteraxes = bathy_axes fill_items(plotaxes) # ======================================================================== # Momentum # ======================================================================== plotfigure = plotdata.new_plotfigure(name="momentum") plotfigure.show = True def momentum_axes(cd): km_labels(cd) mpl.xticks([-300e3, -200e3, -100e3, -30e3], [300, 200, 100, 30], fontsize=15) mpl.xlabel('km') mpl.title("Layer Momenta at t = %4.1f s" % cd.t) mpl.legend(['Top Layer Momentum', 'Bottom Layer Momentum'], loc=4) def inset_momentum_axes(cd): r"""This does not refresh correctly...""" fig = mpl.figure(cd.plotfigure.figno) axes = fig.add_subplot(111) # Plot main figure axes.plot(cd.x, hu_1(cd), 'b-') axes.plot(cd.x, hu_2(cd), 'k--') axes.set_xlim(xlimits) axes.set_ylim(ylimits_momentum) momentum_axes(cd) # Create inset plot from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes from mpl_toolkits.axes_grid1.inset_locator import mark_inset inset_axes = zoomed_inset_axes(axes, 0.5, loc=3) inset_axes.plot(cd.x, hu_1(cd), 'b-') inset_axes.plot(cd.x, hu_2(cd), 'k--') inset_axes.set_xticklabels([]) inset_axes.set_yticklabels([]) x_zoom = [-120e3, -30e3] y_zoom = [-10, 10] inset_axes.set_xlim(x_zoom) inset_axes.set_ylim(y_zoom) mark_inset(axes, inset_axes, loc1=2, loc2=4, fc='none', ec="0.5") # mpl.ion() mpl.draw() # mpl.show() plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Momentum" plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_momentum plotaxes.afteraxes = inset_momentum_axes # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = hu_1 plotitem.plotstyle = 'b-' plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = hu_2 plotitem.plotstyle = 'k--' plotitem.show = True # ======================================================================== # Velocities with Kappa # ======================================================================== include_kappa = False if include_kappa: plotfigure = plotdata.new_plotfigure(name='Velocity and Kappa', figno=14) else: plotfigure = plotdata.new_plotfigure(name='Velocities', figno=14) plotfigure.show = True # plotfigure.kwargs = {'figsize':(7,6)} def twin_axes(cd): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Draw velocity and kappa plot vel_axes = fig.add_subplot(111) # the velocity scale # kappa_axes = vel_axes.twinx() # the kappa scale # Bottom layer velocity bottom_layer = vel_axes.plot(x, u_2(cd), 'k-', label="Bottom Layer Velocity") # Top Layer velocity top_layer = vel_axes.plot(x, u_1(cd), 'b--', label="Top Layer velocity") if include_kappa: # Kappa kappa_line = kappa_axes.plot(x, kappa(cd), 'r-.', label="Kappa") kappa_axes.plot(x, np.ones(x.shape), 'r:') vel_axes.set_xlabel('km') mpl.xticks([-300e3, -200e3, -100e3, -30e3], [300, 200, 100, 30], fontsize=15) for ref_line in bathy_ref_lines: vel_axes.plot([ref_line, ref_line], ylimits_velocities, 'k:') if include_kappa: vel_axes.set_title("Layer Velocities and Kappa at t = %4.1f s" % cd.t) else: vel_axes.set_title("Layer Velocities at t = %4.1f s" % cd.t) vel_axes.set_ylabel('Velocities (m/s)') vel_axes.set_xlim(xlimits) vel_axes.set_ylim(ylimits_velocities) if include_kappa: plot.add_legend(vel_axes, 'Kappa', location=3, color='r', linestyle='-.') kappa_axes.set_ylabel('Kappa') kappa_axes.set_ylim(ylimits_kappa) else: vel_axes.legend(loc=3) try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = twin_axes # ======================================================================== # Combined Top and Internal Surface # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Zoomed Depths', figno=13) plotfigure.show = True plotfigure.kwargs = {'figsize': (6, 6)} # Top surface plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(2,1,1)' plotaxes.title = 'Surfaces' plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_surface_zoomed def top_afteraxes(cd): mpl.xlabel('') locs, labels = mpl.xticks() # labels = np.flipud(locs)/1.e3 labels = ['' for i in xrange(len(locs))] mpl.xticks(locs, labels) add_bathy_dashes(cd) mpl.ylabel('m') mpl.title("Surfaces t = %4.1f s" % cd.t) plotaxes.afteraxes = top_afteraxes plotaxes = fill_items(plotaxes) # Internal surface plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(2,1,2)' plotaxes.title = '' plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_internal_zoomed def internal_surf_afteraxes(cd): km_labels(cd) mpl.title('') mpl.ylabel('m') mpl.subplots_adjust(hspace=0.05) mpl.xticks([-300e3, -200e3, -100e3, -30e3], [300, 200, 100, 30], fontsize=15) mpl.xlabel('km') plotaxes.afteraxes = internal_surf_afteraxes plotaxes = fill_items(plotaxes) # 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_framenos = [0, 30, 100, 200, 300] plotdata.print_fignos = 'all' # list of figures to print plotdata.html = True # create html files of plots? plotdata.html_homelink = '../README.html' # pointer for top of index 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 setplot(plotdata, rho, dry_tolerance): #-------------------------- """ Specify what is to be plotted at each frame. Input: plotdata, an instance of pyclaw.plotters.data.ClawPlotData. Output: a modified version of plotdata. """ def jump_afteraxes(current_data): # Plot position of jump on plot mpl.hold(True) mpl.plot([0.5, 0.5], [-10.0, 10.0], 'k--') mpl.plot([0.0, 1.0], [0.0, 0.0], 'k--') mpl.hold(False) mpl.title('Layer Velocities') # Load bathymetery b = Solution(0, path=plotdata.outdir, read_aux=True).state.aux[bathy_index, :] def bathy(cd): return b def kappa(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[kappa_index, :] def wind(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[wind_index, :] def h_1(cd): return cd.q[0, :] / rho[0] def h_2(cd): return cd.q[2, :] / rho[1] def eta_2(cd): return h_2(cd) + bathy(cd) def eta_1(cd): return h_1(cd) + eta_2(cd) def u_1(cd): index = np.nonzero(h_1(cd) > dry_tolerance) u_1 = np.zeros(h_1(cd).shape) u_1[index] = cd.q[1, index] / cd.q[0, index] return u_1 def u_2(cd): index = np.nonzero(h_2(cd) > dry_tolerance) u_2 = np.zeros(h_2(cd).shape) u_2[index] = cd.q[3, index] / cd.q[2, index] return u_2 plotdata.clearfigures() # clear any old figures,axes,items data # Window Settings xlimits = [0.0, 1.0] xlimits_zoomed = [0.45, 0.55] ylimits_momentum = [-0.004, 0.004] ylimits_depth = [-1.0, 0.2] ylimits_depth_zoomed = ylimits_depth ylimits_velocities = [-0.75, 0.75] ylimits_velocities_zoomed = ylimits_velocities # ======================================================================== # Depth and Momentum Plot # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Depth and Momentum') plotfigure.show = True def twin_axes(cd, xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212, sharex=ax1) # the velocity scale # Bottom layer ax1.fill_between(x, bathy(cd), eta_1(cd), color=plot.bottom_color) # Top Layer ax1.fill_between(x, eta_1(cd), eta_2(cd), color=plot.top_color) # Plot bathy ax1.plot(x, bathy(cd), 'k', linestyle=plot.bathy_linestyle) # Plot internal layer ax1.plot(x, eta_2(cd), 'k', linestyle=plot.internal_linestyle) # Plot surface ax1.plot(x, eta_1(cd), 'k', linestyle=plot.surface_linestyle) # Remove ticks from top plot locs, labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs, labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.2f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(ylimits_depth) # ax1.set_xlabel('x') ax1.set_ylabel('Depth (m)') # Bottom layer velocity bottom_layer = ax2.plot(x, u_2(cd), 'k', linestyle=plot.internal_linestyle, label="Bottom Layer Velocity") # Top Layer velocity top_layer = ax2.plot(x, u_1(cd), 'b', linestyle=plot.surface_linestyle, label="Top Layer velocity") # Add legend ax2.legend(loc=4) ax2.set_title('') # ax1.set_title('Layer Velocities') ax2.set_ylabel('Velocities (m/s)') ax2.set_xlabel('x (m)') ax2.set_xlim(xlimits) ax2.set_ylim(ylimits_velocities) # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd: twin_axes(cd, xlimits) # ======================================================================== # Fill plot zoom # ======================================================================== plotfigure = plotdata.new_plotfigure(name='full_zoom') plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd: twin_axes(cd, xlimits_zoomed) # ======================================================================== # Momentum # ======================================================================== plotfigure = plotdata.new_plotfigure(name="momentum") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Momentum" plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_momentum # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 1 plotitem.plotstyle = 'b-' plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 3 plotitem.plotstyle = 'k--' plotitem.show = True # ======================================================================== # h-values # ======================================================================== plotfigure = plotdata.new_plotfigure(name='depths') plotfigure.show = False plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(2,1,1)' plotaxes.title = 'Depths' plotaxes.xlimits = xlimits plotaxes.afteraxes = jump_afteraxes # plotaxes.ylimits = [-1.0,0.5] # plotaxes.xlimits = [0.45,0.55] # plotaxes.xlimits = [0.0,2000.0] # plotaxes.ylimits = [-2000.0,100.0] # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 0 plotitem.plotstyle = '-' plotitem.color = (0.2, 0.8, 1.0) plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 2 plotitem.color = 'b' plotitem.plotstyle = '-' plotitem.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(2,1,2)' plotaxes.title = 'Depths Zoomed' plotaxes.afteraxes = jump_afteraxes # plotaxes.xlimits = [0.0,1.0] # plotaxes.ylimits = [-1.0,0.5] plotaxes.xlimits = [0.45, 0.55] # plotaxes.xlimits = [0.0,2000.0] # plotaxes.ylimits = [-2000.0,100.0] # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 0 plotitem.plotstyle = 'x' plotitem.color = (0.2, 0.8, 1.0) plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 2 plotitem.color = 'b' plotitem.plotstyle = '+' plotitem.show = True # ======================================================================== # Plot Layer Velocities # ======================================================================== plotfigure = plotdata.new_plotfigure(name='velocities') plotfigure.show = False plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(1,2,1)' plotaxes.title = "Layer Velocities" plotaxes.xlimits = 'auto' plotaxes.ylimits = 'auto' # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = u_1 plotitem.color = 'b' plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.color = (0.2, 0.8, 1.0) plotitem.plot_var = u_2 plotitem.show = True # 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' # pointer for top of index 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 setplot(plotdata, rho, dry_tolerance): #-------------------------- """ Specify what is to be plotted at each frame. Input: plotdata, an instance of pyclaw.plotters.data.ClawPlotData. Output: a modified version of plotdata. """ def jump_afteraxes(current_data): # Plot position of jump on plot mpl.hold(True) mpl.plot([0.5, 0.5], [-10.0, 10.0], 'k--') mpl.plot([0.0, 1.0], [0.0, 0.0], 'k--') mpl.hold(False) mpl.title('Layer Velocities') # Load bathymetery b = Solution(0, path=plotdata.outdir, read_aux=True).state.aux[bathy_index, :] # Load gravitation g = Solution(0, path=plotdata.outdir, read_aux=True).state.problem_data['g'] def bathy(cd): return b def kappa(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[kappa_index, :] def wind(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[wind_index, :] def h_1(cd): return cd.q[0, :] / rho[0] def h_2(cd): return cd.q[2, :] / rho[1] def eta_2(cd): return h_2(cd) + bathy(cd) def eta_1(cd): return h_1(cd) + eta_2(cd) def u_1(cd): index = np.nonzero(h_1(cd) > dry_tolerance) u_1 = np.zeros(h_1(cd).shape) u_1[index] = cd.q[1, index] / cd.q[0, index] index_max = np.where(u_1 > 0.5) u_1[index_max] = 0.5 return u_1 def u_2(cd): index = np.nonzero(h_2(cd) > dry_tolerance) u_2 = np.zeros(h_2(cd).shape) u_2[index] = cd.q[3, index] / cd.q[2, index] #limit the velocity index_max = np.where(u_2 > 0.5) u_2[index_max] = 0.5 return u_2 # def entropy_at_x(q, index): # h_1i=q[0,index] / rho[0] # h_2i=q[2,index] / rho[1] # u_1i=q[1,index] / q[0,index] # u_2i=q[3,index] / q[2,index] # entropy_at_x = rho[0]*1/2*(h_1i*(u_1i)**2+g*(h_1i)**2) + rho[1]*1/2*(h_2i*(u_2i)**2+g*(h_2i)**2) + rho[0]*g*h_1i*h_2i + g*b[index]*(rho[0]*h_1i+rho[1]*h_2i) # return entropy_at_x def entropy(cd): index = np.nonzero( np.all([h_1(cd) > dry_tolerance, h_2(cd) > dry_tolerance], axis=0)) entropy = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) h_1i = cd.q[0, index] / rho[0] h_2i = cd.q[2, index] / rho[1] u_1i = cd.q[1, index] / cd.q[0, index] u_2i = cd.q[3, index] / cd.q[2, index] entropy[index] = rho[0] * 1 / 2 * ( h_1i * (u_1i)**2 + g * (h_1i)**2) + rho[1] * 1 / 2 * ( h_2i * (u_2i)**2 + g * (h_2i)**2) + rho[0] * g * h_1i * h_2i + g * b[index] * ( rho[0] * h_1i + rho[1] * h_2i) return entropy # def entropy_flux_at_x(q, index): # h_1i=q[0,index] / rho[0] # h_2i=q[2,index] / rho[1] # u_1i=q[1,index] / q[0,index] # u_2i=q[3,index] / q[2,index] # entropy_flux_at_x = rho[0]*(h_1i*(u_1i**2)/2+g*(h_1i**2))*u_1i + rho[1]*(h_2i*(u_2i**2)/2+g*(h_2i**2))*u_2i + rho[0]*g*h_1i*h_2i*(u_1i+u_2i) + g*b[index]*(rho[0]*h_1i*u_1i # + rho[1]*h_2i*u_2i) # #print(entropy_flux_at_x) # return entropy_flux_at_x def entropy_flux(cd): index = np.nonzero( np.all([h_1(cd) > dry_tolerance, h_2(cd) > dry_tolerance], axis=0)) entropy_flux = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) h_1i = cd.q[0, index] / rho[0] h_2i = cd.q[2, index] / rho[1] u_1i = cd.q[1, index] / cd.q[0, index] u_2i = cd.q[3, index] / cd.q[2, index] entropy_flux[index] = rho[0] * ( h_1i * (u_1i**2) / 2 + g * (h_1i**2)) * u_1i + rho[1] * ( h_2i * (u_2i**2) / 2 + g * (h_2i**2)) * u_2i + rho[0] * g * h_1i * h_2i * ( u_1i + u_2i) + g * b[index] * (rho[0] * h_1i * u_1i + rho[1] * h_2i * u_2i) return entropy_flux def entropy_condition_is_valid(cd): index_t = int(cd.frameno) if index_t > 0: #entropy at t=0 doesn't exist (x, ) = np.nonzero( np.all([h_1(cd) > dry_tolerance, h_2(cd) > dry_tolerance], axis=0)) len_x = len(x) delta_t = Solution( index_t, path=plotdata.outdir, read_aux=True).t - Solution( index_t - 1, path=plotdata.outdir, read_aux=True).t delta_x = cd.dx entropy_cond = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) for index_x in range(len_x - 1): index_x_next = index_x + 1 entropy_flux_actual = entropy_flux(cd)[index_x] entropy_flux_prev = entropy_flux(cd)[index_x_next] entropy_next = entropy(cd)[index_x] entropy_actual = entropy( Solution(index_t - 1, path=plotdata.outdir, read_aux=True))[index_x] entropy_cond[index_x] = entropy_next - entropy_actual + ( delta_t / delta_x) * (entropy_flux_actual - entropy_flux_prev) # if index_t == 67 or index_t==68 or index_t==69 or index_t==70 : # print('=======================================') # print(entropy_flux_actual) # print(entropy_flux_prev) # print(delta_t/delta_x) # print(entropy) # print(entropy_prev) # print(entropy_cond) return entropy_cond else: return ([0] * 500) def dry_tolerance_(cd): return ([dry_tolerance] * (len(cd.q[1]))) plotdata.clearfigures() # clear any old figures,axes,items data # Window Settings xlimits = [0.0, 1.0] xlimits_zoomed = [0.45, 0.55] ylimits_momentum = [-0.004, 0.004] ylimits_depth = [-1.0, 0.2] ylimits_depth_zoomed = ylimits_depth ylimits_velocities = [-0.75, 0.75] ylimits_velocities_zoomed = ylimits_velocities y_limits_entropy = [-5.0, 0.5] y_limits_entropy_flux = [-0.023, 0.013] y_limits_entropy_condition = y_limits_entropy_flux y_limits_entropy_shared = y_limits_entropy_flux # ======================================================================== # Depth and Momentum Plot # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Depth and Momentum') plotfigure.show = True def twin_axes(cd, xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212, sharex=ax1) # the velocity scale # Bottom layer ax1.fill_between(x, bathy(cd), eta_1(cd), color=plot.bottom_color) # Top Layer ax1.fill_between(x, eta_1(cd), eta_2(cd), color=plot.top_color) # Plot bathy ax1.plot(x, bathy(cd), 'k', linestyle=plot.bathy_linestyle) # Plot internal layer ax1.plot(x, eta_2(cd), 'k', linestyle=plot.internal_linestyle) # Plot surface ax1.plot(x, eta_1(cd), 'k', linestyle=plot.surface_linestyle) # Remove ticks from top plot locs, labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs, labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.2f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(ylimits_depth) # ax1.set_xlabel('x') ax1.set_ylabel('Depth (m)') # Bottom layer velocity bottom_layer = ax2.plot(x, u_2(cd), 'k', linestyle=plot.internal_linestyle, label="Bottom Layer Velocity") # Top Layer velocity top_layer = ax2.plot(x, u_1(cd), 'b', linestyle=plot.surface_linestyle, label="Top Layer velocity") # Add legend ax2.legend(loc=4) ax2.set_title('') # ax1.set_title('Layer Velocities') ax2.set_ylabel('Velocities (m/s)') ax2.set_xlabel('x (m)') ax2.set_xlim(xlimits) ax2.set_ylim(ylimits_velocities) # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd: twin_axes(cd, xlimits) # ======================================================================== # Fill plot zoom # ======================================================================== plotfigure = plotdata.new_plotfigure(name='full_zoom') plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd: twin_axes(cd, xlimits_zoomed) # ======================================================================== # Momentum # ======================================================================== plotfigure = plotdata.new_plotfigure(name="momentum") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Momentum" plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_momentum # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 1 plotitem.plotstyle = 'b-' plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 3 plotitem.plotstyle = 'k--' plotitem.show = True # ======================================================================== # h-valuesplot # ======================================================================== plotfigure = plotdata.new_plotfigure(name='depths') plotfigure.show = False plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(2,1,1)' plotaxes.title = 'Depths' plotaxes.xlimits = xlimits plotaxes.afteraxes = jump_afteraxes # plotaxes.ylimits = [-1.0,0.5] # plotaxes.xlimits = [0.45,0.55] # plotaxes.xlimits = [0.0,2000.0] # plotaxes.ylimits = [-2000.0,100.0] # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 0 plotitem.plotstyle = '-' plotitem.color = (0.2, 0.8, 1.0) plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 2 plotitem.color = 'b' plotitem.plotstyle = '-' plotitem.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(2,1,2)' plotaxes.title = 'Depths Zoomed' plotaxes.afteraxes = jump_afteraxes # plotaxes.xlimits = [0.0,1.0] # plotaxes.ylimits = [-1.0,0.5] plotaxes.xlimits = [0.45, 0.55] # plotaxes.xlimits = [0.0,2000.0] # plotaxes.ylimits = [-2000.0,100.0] # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 0 plotitem.plotstyle = 'x' plotitem.color = (0.2, 0.8, 1.0) plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 2 plotitem.color = 'b' plotitem.plotstyle = '+' plotitem.show = True # ======================================================================== # Plot Layer Velocities # ======================================================================== plotfigure = plotdata.new_plotfigure(name='velocities') plotfigure.show = False plotaxes = plotfigure.new_plotaxes() #plotaxes.axescmd = 'subplot(1,2,1)' plotaxes.title = "Layer Velocities" plotaxes.xlimits = 'auto' plotaxes.ylimits = 'auto' # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = u_1 plotitem.color = 'b' plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.color = (0.2, 0.8, 1.0) plotitem.plot_var = u_2 plotitem.show = True # 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' # pointer for top of index 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? # ======================================================================== # h-values # ======================================================================== plotfigure = plotdata.new_plotfigure(name="Depths and dry tolerance") plotfigure.show = True def depths_same_plot(cd, xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(111) # Bottom layer ax1.fill_between(x, bathy(cd), eta_1(cd), color=plot.bottom_color) # Top Layer ax1.fill_between(x, eta_1(cd), eta_2(cd), color=plot.top_color) # Plot bathy ax1.plot(x, bathy(cd), 'k', linestyle=plot.bathy_linestyle) # Plot internal layer ax1.plot(x, eta_2(cd), 'k', linestyle=plot.internal_linestyle) # Plot surface ax1.plot(x, eta_1(cd), 'k', linestyle=plot.surface_linestyle) # Plot dry tolerance ax1.plot(x, dry_tolerance_(cd), 'k', linestyle=':', color='red') # Remove ticks from top plot locs, labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs, labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.2f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(ylimits_depth) # ax1.set_xlabel('x') ax1.set_ylabel('Depth (m)') # # This does not work on all versions of matplotlib # try: # mpl.subplots_adjust(hspace=0.1) # except: # pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd: depths_same_plot(cd, xlimits) # ==================================================== # Plot Entropy # ==================================================== plotfigure = plotdata.new_plotfigure(name="entropy") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Entropy" plotaxes.xlimits = xlimits plotaxes.ylimits = 'auto' # Entropy plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = entropy plotitem.color = 'b' plotitem.show = True # 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' # pointer for top of index 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? # ==================================================== # Plot Entropy flux # ==================================================== plotfigure = plotdata.new_plotfigure(name="entropy flux") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Entropy flux" plotaxes.xlimits = xlimits plotaxes.ylimits = y_limits_entropy_flux # Entropy plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = entropy_flux plotitem.color = 'b' plotitem.show = True # 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' # pointer for top of index 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? # ==================================================== # Plot Entropy Condition # ==================================================== plotfigure = plotdata.new_plotfigure(name="entropy condition") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Entropy Condition" plotaxes.xlimits = xlimits plotaxes.ylimits = y_limits_entropy_condition # Entropy plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = entropy_condition_is_valid plotitem.color = 'b' plotitem.show = True # 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' # pointer for top of index 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 setplot(plotdata, wave_family, rho, dry_tolerance): #-------------------------- """ Specify what is to be plotted at each frame. Input: plotdata, an instance of pyclaw.plotters.data.ClawPlotData. Output: a modified version of plotdata. """ # Load bathymetry b = Solution(0, path=plotdata.outdir, read_aux=True).state.aux[bathy_index, :] def bathy(cd): return b def kappa(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[kappa_index, :] def wind(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[wind_index, :] def h_1(cd): return cd.q[0, :] / rho[0] def h_2(cd): return cd.q[2, :] / rho[1] def eta_2(cd): return h_2(cd) + bathy(cd) def eta_1(cd): return h_1(cd) + eta_2(cd) def u_1(cd): index = np.nonzero(h_1(cd) > dry_tolerance) u_1 = np.zeros(h_1(cd).shape) u_1[index] = cd.q[1, index] / cd.q[0, index] return u_1 def u_2(cd): index = np.nonzero(h_2(cd) > dry_tolerance) u_2 = np.zeros(h_2(cd).shape) u_2[index] = cd.q[3, index] / cd.q[2, index] return u_2 def jump_afteraxes(current_data): # Plot position of jump on plot mpl.hold(True) mpl.plot([0.5, 0.5], [-10.0, 10.0], 'k--') mpl.plot([0.0, 1.0], [0.0, 0.0], 'k--') mpl.hold(False) mpl.title('') plotdata.clearfigures() # clear any old figures,axes,items data # Window Settings xlimits = [0.0, 1.0] xlimits_zoomed = [0.45, 0.55] ylimits_momentum = [-0.004, 0.004] # External wave if wave_family == 4: ylimits_velocities = [-0.8, 0.8] ylimits_depth = [-1.0, 0.3] ylimits_depth_zoomed = [-1.0, 0.4] ylimits_velocities_zoomed = [-0.1, 0.75] # internal wave elif wave_family == 3: ylimits_velocities = [-0.15, 0.15] ylimits_velocities_zoomed = ylimits_velocities ylimits_depth = [-1.0, 0.2] ylimits_depth_zoomed = ylimits_depth # ======================================================================== # Depth and Momentum Plot # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Depth and Momentum', figno=14) plotfigure.show = True def twin_axes(cd): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis depth_axes = fig.add_subplot(211) vel_axes = fig.add_subplot( 212) #,sharex=depth_axes) # the velocity scale # Bottom layer depth_axes.fill_between(x, bathy(cd), eta_1(cd), color=plot.bottom_color) # Top Layer depth_axes.fill_between(x, eta_1(cd), eta_2(cd), color=plot.top_color) # Plot bathy depth_axes.plot(x, bathy(cd), 'k', linestyle=plot.bathy_linestyle) # Plot internal layer depth_axes.plot(x, eta_2(cd), 'k', linestyle=plot.internal_linestyle) # Plot surface depth_axes.plot(x, eta_1(cd), 'k', linestyle=plot.surface_linestyle) # Remove ticks from top plot num_ticks = len(depth_axes.xaxis.get_ticklocs()) depth_axes.xaxis.set_ticklabels(["" for n in xrange(num_ticks)]) # ax1.set_title('') depth_axes.set_title('Wave Family %s Perturbation at t = %3.2f' % (wave_family, cd.t)) depth_axes.set_xlim(xlimits) depth_axes.set_ylim(ylimits_depth) # depth_axes.set_xlabel('x') depth_axes.set_ylabel('Depth (m)') # Bottom layer velocity bottom_layer = vel_axes.plot(x, u_2(cd), 'k', linestyle=plot.internal_linestyle, label="Bottom Layer Velocity") # Top Layer velocity top_layer = vel_axes.plot(x, u_1(cd), 'b', linestyle=plot.surface_linestyle, label="Top Layer velocity") # Add legend vel_axes.legend(loc=4) vel_axes.set_title('') # vel_axes.set_title('Layer Velocities') vel_axes.set_ylabel('Velocities (m/s)') vel_axes.set_xlabel('x (m)') vel_axes.set_xlim(xlimits) vel_axes.set_ylim(ylimits_velocities) # Add axis labels (not sure why this needs to be done) locs = vel_axes.xaxis.get_ticklocs() vel_axes.xaxis.set_ticklabels([str(loc) for loc in locs]) # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = twin_axes # ======================================================================== # Fill plot zoom # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Depth and Momentum Zoomed', figno=1) plotfigure.show = True def twin_axes_zoomed(cd): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis depth_axes = fig.add_subplot(211) vel_axes = fig.add_subplot( 212) #,sharex=depth_axes) # the velocity scale # Bottom layer depth_axes.fill_between(x, bathy(cd), eta_1(cd), color=plot.bottom_color) # Top Layer depth_axes.fill_between(x, eta_1(cd), eta_2(cd), color=plot.top_color) # Plot bathy depth_axes.plot(x, bathy(cd), color='k', linestyle=plot.bathy_linestyle) # Plot internal layer depth_axes.plot(x, eta_2(cd), 'kx') # Plot surface depth_axes.plot(x, eta_1(cd), 'k+') # Remove ticks from top plot num_ticks = len(depth_axes.xaxis.get_ticklocs()) depth_axes.xaxis.set_ticklabels(["" for n in xrange(num_ticks)]) # ax1.set_title('') depth_axes.set_title('Wave Family %s Perturbation at t = %3.2f' % (wave_family, cd.t)) depth_axes.set_xlim(xlimits_zoomed) depth_axes.set_ylim(ylimits_depth_zoomed) # depth_axes.set_xlabel('x') depth_axes.set_ylabel('Depth (m)') # Bottom layer velocity bottom_layer = vel_axes.plot(x, u_2(cd), 'k+', label="Bottom Layer Velocity") # Top Layer velocity top_layer = vel_axes.plot(x, u_1(cd), 'bx', label="Top Layer velocity") # Add legend vel_axes.legend(loc=4) vel_axes.set_title('') # vel_axes.set_title('Layer Velocities') vel_axes.set_ylabel('Velocities (m/s)') vel_axes.set_xlabel('x (m)') vel_axes.set_xlim(xlimits_zoomed) vel_axes.set_ylim(ylimits_velocities_zoomed) # Add axis labels (not sure why this needs to be done) locs = vel_axes.xaxis.get_ticklocs() vel_axes.xaxis.set_ticklabels([str(loc) for loc in locs]) # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = twin_axes_zoomed # ======================================================================== # Momentum # ======================================================================== plotfigure = plotdata.new_plotfigure(name="momentum", figno=134) plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Momentum" plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_momentum # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 1 plotitem.plotstyle = 'b-' plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 3 plotitem.plotstyle = 'k-' plotitem.show = True # 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 = [0, 20, 25, 30, 50] # list of frames to print # 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' # pointer for top of index 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 wind(cd): return Solution(cd.frameno, path=plotdata.outdir, read_aux=True).state.aux[wind_index, :]
def setplot(plotdata,rho,dry_tolerance): #-------------------------- """ Specify what is to be plotted at each frame. Input: plotdata, an instance of pyclaw.plotters.data.ClawPlotData. Output: a modified version of plotdata. """ def jump_afteraxes(current_data): # Plot position of jump on plot mpl.hold(True) mpl.plot([0.5,0.5],[-10.0,10.0],'k--') mpl.plot([0.0,1.0],[0.0,0.0],'k--') mpl.hold(False) mpl.title('Layer Velocities') # Load bathymetery b = Solution(0, path=plotdata.outdir,read_aux=True).state.aux[bathy_index,:] # Load gravitation g = Solution(0, path=plotdata.outdir,read_aux=True).state.problem_data['g'] # Load one minus r one_minus_r=Solution(0, path=plotdata.outdir,read_aux=True).state.problem_data['one_minus_r'] def bathy(cd): return b def kappa(cd): return Solution(cd.frameno,path=plotdata.outdir,read_aux=True).state.aux[kappa_index,:] def wind(cd): return Solution(cd.frameno,path=plotdata.outdir,read_aux=True).state.aux[wind_index,:] def h_1(cd): return cd.q[0,:] / rho[0] def h_2(cd): return cd.q[2,:] / rho[1] def eta_2(cd): return h_2(cd) + bathy(cd) def eta_1(cd): return h_1(cd) + eta_2(cd) def u_1(cd): index = np.nonzero(h_1(cd) > dry_tolerance) u_1 = np.zeros(h_1(cd).shape) u_1[index] = cd.q[1,index] / cd.q[0,index] return u_1 def u_2(cd): index = np.nonzero(h_2(cd) > dry_tolerance) u_2 = np.zeros(h_2(cd).shape) u_2[index] = cd.q[3,index] / cd.q[2,index] return u_2 def froude_number(u,h): Fr=abs(u)/((g*h)**(1/2)) return Fr def Richardson_number(cd): index=np.nonzero(h_1(cd)+h_2(cd)>0) Ri=np.zeros(h_1(cd).shape) Ri[index]=(u_1(cd)[index]-u_2(cd)[index])**2/(g* one_minus_r *(h_1(cd)[index]+h_2(cd)[index])) return(Ri) def eigenspace_velocity(cd): #Problem for left and right total_depth_l = h_1(cd)+h_2(cd) total_depth_r = h_1(cd)+h_2(cd) mult_depth_l = h_1(cd)*h_2(cd) mult_depth_r = h_1(cd)*h_2(cd) s = np.zeros((4, len(h_1(cd)))) s[0,:]=(h_1(cd)[:]*u_1(cd)[:] + h_2(cd)[:]*u_2(cd)[:]) / total_depth_l - np.sqrt(g*total_depth_l) s[1,:]=(h_2(cd)[:]*u_1(cd)[:] + h_1(cd)[:]*u_2(cd)[:]) / total_depth_l - np.sqrt(g*one_minus_r*mult_depth_l/total_depth_l * (1-(u_1(cd)[:]-u_2(cd)[:])**2/(g*one_minus_r*total_depth_l))) s[2,:]=(h_2(cd)[:]*u_1(cd)[:] + h_1(cd)[:]*u_2(cd)[:]) / total_depth_l + np.sqrt(g*one_minus_r*mult_depth_l/total_depth_l * (1-(u_1(cd)[:]-u_2(cd)[:])**2/(g*one_minus_r*total_depth_l))) s[3,:]=(h_1(cd)[:]*u_1(cd)[:] + h_2(cd)[:]*u_2(cd)[:]) / total_depth_l - np.sqrt(g*total_depth_l) if isinstance(s[1,:], complex) or isinstance(s[2,:], complex): print("Hyperbolicity lost for the speed at %s", cd.frameno) alpha=np.zeros((4,len(h_1(cd)))) alpha[0:1,:]=((s[0:1,:]-u_1(cd)[:])**2 - g*h_1(cd)[:])/(g*h_1(cd)[:]) alpha[2:3,:]=((s[2:3,:]-u_1(cd)[:])**2 - g*h_1(cd)[:])/(g*h_1(cd)[:]) eig_vec = np.zeros((4,4,len(h_1(cd)))) eig_vec[0,:,:] = 1.0 eig_vec[1,:,:] = s[:,:] eig_vec[2,:,:] = alpha[:,:] eig_vec[3,:,:] = s[:,:]*alpha[:,:] return(eig_vec) def eigenspace_velocity_3(cd): total_depth_l = h_1(cd)+h_2(cd) total_depth_r = h_1(cd)+h_2(cd) mult_depth_l = h_1(cd)*h_2(cd) mult_depth_r = h_1(cd)*h_2(cd) s = np.zeros(h_1(cd).shape) s = (h_2(cd)*u_1(cd) + h_1(cd)[:]*u_2(cd) / total_depth_l) + np.sqrt(g*one_minus_r*mult_depth_l/total_depth_l * (1-(u_1(cd)-u_2(cd))**2/(g*one_minus_r*total_depth_l))) alpha=np.zeros(h_1(cd).shape) alpha=((s-u_1(cd))**2 - g*h_1(cd))/(g*h_1(cd)) eig_vec=alpha*s return(eig_vec) def eigenspace_velocity_4(cd): total_depth_l = h_1(cd)+h_2(cd) total_depth_r = h_1(cd)+h_2(cd) mult_depth_l = h_1(cd)*h_2(cd) mult_depth_r = h_1(cd)*h_2(cd) s = np.zeros(h_1(cd).shape) s=(h_1(cd)*u_1(cd) + h_2(cd)*u_2(cd)) / total_depth_l - np.sqrt(g*total_depth_l) alpha=np.zeros(h_1(cd).shape) alpha=((s-u_1(cd))**2 - g*h_1(cd))/(g*h_1(cd)) eig_vec=s*alpha return(eig_vec) def eigenvalues(cd): index = np.nonzero(np.all([h_1(cd) > dry_tolerance, h_2(cd)>dry_tolerance], axis=0)) eigenvalues1 = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) eigenvalues2 = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) eigenvalues3 = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) eigenvalues4 = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) frac = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) sqrt1 = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) sqrt2 = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) frac[index] = (h_1(cd)[index]*u_2(cd)[index] + h_2(cd)[index]*u_1(cd)[index])/(h_1(cd)[index] + h_2(cd)[index]) sqrt1[index] = np.sqrt(g*(h_1(cd)[index] + h_2(cd)[index])) sqrt2[index] = np.sqrt(one_minus_r*g*h_1(cd)[index]*h_2(cd)[index]/(h_1(cd)[index] + h_2(cd)[index])*(1-(u_1(cd)[index]-u_2(cd)[index])**2/(one_minus_r*g*(h_1(cd)[index] + h_2(cd)[index])))) eigenvalues1[index] = frac[index]-sqrt1[index] eigenvalues2[index] = frac[index]-sqrt2[index] eigenvalues3[index] = frac[index]+sqrt2[index] eigenvalues4[index] = frac[index]+sqrt1[index] return([eigenvalues1, eigenvalues2, eigenvalues3, eigenvalues4]) def entropy(cd): index = np.nonzero(np.all([h_1(cd) > dry_tolerance, h_2(cd)>dry_tolerance], axis=0)) entropy = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) h_1i=cd.q[0,index] / rho[0] h_2i=cd.q[2,index] / rho[1] u_1i=cd.q[1,index] / cd.q[0,index] u_2i=cd.q[3,index] / cd.q[2,index] entropy[index] = rho[0]*1/2*(h_1i*(u_1i)**2+g*(h_1i)**2) + rho[1]*1/2*(h_2i*(u_2i)**2+g*(h_2i)**2) + rho[0]*g*h_1i*h_2i + g*b[index]*(rho[0]*h_1i+rho[1]*h_2i) return entropy def entropy_flux(cd): index = np.nonzero(np.all([h_1(cd)>dry_tolerance, h_2(cd)>dry_tolerance], axis=0)) entropy_flux = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) h_1i=cd.q[0,index] / rho[0] h_2i=cd.q[2,index] / rho[1] u_1i=cd.q[1,index] / cd.q[0,index] u_2i=cd.q[3,index] / cd.q[2,index] entropy_flux[index] = rho[0]*(h_1i*(u_1i**2)/2+g*(h_1i**2))*u_1i + rho[1]*(h_2i*(u_2i**2)/2+g*(h_2i**2))*u_2i + rho[0]*g*h_1i*h_2i*(u_1i+u_2i) + g*b[index]*(rho[0]*h_1i*u_1i + rho[1]*h_2i*u_2i) return entropy_flux def entropy_condition_is_valid(cd): index_t = int(cd.frameno) if index_t>0 : #entropy at t=0 doesn't exist (x,) = np.nonzero(np.all([h_1(cd)>dry_tolerance, h_2(cd)>dry_tolerance],axis=0)) len_x = len(x) delta_t = Solution(index_t, path=plotdata.outdir,read_aux=True).t - Solution(index_t-1, path=plotdata.outdir,read_aux=True).t delta_x = cd.dx entropy_cond = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) for index_x in range(len_x-1): index_x_next = index_x + 1 entropy_flux_actual = entropy_flux(cd)[index_x] entropy_flux_prev = entropy_flux(cd)[index_x_next] entropy_next=entropy(cd)[index_x] entropy_actual=entropy(Solution(index_t-1, path=plotdata.outdir,read_aux=True))[index_x] entropy_cond[index_x]= entropy_next-entropy_actual + (delta_t/delta_x)*(entropy_flux_actual-entropy_flux_prev) #print(eigenspace_velocity(cd)) return entropy_cond else : return([0]*500) def froude_number_1(cd): index=np.nonzero(h_1(cd) > dry_tolerance) Fr=np.zeros(h_1(cd).shape) Fr[index] = froude_number(u_1(cd)[index],h_1(cd)[index]) #print(Fr) return(Fr) def froude_number_2(cd): index=np.nonzero(h_2(cd) > dry_tolerance) Fr=np.zeros(h_2(cd).shape) Fr[index] = froude_number(u_2(cd)[index],h_2(cd)[index]) #print(Fr) return(Fr) def composite_Froude_nb(cd): index = np.nonzero(np.all([h_1(cd)>dry_tolerance, h_2(cd)>dry_tolerance], axis=0)) Fr = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) Fr1_carre = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) Fr2_carre = np.zeros(min(h_1(cd).shape, h_2(cd).shape)) Fr1_carre[index] = (u_1(cd)[index])**2/(one_minus_r * g * h_1(cd)[index]) Fr2_carre[index] = (u_2(cd)[index])**2/(one_minus_r * g * h_2(cd)[index]) Fr[index] = np.sqrt( Fr1_carre[index] + Fr2_carre[index] ) #Fr[index] = np.sqrt(Fr1_carre[index] + Fr2_carre[index] - one_minus_r * np.sqrt(Fr1_carre) * np.sqrt(Fr2_carre)) return(Fr) def dry_tolerance_(cd): return ([dry_tolerance]*(len(cd.q[1])) ) def limit_entropy_condition(cd): return ([0]*(len(cd.q[1]))) def flow_type(cd): return ([1]*len(cd.q[1])) def charac(cd): values1=[0]*500 values2=[0]*500 (eigenvalues1, eigenvalues2, eigenvalues3, eigenvalues4) = eigenvalues(cd) values1[0:249]=[(k-500)*eigenvalues1[249]/1000 for k in range(0,500,2)] values2[0:249]=[(k-500)*eigenvalues2[249]/1000 for k in range(0,500,2)] values2[250:501]=[(k-500)*eigenvalues3[250]/1000 for k in range(500,1000,2)] values1[250:501]=[(k-500)*eigenvalues4[250]/1000 for k in range(500,1000,2)] return([values1, values2]) plotdata.clearfigures() # clear any old figures,axes,items data # Window Settings xlimits = [0.0,1.0] xlimits_zoomed = [0.45,0.55] ylimits_momentum = [-5.0,5.0] ylimits_depth = [-1.0,0.5] ylimits_depth_zoomed = ylimits_depth ylimits_velocities = [-8.75,8.75] ylimits_velocities_zoomed = ylimits_velocities y_limits_depth_only=[0.,5.0] y_limits_entropy = [-5.0 , 0.5] y_limits_entropy_flux = [-0.023 , 0.003 ] y_limits_entropy_condition = y_limits_entropy_flux y_limits_entropy_shared =y_limits_entropy_flux y_limits_richardson = [-0.1,17.0] y_limits_Froude=[-1.0,10.0] y_limits_eigenspace=[-12.0,12.0] y_limits_eigenspace_4=[-30.0,15.0] y_limits_charac=[-5.0,10.0] # ======================================================================== # Depth and Momentum Plot # ======================================================================== plotfigure = plotdata.new_plotfigure(name='Depth and Momentum') plotfigure.show = False def twin_axes(cd,xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212,sharex=ax1) # the velocity scale # Bottom layer ax1.fill_between(x,bathy(cd),eta_1(cd),color=plot.bottom_color) # Top Layer ax1.fill_between(x,eta_1(cd),eta_2(cd),color=plot.top_color) # Plot bathy ax1.plot(x,bathy(cd),'k',linestyle=plot.bathy_linestyle) # Plot internal layer ax1.plot(x,eta_2(cd),'k',linestyle=plot.internal_linestyle) # Plot surface ax1.plot(x,eta_1(cd),'k',linestyle=plot.surface_linestyle) # Remove ticks from top plot locs,labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs,labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.5f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(ylimits_depth) # ax1.set_xlabel('x') ax1.set_ylabel('Depth (m)') # Bottom layer velocity bottom_layer = ax2.plot(x,u_2(cd),'k',linestyle=plot.internal_linestyle,label="Bottom Layer Velocity") # Top Layer velocity top_layer = ax2.plot(x,u_1(cd),'b',linestyle=plot.surface_linestyle,label="Top Layer velocity") # Add legend ax2.legend(loc=4) ax2.set_title('') # ax1.set_title('Layer Velocities') ax2.set_ylabel('Velocities (m/s)') ax2.set_xlabel('x (m)') ax2.set_xlim(xlimits) ax2.set_ylim(ylimits_velocities) # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd:twin_axes(cd,xlimits) # ======================================================================== # Fill plot zoom # ======================================================================== plotfigure = plotdata.new_plotfigure(name='full_zoom') plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd:twin_axes(cd,xlimits_zoomed) # ======================================================================== # Momentum # ======================================================================== plotfigure = plotdata.new_plotfigure(name="momentum") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Momentum" plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits_momentum # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 1 plotitem.plotstyle = 'b-' plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 3 plotitem.plotstyle = 'k--' plotitem.show = True # ======================================================================== # h-valuesplot # ======================================================================== plotfigure = plotdata.new_plotfigure(name='depths') plotfigure.show = False plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(2,1,1)' plotaxes.title = 'Depths' plotaxes.xlimits = xlimits plotaxes.afteraxes = jump_afteraxes # plotaxes.ylimits = [-1.0,0.5] # plotaxes.xlimits = [0.45,0.55] # plotaxes.xlimits = [0.0,2000.0] # plotaxes.ylimits = [-2000.0,100.0] # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 0 plotitem.plotstyle = '-' plotitem.color = (0.2,0.8,1.0) plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 2 plotitem.color = 'b' plotitem.plotstyle = '-' plotitem.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.axescmd = 'subplot(2,1,2)' plotaxes.title = 'Depths Zoomed' plotaxes.afteraxes = jump_afteraxes # plotaxes.xlimits = [0.0,1.0] # plotaxes.ylimits = [-1.0,0.5] plotaxes.xlimits = [0.45,0.55] # plotaxes.xlimits = [0.0,2000.0] # plotaxes.ylimits = [-2000.0,100.0] # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 0 plotitem.plotstyle = 'x' plotitem.color = (0.2,0.8,1.0) plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = 2 plotitem.color = 'b' plotitem.plotstyle = '+' plotitem.show = True # ======================================================================== # Plot Layer Velocities # ======================================================================== plotfigure = plotdata.new_plotfigure(name='velocities') plotfigure.show = False plotaxes = plotfigure.new_plotaxes() #plotaxes.axescmd = 'subplot(1,2,1)' plotaxes.title = "Layer Velocities" plotaxes.xlimits = 'auto' plotaxes.ylimits = 'auto' # Top layer plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = u_1 plotitem.color = 'b' plotitem.show = True # Bottom layer plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.color = (0.2,0.8,1.0) plotitem.plot_var = u_2 plotitem.show = True # 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' # pointer for top of index # 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? # ======================================================================== # h-values # ======================================================================== plotfigure = plotdata.new_plotfigure(name = "Depths and dry tolerance") plotfigure.show = True def depths_same_plot(cd,xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(111) # Bottom layer ax1.fill_between(x,bathy(cd),eta_1(cd),color=plot.bottom_color) # Top Layer ax1.fill_between(x,eta_1(cd),eta_2(cd),color=plot.top_color) # Plot bathy ax1.plot(x,bathy(cd),'k',linestyle=plot.bathy_linestyle) # Plot internal layer ax1.plot(x,eta_2(cd),'k',linestyle=plot.internal_linestyle) # Plot surface ax1.plot(x,eta_1(cd),'k',linestyle=plot.surface_linestyle) #plot depth 1 #ax1.plot(x,h_1(cd),'k',color='green') #plot_depth 2 #ax1.plot(x,h_2(cd),'k',color='orange') # Plot dry tolerance ax1.plot(x,dry_tolerance_(cd),'k',linestyle=':', color = 'red') # Remove ticks from top plot locs,labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs,labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.5f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(ylimits_depth) # ax1.set_xlabel('x') ax1.set_ylabel('Depth (m)') # # This does not work on all versions of matplotlib # try: # mpl.subplots_adjust(hspace=0.1) # except: # pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd:depths_same_plot(cd,xlimits) # ==================================================== # Plot Entropy # ==================================================== plotfigure = plotdata.new_plotfigure(name="Entropy") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Entropy" plotaxes.xlimits = xlimits plotaxes.ylimits = 'auto' # Entropy plotitem = plotaxes.new_plotitem(plot_type='1d') plotitem.plot_var = entropy plotitem.color = 'b' plotitem.show = True # # 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' # pointer for top of index # 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? # ==================================================== # Plot Entropy flux # ==================================================== plotfigure = plotdata.new_plotfigure(name="Entropy flux") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Entropy flux" plotaxes.xlimits = xlimits plotaxes.ylimits = 'auto' # Entropy plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = entropy_flux plotitem.color = 'b' plotitem.show = True # 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' # pointer for top of index # 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? # ==================================================== # Plot Entropy Condition # ==================================================== plotfigure = plotdata.new_plotfigure(name="Entropy condition") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Entropy Condition" plotaxes.xlimits = xlimits plotaxes.ylimits = 'auto' # Entropy plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = entropy_condition_is_valid plotitem.color = 'b' plotitem.show = True # ==================================================== # Plot Richardson Number # ==================================================== plotfigure = plotdata.new_plotfigure(name="Kappa") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Richardson number" plotaxes.xlimits = xlimits plotaxes.ylimits = y_limits_richardson # Richardson plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = Richardson_number plotitem.color = 'b' plotitem.show = True # ======================================================================== # Froude number # ======================================================================== plotfigure = plotdata.new_plotfigure(name = "Froude number") plotfigure.show = False def froude_same_plot(cd,xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212,sharex=ax1) # Froude number 1 ax1.plot(x,froude_number_1(cd),'k',color = 'blue') # Plot limit flow type ax1.plot(x,flow_type(cd),'k',linestyle=':', color = 'red') # Remove ticks from top plot locs,labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs,labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.5f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(y_limits_Froude) # ax1.set_xlabel('x') ax1.set_ylabel('Froude number 1') # froude_number_2 ax2.plot(x,froude_number_2(cd),'k',color='green') # Plot limit flow type ax2.plot(x,flow_type(cd),'k',linestyle=':', color = 'red') # Add legend ax2.legend(loc=4) ax2.set_title('') # ax1.set_title('Layer Velocities') ax2.set_ylabel('Froude number 2') ax2.set_xlabel('x (m)') ax2.set_xlim(xlimits) ax2.set_ylim(y_limits_Froude) # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd:froude_same_plot(cd,xlimits) # ==================================================== # Plot Richardson Number # ==================================================== plotfigure = plotdata.new_plotfigure(name="Composite Froude") plotfigure.show = True plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Composite Froude number" plotaxes.xlimits = xlimits plotaxes.ylimits = 'auto' # Composite Froude number plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = composite_Froude_nb plotitem.color = 'b' plotitem.show = True # ======================================================================== # Eigenspaces # ======================================================================== plotfigure = plotdata.new_plotfigure(name = "Eigenspace") plotfigure.show = True def eigenspace_same_plot(cd,xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(221) ax2 = fig.add_subplot(223,sharex=ax1) ax3 = fig.add_subplot(222) ax4 = fig.add_subplot(224,sharex=ax3) # Eigenspace 1 ax1.plot(x,eigenspace_velocity(cd)[0,0,:],'k',color = 'blue') ax1.plot(x,eigenspace_velocity(cd)[0,1,:],'k',color = 'red') ax1.plot(x,eigenspace_velocity(cd)[0,2,:],'k',color = 'green') ax1.plot(x,eigenspace_velocity(cd)[0,3,:],'k',color = 'grey') #Eigenspace 2 ax2.plot(x,eigenspace_velocity(cd)[1,0,:],'k',color = 'blue') ax2.plot(x,eigenspace_velocity(cd)[1,1,:],'k',color = 'red') ax2.plot(x,eigenspace_velocity(cd)[1,2,:],'k',color = 'green') ax2.plot(x,eigenspace_velocity(cd)[1,3,:],'k',color = 'grey') #Eigenspace 3 ax3.plot(x,eigenspace_velocity(cd)[2,0,:],'k',color = 'blue') ax3.plot(x,eigenspace_velocity(cd)[2,1,:],'k',color = 'red') ax3.plot(x,eigenspace_velocity(cd)[2,2,:],'k',color = 'green') ax3.plot(x,eigenspace_velocity(cd)[2,3,:],'k',color = 'grey') #Eigenspace 4 ax4.plot(x,eigenspace_velocity(cd)[3,0,:],'k',color = 'blue') ax4.plot(x,eigenspace_velocity(cd)[3,1,:],'k',color = 'red') ax4.plot(x,eigenspace_velocity(cd)[3,2,:],'k',color = 'green') ax4.plot(x,eigenspace_velocity(cd)[3,3,:],'k',color = 'grey') # Remove ticks from top plot locs,labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs,labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.5f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(y_limits_eigenspace) ax1.set_ylabel('Eigenspace 1') # Add legend ax2.legend(loc=4) ax2.set_title('') ax2.set_ylabel('Eigenspace 2') ax2.set_xlabel('x (m)') ax2.set_xlim(xlimits) ax2.set_ylim(y_limits_eigenspace) ax3.set_xlim(xlimits) ax3.set_ylim(y_limits_eigenspace) #ax3.set_ylabel('Eigenspace 3') # Add legend ax4.legend(loc=4) ax4.set_title('') #ax4.set_ylabel('Eigenspace 4') ax4.set_xlabel('x (m)') ax4.set_xlim(xlimits) ax4.set_ylim(y_limits_eigenspace) # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd:eigenspace_same_plot(cd,xlimits) # ======================================================================== # Zoom eigenspaces # ======================================================================== plotfigure = plotdata.new_plotfigure(name = "Eigenspaces 4") plotfigure.show = True def eigenspace_same_plot_zoom(cd,xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(111) #Eigenspace 4 ax1.plot(x,eigenspace_velocity(cd)[3,0,:],'k',color = 'blue') ax1.plot(x,eigenspace_velocity(cd)[3,1,:],'k',color = 'red') ax1.plot(x,eigenspace_velocity(cd)[3,2,:],'k',color = 'green') ax1.plot(x,eigenspace_velocity(cd)[3,3,:],'k',color = 'grey') # Remove ticks from top plot locs,labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs,labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.5f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(y_limits_eigenspace_4) ax1.set_ylabel('Eigenspace 4') # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd:eigenspace_same_plot_zoom(cd,xlimits) # ==================================================== # Plot Eigenspace 3 # ==================================================== plotfigure = plotdata.new_plotfigure(name="Eigenspace 3") plotfigure.show = False plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Eigenspace 3" plotaxes.xlimits = xlimits plotaxes.ylimits = 'auto' # Richardson plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = eigenspace_velocity_3 plotitem.color = 'b' plotitem.show = True # ==================================================== # Plot Eigenspace 4 # ==================================================== plotfigure = plotdata.new_plotfigure(name="Eigenspace 4") plotfigure.show = False plotaxes = plotfigure.new_plotaxes() plotaxes.title = "Eigenspace 4" plotaxes.xlimits = xlimits plotaxes.ylimits = 'auto' # Richardson plotitem = plotaxes.new_plotitem(plot_type='1d_plot') plotitem.plot_var = eigenspace_velocity_4 plotitem.color = 'b' plotitem.show = True # ======================================================================== # Zoom eigenspaces # ======================================================================== plotfigure = plotdata.new_plotfigure(name = "Characteristic") plotfigure.show = True def charac_same_plot(cd,xlimits): fig = mpl.gcf() fig.clf() # Get x coordinate values x = cd.patch.dimensions[0].centers # Create axes for each plot, sharing x axis ax1 = fig.add_subplot(111) #Eigenspace 4 ax1.plot(x,charac(cd)[0],'k',color = 'blue') ax1.plot(x,charac(cd)[1],'k',color = 'green') #ax1.plot(x,charac(cd)[2],'k',color = 'green') #ax1.plot(x,charac(cd)[3],'k',color = 'grey') ax1.plot(x,limit_entropy_condition(cd),'k',linestyle=':',color = 'red') # Remove ticks from top plot locs,labels = mpl.xticks() labels = ['' for i in xrange(len(locs))] mpl.xticks(locs,labels) # ax1.set_title('') ax1.set_title('Solution at t = %3.5f' % cd.t) ax1.set_xlim(xlimits) ax1.set_ylim(y_limits_charac) ax1.set_ylabel('t') # This does not work on all versions of matplotlib try: mpl.subplots_adjust(hspace=0.1) except: pass plotaxes = plotfigure.new_plotaxes() plotaxes.afteraxes = lambda cd:charac_same_plot(cd,xlimits) # 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' # pointer for top of index 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