def main(File, Directory): # If a convergence file given: # plot it # If a directory given: # plot each convergence file in each subdirectory # # check to see if a convergence file exists in the directory given, if there is... use it as a constant line. if Directory: # if a directory is given... directory = ut.format_Directory_Path(Directory) os.chdir(directory) # the last directory name is the case name. fileName = directory.split("/") fileName = fileName[-2] # Read convergence files in this directory and all sub directories... all_convergence_data = {} for root, sub_dirs, files in os.walk(directory): for file in files: if file.endswith("convergence.asc"): print(os.path.join(root, file)) # read in convergence file # initialise convergence dictionary all_convergence_data[fileName] = {} # populate the dictionary all_convergence_data[fileName] = ut.read_Convergence_NKH(file) print("") for sub_dir in sub_dirs: sub_fileName = sub_dir sub_dir = os.path.join(root, sub_dir) os.chdir(sub_dir) for file in os.listdir(sub_dir): if file.endswith("convergence.asc"): print(os.path.join(sub_dir, file)) # read in convergence file # initialise convergence dictionary all_convergence_data[sub_fileName] = {} # populate the dictionary all_convergence_data[sub_fileName] = ut.read_Convergence_NKH(file) break os.chdir(directory) ut.plot_Convergence_NKH_multi(all_convergence_data, "Newton_Steps", "L2Norm(u)") ut.plot_Convergence_NKH_multi(all_convergence_data, "ftotal", "L2Norm(u)") ut.plot_Convergence_NKH_multi(all_convergence_data, "fnewt", "L2Norm(u)") ut.plot_Convergence_NKH_multi(all_convergence_data, "fhook", "L2Norm(u)") ut.plot_Convergence_NKH_multi(all_convergence_data, "Newton_Steps", "L2Norm(G)") ut.plot_Convergence_NKH_multi(all_convergence_data, "ftotal", "L2Norm(G)") ut.plot_Convergence_NKH_multi(all_convergence_data, "fnewt", "L2Norm(G)") ut.plot_Convergence_NKH_multi(all_convergence_data, "fhook", "L2Norm(G)") ut.plot_Convergence_NKH_multi(all_convergence_data, "Newton_Steps", "L2Norm(du)") ut.plot_Convergence_NKH_multi(all_convergence_data, "ftotal", "L2Norm(du)") ut.plot_Convergence_NKH_multi(all_convergence_data, "fnewt", "L2Norm(du)") ut.plot_Convergence_NKH_multi(all_convergence_data, "fhook", "L2Norm(du)") ut.plot_Convergence_NKH_multi(all_convergence_data, "Newton_Steps", "GMRESerr")
action='store_true') parser.add_argument("-a", "--SpatiallyAveraged", help="Spatially averaged?.", action='store_true') parser.add_argument("-q", "--Quiver", help="Plot vector arrows as well?", action='store_true') parser.add_argument("-l", "--Levels", help="How many levels the colorbar should have? (Default = 20)", metavar='\b', type=int) parser.add_argument("-s", "--Small", help="Small figures?", action='store_true') parser.add_argument("-t", "--Type", help="File type?", metavar='\b', type=str) args = parser.parse_args() #===================================================================# #### Format current directory path #### #===================================================================# pwd = ut.format_Directory_Path(os.getcwd()) #===================================================================# #### Read file and details file #### #===================================================================# file_info, original_attrs = ut.read_H5(args.File) details = ut.read_Details(args.Details) #===================================================================# #### Make output directory for images and change into it #### #===================================================================# images_directory = ut.make_Folder(pwd, "images_" + str(args.File)[:-3], False) os.chdir(images_directory) #===================================================================# #### Initialise flow field class with given file #### #===================================================================# ff = ffClass.FlowFieldChannelFlow( file_info['Nd'], file_info['Nx'],
#!/usr/bin/env python3 import argparse import os import sys sys.path.append("/".join(sys.path[0].split("/")[:-1])) import Utils as ut parser = argparse.ArgumentParser(description="Run nkh searches") parser.add_argument("-f", "--File", metavar="\b", help="File to approximate", required=True) parser.add_argument("-dir", "--Directory", metavar="\b", help="Directory to perform searches in.", required=True) parser.add_argument("-d", "--Details", metavar="\b", help="Details file.", required=True) args = parser.parse_args() name = str(args.File) directory = ut.format_Directory_Path(args.Directory) directory += name directory = ut.format_Directory_Path(directory) os.chdir(directory) print(directory) #### Plot flow field plot = "e_Plot_Field.py -f " + name + ".h5 -d " + args.Details + " -i 0 -n 0 -a -l 16" print(plot) os.system(plot) plot = "e_Plot_Field.py -f " + name + ".h5 -d " + args.Details + " -i 0 -n 0 -f -l 16" print(plot) os.system(plot) #### ---NKH Search nkh = "findsoln -eqb -sn -log nkh-" + name + ".log " + name + ".h5" print(nkh) os.system(nkh)
def main(File, s, a, contourPlot): print(File) #===================================================================# #### Format current directory path #### #===================================================================# pwd = ut.format_Directory_Path(os.getcwd()) #===================================================================# #### Read deconstructed field #### #===================================================================# deconstructed_field = ut.read_H5_Deconstructed(File) #===================================================================# #### Chck what we are working with? #### #===================================================================# #### Singular values if s: print("Printing singular values") # Extract the norm singular values... sing_vals = np.zeros((len(deconstructed_field["Mx"]), len(deconstructed_field["Mz"])), dtype=float) Mx_shifted = [] if deconstructed_field["Nx"] % 2 == 0: # even Nx Mx_shifted = list(deconstructed_field["Mx"][deconstructed_field["Nx"]/2+1:]) Mx_shifted.extend(list(deconstructed_field["Mx"][:deconstructed_field["Nx"]/2+1])) else: # odd Nx Mx_shifted = list(deconstructed_field["Mx"][(deconstructed_field["Nx"]+1)/2:]) Mx_shifted.extend(list(deconstructed_field["Mx"][:(deconstructed_field["Nx"]-1)/2+1])) Mz_shifted = [] if deconstructed_field["Nz"] % 2 == 0: # even Nz Mz_shifted = list(deconstructed_field["Mz"][deconstructed_field["Nz"]/2+1:]) Mz_shifted.extend(list(deconstructed_field["Mz"][:deconstructed_field["Nz"]/2+1])) else: # odd Nz Mz_shifted = list(deconstructed_field["Mz"][(deconstructed_field["Nz"]+1)/2:]) Mz_shifted.extend(list(deconstructed_field["Mz"][:(deconstructed_field["Nz"]-1)/2+1])) Mx_shifted = np.array(Mx_shifted).astype(int) Mz_shifted = np.array(Mz_shifted).astype(int) for mx in range(0,len(Mx_shifted)): for mz in range(0,len(Mz_shifted)): oldIndex_mx = Mx_shifted[mx] oldIndex_mz = Mz_shifted[mz] # 2-norm to get magnitude of singular values sing_vals[mx,mz] = np.linalg.norm(deconstructed_field['singular_values'][oldIndex_mx,oldIndex_mz,:], 2) if oldIndex_mx == 0 and oldIndex_mz == 0: sing_vals[mx,mz] = 1e-17 # sing_vals is a 2D matrix of data # plot a contour now fileName = str(File[:-3]) + "_singular_values_2Norm" max_val = sing_vals.max() min_val = sing_vals.min() colorbar_label = "$|| \sigma ||$" levels = 16 title = "$|| \sigma ||$ at each Fourier mode" ut.plot_Contour_coeffs(pwd, fileName, Mx_shifted, Mz_shifted, sing_vals, "Mx", "Mz", colorbar_label, max_val, min_val, levels, title, contourPlot) #### Amplitude coefficients if a: print("Printing amplitude coefficients values") # Extract the norm singular values... amp_coefs = np.zeros((len(deconstructed_field["Mx"]), len(deconstructed_field["Mz"])), dtype=float) Mx_shifted = [] if deconstructed_field["Nx"] % 2 == 0: # even Nx Mx_shifted = list(deconstructed_field["Mx"][deconstructed_field["Nx"]/2+1:]) Mx_shifted.extend(list(deconstructed_field["Mx"][:deconstructed_field["Nx"]/2+1])) else: # odd Nx Mx_shifted = list(deconstructed_field["Mx"][(deconstructed_field["Nx"]+1)/2:]) Mx_shifted.extend(list(deconstructed_field["Mx"][:(deconstructed_field["Nx"]-1)/2+1])) Mz_shifted = [] if deconstructed_field["Nz"] % 2 == 0: # even Nz Mz_shifted = list(deconstructed_field["Mz"][deconstructed_field["Nz"]/2+1:]) Mz_shifted.extend(list(deconstructed_field["Mz"][:deconstructed_field["Nz"]/2+1])) else: # odd Nz Mz_shifted = list(deconstructed_field["Mz"][(deconstructed_field["Nz"]+1)/2:]) Mz_shifted.extend(list(deconstructed_field["Mz"][:(deconstructed_field["Nz"]-1)/2+1])) Mx_shifted = np.array(Mx_shifted).astype(int) Mz_shifted = np.array(Mz_shifted).astype(int) for mx in range(0,len(Mx_shifted)): for mz in range(0,len(Mz_shifted)): oldIndex_mx = Mx_shifted[mx] oldIndex_mz = Mz_shifted[mz] # 2-norm to get magnitude of amplitude coefficients amp_coefs[mx,mz] = np.linalg.norm(deconstructed_field['coefficients'][oldIndex_mx,oldIndex_mz,:], 2) if oldIndex_mx == 0 and oldIndex_mz == 0: amp_coefs[mx,mz] = 1e-17 # sing_vals is a 2D matrix of data # plot a contour now fileName = str(File[:-3]) + "_amplitude_coeffs_2Norm" max_val = amp_coefs.max() min_val = amp_coefs.min() colorbar_label = "$|| \Xi ||$" levels = 16 title = "$|| \Xi ||$ at each Fourier mode" ut.plot_Contour_coeffs(pwd, fileName, Mx_shifted, Mz_shifted, amp_coefs, "Mx", "Mz", colorbar_label, max_val, min_val, levels, title, contourPlot) #### Combined if a and s: print("Printing multiple of above values") # Extract the norm singular values... chi = np.zeros((len(deconstructed_field["Mx"]), len(deconstructed_field["Mz"])), dtype=float) Mx_shifted = [] if deconstructed_field["Nx"] % 2 == 0: # even Nx Mx_shifted = list(deconstructed_field["Mx"][deconstructed_field["Nx"]/2+1:]) Mx_shifted.extend(list(deconstructed_field["Mx"][:deconstructed_field["Nx"]/2+1])) else: # odd Nx Mx_shifted = list(deconstructed_field["Mx"][(deconstructed_field["Nx"]+1)/2:]) Mx_shifted.extend(list(deconstructed_field["Mx"][:(deconstructed_field["Nx"]-1)/2+1])) Mz_shifted = [] if deconstructed_field["Nz"] % 2 == 0: # even Nz Mz_shifted = list(deconstructed_field["Mz"][deconstructed_field["Nz"]/2+1:]) Mz_shifted.extend(list(deconstructed_field["Mz"][:deconstructed_field["Nz"]/2+1])) else: # odd Nz Mz_shifted = list(deconstructed_field["Mz"][(deconstructed_field["Nz"]+1)/2:]) Mz_shifted.extend(list(deconstructed_field["Mz"][:(deconstructed_field["Nz"]-1)/2+1])) Mx_shifted = np.array(Mx_shifted).astype(int) Mz_shifted = np.array(Mz_shifted).astype(int) for mx in range(0,len(Mx_shifted)): for mz in range(0,len(Mz_shifted)): oldIndex_mx = Mx_shifted[mx] oldIndex_mz = Mz_shifted[mz] # 2-norm to get magnitude of singular values s_val = np.asmatrix(deconstructed_field['singular_values'][oldIndex_mx,oldIndex_mz,:]) a_val = np.asmatrix(deconstructed_field['coefficients'][oldIndex_mx,oldIndex_mz,:]).T tmp = s_val * a_val chi[mx,mz] = np.linalg.norm(tmp, 2) if oldIndex_mx == 0 and oldIndex_mz == 0: chi[mx,mz] = 1e-10 # sing_vals is a 2D matrix of data # plot a contour now fileName = str(File[:-3]) + "_chi_2Norm" max_val = chi.max() min_val = chi.min() colorbar_label = "$|| \chi ||$" levels = 16 title = "$|| \chi ||$ at each Fourier mode" ut.plot_Contour_coeffs(pwd, fileName, Mx_shifted, Mz_shifted, chi, "Mx", "Mz", colorbar_label, max_val, min_val, levels, title, contourPlot) print("Finished")
parser.add_argument("-th_steps", "--Theta_steps", help="Number of cases to generate. (If 1 sample to generate, the maximum theta will be used for scaling.)\n(theta_max, theta_min, theta_steps)", metavar='\b', required=True, type=int) parser.add_argument("-T0", "--T0", help="DNS starting time unit.", metavar='\b', required=True, type=float) parser.add_argument("-T1", "--T1", help="DNS ending time unit.", metavar='\b', required=True, type=float) args = parser.parse_args() date = time.strftime("%Y_%m_%d") #================================================================ #### Format output directory correctly. #================================================================ output_directory = ut.format_Directory_Path(args.Directory) print('\nThe process will be carried out in:') print(output_directory, '\n') #================================================================ #### Define theta array #================================================================ powers = np.linspace(args.Theta_max, args.Theta_min, args.Theta_steps) #================================================================ #### Initialise initial velocity fields in their respective directories #================================================================ directories = [] for i in range(0, args.theta_steps): command = "eMakeFlowField.py" command += " -wp " + str(args.Wavepacket) command += " -nd " + str(args.Nd) command += " -nx " + str(args.Nx)
required=True) parser.add_argument("-v", "--MeanProfile", metavar='\b', help="Turbulent mean velocity profile as .txt file. Keep in same directory as file to approximate.") parser.add_argument("-s", "--Sparse", help="Use sparse SVD algorithm.", action='store_true') args = parser.parse_args() #================================================================ #### Create a temporary folder #================================================================ parent_directory = ut.format_Directory_Path(os.getcwd()) temp_rank_folder = ut.make_Temporary_Folder(parent_directory, "rank", True) # All work is done from the temporary directory. os.chdir(temp_rank_folder) #================================================================ #### Check file type #================================================================ if args.File[-3:] == ".h5": print("HDF5 file given.") #------------------------------------------------ #### Read the HDF5 and details file files_info = ut.read_H5(parent_directory, args.File) details = ut.read_Details(parent_directory, "u0_Details.txt")
def main(File, Details, VelComponent, SpatialComponent, Coordinate, Full, SpatiallyAveraged, Quiver, Levels): #===================================================================# #### Format current directory path #### #===================================================================# pwd = ut.format_Directory_Path(os.getcwd()) #===================================================================# #### Read file and details file #### #===================================================================# file_info, original_attrs = ut.read_H5(File) details = ut.read_Details(Details) #===================================================================# #### Make output directory for images and change into it #### #===================================================================# images_directory = ut.make_Folder(pwd, "images_" + str(File)[:-3], False) os.chdir(images_directory) #===================================================================# #### Initialise flow field class with given file #### #===================================================================# ff = ffClass.FlowFieldChannelFlow( file_info['Nd'], file_info['Nx'], file_info['Ny'], file_info['Nz'], file_info['Lx'], file_info['Lz'], file_info['alpha'], file_info['beta'], details['c'], details['bf'], details['Re'], file_info['ff'], "pp") #===================================================================# #### Set velocity and spatial components #### #===================================================================# i = VelComponent n = SpatialComponent m=n+1; p=n-1 if m==3: m=0 if p==-1: p=2 velName = "" if i==0: velName = "u" elif i==1: velName = "v" elif i==2: velName = "w" #===================================================================# #### Start plotting #### #===================================================================# print("Plotting...") vl_max = np.amax(ff.velocityField[i, :, :, :]) vl_min = np.amin(ff.velocityField[i, :, :, :]) printFullTitle = True if Levels: contour_levels = Levels else: contour_levels = 20 #===================================================================# #### If Full selected #### #===================================================================# if Full: if n == 0: x_directory = ut.make_Folder(images_directory, "x", False) for j in range(0, ff.Nx): ut.plot_Contour(x_directory, str(File[:-3]), ff.z, ff.y, ff.velocityField[i, j, :, :], format(ff.x[j], '.2f'), ":", ":", ff.Re, str(j), "-", "-", ff.velocityField[m, j, :, :], ff.velocityField[p, j, :, :], "z", "y", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) elif n == 1: y_directory = ut.make_Folder(images_directory, "y", False) for j in range(0, ff.Ny): ut.plot_Contour(y_directory, str(File[:-3]), ff.z, ff.x, ff.velocityField[i, :, j, :], ":", format(ff.y[j], '.2f'), ":", ff.Re, "-", str(j), "-", ff.velocityField[m, :, j, :], ff.velocityField[p, :, j, :], "z", "x", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) elif n == 2: z_directory = ut.make_Folder(images_directory, "z", False) for j in range(0, ff.Nz): ut.plot_Contour(z_directory, str(File[:-3]), ff.x, ff.y, ff.velocityField[i, :, :, j].T, ":", ":", format(ff.z[j], '.2f'), ff.Re, "-", "-", str(j), ff.velocityField[m, :, :, j].T, ff.velocityField[p, :, :, j].T, "x", "y", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) #===================================================================# #### If Co-Ordinate given #### #===================================================================# printFullTitle = True if Coordinate: if n == 0: coords = Tests.indices(ff.x, lambda m: m > float(Coordinate)) x_coord = coords[0] x_directory = ut.make_Folder(images_directory, "x", False) ut.plot_Contour(x_directory, str(File[:-3]), ff.z, ff.y, ff.velocityField[i, x_coord, :, :], format(ff.x[x_coord], '.2f'), ":", ":", ff.Re, str(x_coord), "-", "-", ff.velocityField[m, x_coord, :, :], ff.velocityField[p, x_coord, :, :], "z", "y", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) elif n == 1: coords = Tests.indices(ff.y, lambda m: m > float(Coordinate)) y_coord = coords[-1] y_directory = ut.make_Folder(images_directory, "y", False) ut.plot_Contour(y_directory, str(File[:-3]), ff.z, ff.x, ff.velocityField[i, :, y_coord, :], ":", format(ff.y[y_coord], '.2f'), ":", ff.Re, "-", str(y_coord), "-", ff.velocityField[m, :, y_coord, :], ff.velocityField[p, :, y_coord, :], "z", "x", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) elif n == 2: coords = Tests.indices(ff.z, lambda m: m > float(Coordinate)) z_coord = coords[0] z_directory = ut.make_Folder(images_directory, "z", False) ut.plot_Contour(z_directory, str(File[:-3]), ff.x, ff.y, ff.velocityField[i, :, :, z_coord].T, ":", ":", format(ff.z[z_coord], '.2f'), ff.Re, "-", "-", str(z_coord), ff.velocityField[m, :, :, z_coord].T, ff.velocityField[p, :, :, z_coord].T, "x", "y", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) #===================================================================# #### If Spatially averaging selected #### #===================================================================# printFullTitle = False if SpatiallyAveraged: if n == 0: # Average the flow field in teh streamwise direction. x_averaged_ff = np.zeros((ff.Nd, ff.Ny, ff.Nz)) for nd in range(0, ff.Nd): for nx in range(0, ff.Nx): x_averaged_ff[nd, :, :] += ff.velocityField[nd, nx, :, :] x_averaged_ff *= (1.0 / ff.Nx) vl_max = np.amax(x_averaged_ff[i, :, :]) vl_min = np.amin(x_averaged_ff[i, :, :]) fileName = str(File)[:-3] + "_x_avgd_" ut.plot_Contour(images_directory, fileName, ff.z, ff.y, x_averaged_ff[i, :, :], "avg", ":", ":", ff.Re, "x-avg", "-", "-", x_averaged_ff[m, :, :], x_averaged_ff[p, :, :], "z", "y", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) elif n == 1: # Average the flow field in teh streamwise direction. y_averaged_ff = np.zeros((ff.Nd, ff.Nx, ff.Nz)) for nd in range(0, ff.Nd): for ny in range(0, ff.Ny): y_averaged_ff[nd, :, :] += ff.velocityField[nd, :, ny, :] y_averaged_ff *= (1.0 / ff.Ny) vl_max = np.amax(y_averaged_ff[i, :, :]) vl_min = np.amin(y_averaged_ff[i, :, :]) fileName = str(File)[:-3] + "_y_avgd_" ut.plot_Contour(images_directory, fileName, ff.z, ff.x, y_averaged_ff[i, :, :], ":", "avg", ":", ff.Re, "-", "y-avg", "-", y_averaged_ff[m, :, :], y_averaged_ff[p, :, :], "z", "x", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) elif n == 2: # Average the flow field in teh streamwise direction. z_averaged_ff = np.zeros((ff.Nd, ff.Nx, ff.Ny)) for nd in range(0, ff.Nd): for nz in range(0, ff.Nz): z_averaged_ff[nd, :, :] += ff.velocityField[nd, :, :, nz] z_averaged_ff *= (1.0 / ff.Nz) vl_max = np.amax(z_averaged_ff[i, :, :]) vl_min = np.amin(z_averaged_ff[i, :, :]) fileName = str(File)[:-3] + "_z_avgd_" ut.plot_Contour(images_directory, fileName, ff.x, ff.y, z_averaged_ff[i, :, :].T, ":", ":", "avg", ff.Re, "-", "-", "z-avg", z_averaged_ff[m, :, :].T, z_averaged_ff[p, :, :].T, "x", "y", velName, vl_max, vl_min, Quiver, contour_levels, printFullTitle) ut.print_EndMessage()
#!/usr/bin/env python3 import numpy as np import os import Utils as ut output_directory = os.getcwd() output_directory = ut.format_Directory_Path(output_directory) # Make a directory to store the files with integer names. ints_directory = output_directory + 'ints' # if directory exists, delete it: if os.path.exists(ints_directory): print("\nRemoving:\t" + str(ints_directory)) command = "rm -rf " + ints_directory os.system(command) # if directory doesn't exist, make it: if not os.path.exists(ints_directory): print("Making:\t\t" + str(ints_directory)) os.mkdir(ints_directory) ints_directory = output_directory + 'ints' T0 = 0 T1 = 1400 steps = T1 - T0 + 1 TRange = np.linspace(T0, T1, steps) #### Change directory down # change into the ints folder and list files and rename the float files to integer files. os.chdir(ints_directory) files = [fi for fi in os.listdir(output_directory) if os.path.isfile(os.path.join(output_directory,fi))] files = sorted(files) for k in files: if str(k)[0] == 'u' and str(k).find("asc") == -1: oldFile = k