def plot_modes(files,acoef_file,quantity,quantity_replace,pic_dir="./",fc=fc_default): f = open(acoef_file) data = [[float(num) for num in line.split()] for line in f] f.close data = np.asarray(data) amin = np.amin(data) amax = np.amax(data) print("min(a_coef):", amin) print("max(a_coef):", amax) for mode,file in enumerate(files): plt_file = file.split("/")[-1] plt_file = plt_file.replace(quantity+"_",quantity_replace+"_") plt_file = plt_file.replace('h5','png') fig = plt.figure(44) fig.subplots_adjust(wspace=0.05,hspace=0.0) gs1 = gs.GridSpec(nrows=6,ncols=2) ax1 = plt.subplot(gs1[:5,0]) ax,cb,hplot = wt.plot_wabbit_file(file,cmap=fc,caxis_symmetric=True,dpi=600, \ shading='flat', \ block_edge_alpha=0.1, \ title=False, ticks=False, colorbar=False, fig=fig, ax=ax1) ax.set_title("$\Psi_{"+str(mode+1)+"}^\epsilon(x,y)$") # ax.set_xlabel("$x$") #ax.set_ylabel("$y$")y ax2 = plt.subplot(gs1[5:,0]) ######################## # Do the actual plotting ####################### ax2.plot(data[:,mode], linestyle='-',marker = ".", mfc='none', markersize=5) ax2.set_xlabel("$i$") ax2.set_ylabel("$a^\epsilon_{"+str(mode+1)+"}(t_i)$") ax2.yaxis.tick_right() ax2.set_ylim([amin,amax]) # Add the colorbar outside... pad, width = 0.02, 0.02 fig.subplots_adjust(bottom=0.2,top=0.9) cax = plt.subplot(gs1[:5,1]) box = ax1.get_position() fig.colorbar(hplot, cax=cax) cax.set_position([cax.get_position().xmin, box.ymin, width , box.height]) cax.axis('tight') #cb.set_label("vorticity [1/s]") print("Saving plot to: "+pic_dir+plt_file) plt.savefig( pic_dir+plt_file, dpi=600, transparent=True, bbox_inches='tight' ) plt.show()
case = "CDF44_dealias_pacman" #case = "CDF44_pacman" ini = "pacman.ini" eps_dir = "./adaptive_" + case + "_Bs17_Jmax7*eps1.0e-04_iter1/" norm = 2 # %% files = glob.glob(eps_dir + '/' + quantity + '*.h5') files.sort() for file in files: plt_file = file.replace('h5', 'png') if (os.path.isfile(plt_file)): continue fig, ax = plt.subplots() ax,cb,hplot = wt.plot_wabbit_file(file,cmap ='bwr', dpi=300, \ shading='gouraud', caxis=[0,1],block_edge_color='w', \ block_edge_alpha=0.7, block_linewidth=0.9 ,colorbar_orientation="vertical", \ title=False, ticks=False, colorbar=True) #ax.set_title("$\epsilon="+str(eps_list[i])+"$") # ax.set_xlabel("$x$") #ax.set_ylabel("$y$") ax.set_aspect('equal') #cb.set_label("vorticity [1/s]") print("Saving plot to: " + plt_file) plt.savefig(plt_file, dpi=300, transparent=True, bbox_inches='tight') plt.show() #tikzplotlib.clean_figure() #tikzplotlib.save(plt_file) ############################################################################## # %% eps vs err
files.sort() if cmap is 'jet': fc = 'jet' else: fc = farge_colormaps.farge_colormap_multi(taille=600, limite_faible_fort=0.2, etalement_du_zero=0.04, type=cmap) for file, i in zip(files[1:], range(len(files[1:]))): wabbit_tools.plot_wabbit_file(file, savepng=True, cmap=fc, ticks=False, colorbar=True, dpi=300, title=True, block_edge_color='w', caxis_symmetric=True, shading='gouraud') #%% flusi cylinder #for prefix, cmap in zip(['vorx','p','uy','uz','mask'],['vorticity','pressure','velocity','velocity','streamfunction']): # fname = '/home/engels/dev/FLUSI/cyl/'+prefix+'_001500.h5' # # plt.gcf().clf() # # # read data # time, box, origin, data = insect_tools.read_flusi_HDF5(fname) # # # colormap
def plot_vector_modes(files,acoef_file,quantity,quantity_replace,pic_dir="./",fc=fc_default, mode_names=None): f = open(acoef_file) data = [[float(num) for num in line.split()] for line in f] f.close data = np.asarray(data) amin = np.amin(data) amax = np.amax(data) print("min(a_coef):", amin) print("max(a_coef):", amax) Ncomponents=len(files) Nmodes = len(files[0]) mode_ax=[] for n_mode in range(Nmodes): fig = plt.figure(n_mode) fig.subplots_adjust(wspace=0.05,hspace=0.05) for k in range(Ncomponents): file = files[k][n_mode] plt_file = file.split("/")[-1] plt_file = plt_file.replace(quantity+"_",quantity_replace+"_") plt_file = plt_file.replace('h5','png') gs1 = gs.GridSpec(nrows=Ncomponents+1,ncols=1) ax1 = plt.subplot(gs1[k,0]) ax,cb,hplot = wt.plot_wabbit_file(file,cmap=fc,caxis_symmetric=True,dpi=600, \ shading='flat', block_linewidth=0.25, \ block_edge_alpha=0.4, block_edge_color='k', \ title=False, ticks=False, colorbar=False, fig=fig, ax=ax1) if k==0: ax.set_title("$\Psi_{"+str(n_mode+1)+"}^\epsilon(x,y)$") if mode_names is not None: ax1.set_ylabel(mode_names[k]) # ax.set_xlabel("$x$") #ax.set_ylabel("$y$")y mode_ax.append(ax1) axins1 = inset_axes(ax1, width="2%", # width = 50% of parent_bbox width height="80%", # height : 5% loc='right', bbox_to_anchor=(0.03, 0., 1, 1), bbox_transform=ax1.transAxes, borderpad=0) fig.colorbar(hplot, cax=axins1, orientation="vertical") # for k,ax1 in enumerate(mode_ax): # pad, width = 0.02, 0.02 # fig.subplots_adjust(bottom=0.2,top=0.9) # fig.canvas.draw() # cax = plt.subplot(gs1[np.mod(k,1),1]) # box = ax1.get_position() # cax.set_position([cax.get_position().xmin, box.ymin, 0.01 , box.height]) # cax.axis('tight') # fig.colorbar(hplot, cax=cax) ax2 = plt.subplot(gs1[Ncomponents,0]) ######################## # Do the actual plotting ####################### ax2.plot(data[:,n_mode], linestyle='-',marker = ".", mfc='none', markersize=5) ax2.set_xlabel("$i$") ax2.set_ylabel("$a^\epsilon_{"+str(n_mode+1)+"}(t_i)$") ax2.yaxis.tick_right() ylim=1.2*np.max(np.abs(ax2.get_ylim())) ax2.set_ylim([-ylim,ylim]) # Add the colorbar outside... #cb.set_label("vorticity [1/s]") print("Saving plot to: "+pic_dir+plt_file) plt.savefig( pic_dir+plt_file, dpi=600, transparent=True, bbox_inches='tight' ) plt.show()
############################################################################### # %% get the data quantity = "vorx-sparse" plt.close("all") for i, eps_dir in enumerate(eps_dir_list[::5]): files = glob.glob(eps_dir + '/' + quantity + '_*.h5') files.sort() for file in files: plt_file = file.split("/")[-1] plt_file = plt_file.replace(quantity + "_", quantity + "-" + eps_dir_list[i] + "_") plt_file = plt_file.replace('h5', 'png') fig, ax = plt.subplots() ax,cb = wt.plot_wabbit_file(file,cmap=fc,caxis_symmetric=True,dpi=300, \ shading='gouraud',caxis=[-10,10], \ block_edge_alpha=0.2,colorbar_orientation="horizontal", \ title=False, ticks=False, colorbar=True) ax.set_title("$\epsilon=" + str(eps_list[i]) + "$") # ax.set_xlabel("$x$") #ax.set_ylabel("$y$") ax.set_aspect('equal') #cb.set_label("vorticity [1/s]") print("Saving plot to: " + pic_dir + plt_file) plt.savefig(pic_dir + plt_file, dpi=300, transparent=True, bbox_inches='tight') plt.show() exit
def wabbit_adapt(dirs, params, wabbit_setup): mpicommand = wabbit_setup["mpicommand"] memory = wabbit_setup["memory"] wdir = dirs["wabbit"] work = dirs["work"] jmax_list = params.jmax_list # set initial gird dim = len(params.domain.L) x = [np.linspace(0,params.domain.L[d],params.domain.N[d]) \ for d in range(dim) ] X = np.meshgrid(*x) phi = params.init(X, params.domain.L) Bs = wt.field_shape_to_bs(params.domain.N, jmax_list[-1]) # create reference file file_ref = wt.dense_to_wabbit_hdf5(phi, work + "/phi", Bs, params.domain.L, 0) params.Bs_list = [] l2error = np.zeros([len(params.jmax_list), len(params.eps_list)]) linferror = np.zeros_like(l2error) compress = np.zeros_like(l2error) for j, jmax in enumerate(params.jmax_list): Bs = wt.field_shape_to_bs(params.domain.N, jmax) params.Bs_list.append(Bs) # adapt field for different eps using wabbit-post -dense-to-sparse print( "\n\n###################################################################" ) print( "###################################################################" ) print("\t\tJmax: ", jmax, "\n\n") for k, eps in enumerate(params.eps_list): # create dense field and save to work fname = "phi-j" + str(jmax) + "-eps" file = work + "/" + fname file = wt.dense_to_wabbit_hdf5(phi, file, Bs, params.domain.L, eps * 100) command = mpicommand + " " + wdir + \ "wabbit-post --dense-to-sparse --eps=" + str(eps) + " --order=CDF44 --eps-norm=Linfty " + memory + \ " --files="+ file + ">adapt.log" # command for densing file again dense_command = mpicommand + " " + wdir + \ "wabbit-post --sparse-to-dense " + \ " "+ file + " "+file + ">>adapt.log" # ----------------------------- # Execute Command # ----------------------------- print( "\n\n###################################################################" ) print("\t\teps =", eps) print( "###################################################################" ) print("\n", command, "\n\n") success = os.system(command) # execute command if np.mod(k, 4) == 0: wt.plot_wabbit_file(file, savepng=True) compress[j, k] = sum(wt.block_level_distribution_file(file)) print("\n", dense_command, "\n\n") success += os.system( dense_command) # dense the file for comparison to original if success != 0: print("command did not execute successfully") return # --------------------------- # compare to original file # -------------------------- l2error[j, k] = wt.wabbit_error_vs_wabbit(file_ref, file, norm=2, dim=2) linferror[j, k] = wt.wabbit_error_vs_wabbit(file_ref, file, norm=np.inf, dim=2) compress[j, k] /= sum(wt.block_level_distribution_file(file)) # delete file os.system("rm " + file) # delete reference file os.system("rm " + file_ref) return l2error, linferror, compress