def main(): ## parameters dir_in = '/usr/local/home/yl8bc/duannas/' filename_in_grid = 'nozzle_grid_test.h5' filename_outlet = 'Test_Incompact3d/HLB_Nozzle/AcousticZgrid_k500.dat' ## output dir_out = '../../data/nozzle/' filename_out = 'nozzle_grid_test_try1' ## BELOW NO PARAMS ARE DEFINED tstart = time.time() ## Read grid(uniform) grid, vars_name = IO_util.read_hdf5(dir_out + filename_in_grid) u = grid['x'] v = grid['z'] dset, zones_name, vars_name = util_tp.read_tp(dir_in + filename_outlet) data_outlet, nodemap = util_tp.read_tp_zone(dset, 'SubZone', vars_name) ## intersections nx, ny = u.shape v[-1, :] = v[-1, -1] * normalized_flipped(data_outlet['z'], ny) u, v = gridgen.cm_gridgen.gridgen_checker(u, v) print 'Checker done. Elapsed time: %f' % (time.time() - tstart) ## Write grid grid['x'] = u grid['z'] = v IO_util.write_hdf5(dir_out + filename_out, grid)
def main(): ###---parameters----### shape = (500, 100) # Files required to start interpolation dir_in = '/usr/local/home/yl8bc/duannas/' filename_fluent = 'jhyt7/Acoustics/HLB/Interp_Fluent_DNS/nozzle2d_fluent.dat' filename_outlet = 'Test_Incompact3d/HLB_Nozzle/AcousticZgrid_k500.dat' # Files generated by the program dir_out = '../../data/nozzle/' filename_out = 'nozzle_grid_test' ###---no parameters below---# #----read fluent grid & data-----! dset, zones_name, vars_name = util_tp.read_tp(dir_in + filename_fluent) data_wall, nodemap = util_tp.read_tp_zone(dset, 'nozzlewall', vars_name) ## define boundary x0 = data_wall['X'][0] xm = data_wall['X'][-1] y0 = data_wall['Y'][0] ym = data_wall['Y'][-1] choice_left = np.stack( [np.ones((2**16, )) * x0, np.linspace(0., y0, 2**16)], axis=1) # y0*normalized_flipped(grid_outlet['SubZone']['z'], ny)], axis=1) choice_right = np.stack( [np.ones((2**16, )) * xm, np.linspace(0., ym, 2**16)], axis=1) # ym*normalized_flipped(grid_outlet['SubZone']['z'], ny)], axis=1) choice_bottom = np.stack([np.linspace(x0, xm, 2**16), np.zeros((2**16, ))], axis=1) choice_top = np.stack([data_wall['X'], data_wall['Y']], axis=1) choice_top = gridgen.cm_gridgen.refine_boundary( choice_top, 2**16 / choice_top.shape[0]) ## compute u, v = util_grid.gridgen_orth(shape, choice_left, choice_right, choice_bottom, choice_top, dir_out + filename_out, varname=['x', 'z'], tol_in=1.e-8, tol_bdry=0, nsave=64, fixed_boundary=[0, 0, 0, 0])
def main(): ###params### mrange = range(1, 99, 1) mmax = len(mrange) nmax = 90 dir_in = '/usr/local/home/yl8bc/duannas/jhyt7/Acoustics/HIFiRE_Cone/FluentData/' #'/usr/local/home/yl8bc/duannas/jhyt7/Acoustics/HLB/Interp_Fluent_DNS/' filename_in_data = 'CircularCone2D.dat' # 'nozzle2d_fluent.dat' filename_in_case = 'CircularCone2D.cas' # 'nozzle2d_fluent.dat' ## names of the zones below interior = 'unspecified' wall_right = 'wall' ## files output: dir_out = '/usr/local/home/yl8bc/yl8bc/data/cone/FLUENT/' filename_out_data = 'data_fluent' filename_out_profiles = 'profiles_fluent' filename_out_integrals = 'integrals_fluent' ##--below no param is defined--## tstart = time.time() keys_change = { 'X': 'x', 'Y': 'z', 'X Velocity': 'u', 'Y Velocity': 'w', 'Pressure': 'p', 'Density': 'rho', 'Temperature': 'T' } grid_keys = ['x', 'z'] ## read grid and data data = util_tp.read_tp(dir_in + filename_in_data, file_type='fluent', case_filenames=dir_in + filename_in_case) print('Data read. Time elapsed: %f secs' % (time.time() - tstart)) ## recover structured print('Rebuilding...') data_int = util_data.change_dict(data[interior], keys_change) data_int = util_data.recover_structured_data(data_int, grid_keys=grid_keys) #data_int = recovery.recover_interior(data_int, grid_keys) R = util_flow.get_R(data_int['p'], data_int['rho'], data_int['T']) print(R) ## boundary data_right = util_data.change_dict(data[wall_right], keys_change) data_right = util_data.recover_structured_data(data_right, grid_keys=grid_keys, standard=False) data_right['rho'] = data_right['p'] / (R * data_right['T']) data = { name: np.concatenate((data_int[name], data_right[name][np.newaxis, :]), axis=0) for name in data_int.keys() } print('Rebuilt. Time elapsed: %f secs' % (time.time() - tstart)) ## wall normal profiles sdata = util_data.structured_data(data, grid_keys) profiles_out = sdata.get_wall_normal_profiles('right', mrange, nmax) ## integral delta = np.zeros(mmax) delta_star = np.zeros(mmax) theta = np.zeros(mmax) for n in range(mmax): wd = profiles_out['wd'][n, :] x = profiles_out['x'][n, :] z = profiles_out['z'][n, :] u = profiles_out['u'][n, :] w = profiles_out['w'][n, :] rho = profiles_out['rho'][n, :] up = util_flow.get_up_2d(u, w, x, z) delta[n] = util_flow.get_delta(wd, up) delta_star[n] = util_flow.get_delta_star(wd, up, rho) theta[n] = util_flow.get_theta(wd, up, rho) int_out = {} int_out['x'] = profiles_out['x'][:, 0] int_out['z'] = profiles_out['z'][:, 0] int_out['delta'] = delta int_out['delta*'] = delta_star int_out['theta'] = theta ## out IO_util.write_hdf5(dir_out + filename_out_data, data) IO_util.write_hdf5(dir_out + filename_out_profiles, profiles_out) IO_util.write_hdf5(dir_out + filename_out_integrals, int_out)
def main(): ''' This script converts unstructured cell-centered fluent data to structured data. Tecplot needs to be used to load fluent case and data files and write the data in Tecplot ASCII (*.dat) or binary format (*.plt,*szplt), which is used for variable "filename_in_data". run this script: python3 nozzle_fluent.py I've added one script that builds structured data from a Fluent/PLT file under /DNSMST_utility/src/pypost/grid_interpolation/nozzle_fluent.py. It has been tested to work with data located at duannas/duanl/Acoustics/TestFluentConversion which is a nozzle with wall on the top. If you're trying this on some other dataset, please pay attention to the following potential issues. Input data file_type. The data could be of PLT, SZPLT, DAT type, so please specify for the function read_tp() Data variable. Those variables could be named differently. By default the x-axis goes by the name 'X' and y-axis 'Y' and all other variables will be reconstructred to structured data according to these too coordinate variables. Wall direction. By default the wall is on the top. Broken connectivity. If the boundary points are not arranged in a ordered manner(eg. not following descending order with respect to 'X'), those points might need to be reordered. But this is not common anyway. The runtime for my test(around 200k datapoints) is ~20mins and the code is not optimized to its best state yet. ATTENTION!!! ------------------------------ POTENTIAL FAILURE: 1. Unmatached variable names. please go to line 37 keys_change and re-define! 2. Wrong direction. Please go to line to chooose one of those boundaries! 3. Input file format. Caution with tecplot files, for the format is unclear(ordered/unordered). -----------------------------------------------''' ###params### dir_in = './' filename_in_data = 'nozzle_cartesian_231x101_kwsst_refine1_2nd_UnstrTecplotCellCentered.plt' ## names of the zones below interior = 'unspecified' wall_top = 'wall' ## files output: dir_out = './' filename_out_data = 'nozzle_cartesian_460x200_kwsst_2nd_structured' ##--below no param is defined--## tstart = time.time() keys_change = {'X':'x', 'Y':'z', 'X Velocity':'u', 'Y Velocity':'w', 'Pressure':'p', 'Density':'rho', 'Temperature':'T'} grid_keys = ['x','z'] ## read grid and data data = util_tp.read_tp(dir_in+filename_in_data) print('Data read. Time elapsed: %f secs'%(time.time()-tstart)) ## recover structured print('Rebuilding...') data_int = util_data.change_dict(data[interior], keys_change) data_int = util_data.recover_structured_data(data_int, grid_keys=grid_keys) R = util_flow.get_R(data_int['p'], data_int['rho'], data_int['T']) print(R) ## boundary data_top = util_data.change_dict(data[wall_top], keys_change) data_top = util_data.recover_structured_data(data_top, grid_keys=grid_keys, standard=False) data_top['rho'] = data_top['p'] / (R*data_top['T']) data_top = sort_top(data_top, grid_keys[0]) ## one of these boundries below, need to choose!! ## top data = {name:np.concatenate((data_int[name], data_top[name][:,np.newaxis]), axis=1) for name in data_int.keys()} ## bot #data = {name:np.concatenate((data_top[name][:,np.newaxis], data_int[name]), axis=1) for name in data_int.keys()} ## right #data = {name:np.concatenate((data_int[name], data_top[name][np.newaxis,:]), axis=0) for name in data_int.keys()} ## left #data = {name:np.concatenate((data_top[name][np.newaxis,:], data_int[name]), axis=0) for name in data_int.keys()} print('Rebuilt. Time elapsed: %f secs'%(time.time()-tstart)) ## out # Put gridkeys in first two def sortkey(x): if x[0]==grid_keys[0]: return 0 elif x[0]==grid_keys[1]: return 1 else: return 2 data =OrderedDict( sorted(data.items(), key=sortkey)) print( data.keys()) IO_util.write_hdf5(dir_out+filename_out_data, data) util_tp.write_tp(dir_out+filename_out_data, data, old=True, order='F')
def main(): ''' Note: The boundary thickness calculation relies on a clear profile that converges. current code cannot intelligently tell which wall normal profile is "perfect". Thus boundary layer thickness might yield to poor quality if the profile is badly extracted. ''' ###params## mrange = range(100, 300, 100) ## along the wall at which index to extract nmax = 75 ## along wall normal direction how many nodes to extract fluid_type = 'nitrogen' dir_in = './' filename_in_data = 'structured_tec.plt' is_in_tecplot = True # Input is of tecplot format ??? False to be HDF5, True to be Tecplot format ## files output---------------------------------! dir_out = './' filename_out_profiles = 'profiles' filename_out_integrals = 'integrals' ## names of variables---------------------------! name_x = 'X' # name of these variables! name_z = 'Y' name_u = 'u' name_w = 'w' name_p = 'p' name_T = 'T' ## -------------------------------------- keys_change = {name_x: 'x', name_z: 'z'} grid_keys = ['x', 'z'] ## end params tstart = time.time() ## read grid and data if is_in_tecplot: data = util_tp.read_tp(dir_in + filename_in_data, order='F') data = next(iter(data.values())) else: data = IO_util.read_hdf5(dir_in + filename_in_data) print('Data read. Time elapsed: %f secs' % (time.time() - tstart)) ## slice data = util_data.change_dict(data, keys_change=keys_change) sdata = util_data.structured_data(data, grid_keys) ## wall normal profiles profiles_out = sdata.get_wall_normal_profiles('top', mrange, nmax) ## integral mmax = len(mrange) delta = np.zeros(mmax) delta_star = np.zeros(mmax) theta = np.zeros(mmax) tauw = np.zeros(mmax) utau = np.zeros(mmax) ztau = np.zeros(mmax) for n in range(mmax): wd = profiles_out['wd'][n, :] x = profiles_out['x'][n, :] z = profiles_out['z'][n, :] u = profiles_out[name_u][n, :] w = profiles_out[name_w][n, :] p = profiles_out[name_p][n, :] T = profiles_out[name_T][n, :] rho = util_flow.get_rho(profiles_out[name_p][n, :], profiles_out[name_T][n, :], fluid_type=fluid_type) up = util_flow.get_up_2d(u, w, x, z) delta[n] = util_flow.get_delta(wd, up) delta_star[n] = util_flow.get_delta_star(wd, up, rho) theta[n] = util_flow.get_theta(wd, up, rho) mu = util_flow.get_mu_Sutherland(T[0], fluid_type=fluid_type) tauw[n] = np.abs(mu * up[1] / wd[1]) utau[n] = np.sqrt(tauw[n] / rho[0]) ztau[n] = mu / rho[0] / utau[n] int_out = {} int_out['x'] = profiles_out['x'][:, 0] int_out['z'] = profiles_out['z'][:, 0] int_out['delta'] = delta int_out['delta*'] = delta_star int_out['theta'] = theta int_out['tauw'] = tauw int_out['utau'] = utau int_out['ztau'] = ztau ## out IO_util.write_hdf5(dir_out + filename_out_profiles, profiles_out) IO_util.write_hdf5(dir_out + filename_out_integrals, int_out) IO_util.write_ascii_point(dir_out + filename_out_profiles, profiles_out) IO_util.write_ascii_point(dir_out + filename_out_integrals, int_out)
filename = dir_in + filename_stat_h5[0] + n.__str__().zfill( 8) + filename_stat_h5[1] filename_list.append(filename) stat_in, varsname = read_hdf5_group_series(filename_list, 'Stat2d', ['pave', 'p2']) stat_bot, varsname = read_hdf5_group_series(filename_list, 'Int_BotWall', ['tauw', 'delta']) stat_top, varsname = read_hdf5_group_series(filename_list, 'Int_TopWall', ['tauw', 'delta']) tauw = 0.5 * (stat_bot['tauw'] + stat_top['tauw']) delta = 0.5 * (stat_bot['delta'] + stat_top['delta']) if in_plt: from util import util_tp dset, zones_name, vars_name = util_tp.read_tp(dir_in + filename_stat_plt) stat_in = util_tp.read_tp_zone(dset, zones_name[0], ['pave', 'p2', 'tauw', 'delta'], order='F') tauw = 0.5 * (stat_in['tauw'][:, 0] + stat_in['tauw'][:, -1]) delta = 0.5 * (stat_in['delta'][:, 0] + stat_in['delta'][:, -1]) ## calculation stat_out = {} stat_out['prms'] = np.sqrt(np.abs(stat_in['p2'] - stat_in['pave']**2)) prms_tauw_vs_x = stat_out['prms'][:, index_k_vs_x] / tauw # prms_tauw_vs_z = np.mean(stat_out['prms'][ibe:ien, :] / tauw[ibe:ien, np.newaxis], axis=0)