Esempio n. 1
0
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 read_hdf5_group_series(filename_list, gname, vars_name):
    data, names = IO_util.read_hdf5_group(filename_list[0], gname, vars_name)
    for filename in filename_list[1:]:
        data_tmp, names = IO_util.read_hdf5_group(filename, gname, vars_name)
        for name in names:
            data[name] += data_tmp[name]
    for name in names:
        data[name] *= 1. / len(filename_list)

    return data, names
Esempio n. 3
0
def main():
    ## params
    dims = (32, 100, 140)
    dir_out = '/usr/local/home/yl8bc/yl8bc/data/swept_wing/REST/'
    filename_out_grid = 'grid'
    ## end params

    ## define x and z
    xi = np.expand_dims(np.linspace(0., 1., dims[1]), 1)
    zeta = np.expand_dims(np.linspace(0., 10., dims[2]), 0)
    x = xi**2 + 0.5 * (1. - zeta)
    z = np.sqrt(2.) * xi * zeta

    ## out
    grid = {'x': x, 'z': z}
    IO_util.write_hdf5(dir_out + filename_out_grid, grid)
Esempio n. 4
0
def main():
    dir_in = '/usr/local/home/yl8bc/duannas/yl8bc/data/cone/run3_polar/REST/'
    filename_in_grid = 'grid.h5'
    stencilsize = 6
    bc = [0, 0, 1, 1, 0, 1]
    ## end params

    ## read grid
    grid_in = IO_util.read_hdf5(dir_in + filename_in_grid)
    x = grid_in['x']
    y = grid_in['y']
    z = grid_in['z']
    ny, nx, nz = x.shape

    ## extend grid
    x, y, z = util_f.mod_metrics.extend_grid(x, y, z, stencilsize)

    ## compute grid der
    grid_derivative = util_f.mod_metrics.compute_grid_derivative(
        x, y, z, ny, nx, nz, stencilsize, bc)
    grid_derivative = grid_derivative[:, (1, 0, 2), :, :, :]

    ## condition gridder
    grid_derivative[(0, 2), 1, :, :, :] = 0.
    grid_derivative[1, (0, 2), :, :, :] = 0.
    grid_derivative = np.repeat(
        grid_derivative[:, :,
                        stencilsize + ny / 2:stencilsize + ny / 2 + 1, :, :],
        grid_derivative.shape[2],
        axis=2)
    grid_derivative[:, 1, :2, :, :] = 0.
    grid_derivative[:, 1, -2:, :, :] = 0.

    ## out
    grid_out = {'dxdi':grid_derivative[0,0,:,:,:], \
                'dxdj':grid_derivative[0,1,:,:,:], \
                'dxdk':grid_derivative[0,2,:,:,:], \
                'dydi':grid_derivative[1,0,:,:,:], \
                'dydj':grid_derivative[1,1,:,:,:], \
                'dydk':grid_derivative[1,2,:,:,:], \
                'dzdi':grid_derivative[2,0,:,:,:], \
                'dzdj':grid_derivative[2,1,:,:,:], \
                'dzdk':grid_derivative[2,2,:,:,:]}
    IO_util.write_hdf5(dir_in + 'gridDerivative_f.h5', grid_out)
Esempio n. 5
0
def gridgen_orth(shape, choice_left, choice_right, choice_bottom, choice_top, \
                filename_out, varname=['x','z'], \
                tol_in=1.e-8, tol_bdry=0, nsave=64, fixed_boundary=[0,0,0,0], bend_boundary=[0,0,0,0]):
    u = np.zeros(shape)
    v = np.zeros(shape)
    
    ## init boundary
    idx_left, u[0,:],v[0,:] = util_f.cm_gridgen.init_index(choice_left, shape[1], 1)
    idx_right, u[-1,:],v[-1,:] = util_f.cm_gridgen.init_index(choice_right, shape[1], 1)
    idx_bottom, u[:,0],v[:,0] = util_f.cm_gridgen.init_index(choice_bottom, shape[0], 1)
    idx_top, u[:,-1],v[:,-1] = util_f.cm_gridgen.init_index(choice_top, shape[0], 1)
    
    ## init via tfi
    u,v = util_f.cm_gridgen.init_tfi(u, v)
    
    grid = {varname[0]:u, varname[1]:v}
    IO_util.write_hdf5(filename_out, grid)
    
    ## computation
    print('Gridgen orth starts computing...')
    iloop = True
    while iloop:
        u,v,idx_left,idx_right,idx_bottom,idx_top,iconverge = \
        util_f.cm_gridgen.compute_grid(u,v,idx_left,idx_right, \
                                            idx_bottom,idx_top, \
                                            choice_left,choice_right, \
                                            choice_bottom,choice_top, \
                                            tol_in, tol_bdry, nsave, \
                                            fixed_boundary,  \
                                            bend_boundary )
        ## out
        grid = {varname[0]:u, varname[1]:v}
        IO_util.write_hdf5(filename_out, grid)
 
        if iconverge==1:
            print('Converged!')
            iloop=False

    return u,v
Esempio n. 6
0
    #     choice_bottom = gridgen.cm_gridgen.refine_boundary(choice_bottom)
    #     choice_top = gridgen.cm_gridgen.refine_boundary(choice_top)
    # print choice_bottom.shape, choice_top.shape
    # print choice_top


    start_over = True
    if start_over:
        #IC
        idx_left, u[0,:],v[0,:] = gridgen.cm_gridgen.init_index(choice_left, shape[1], 1)
        idx_right, u[-1,:],v[-1,:] = gridgen.cm_gridgen.init_index(choice_right, shape[1], 1)
        idx_bottom, u[:,0],v[:,0] = gridgen.cm_gridgen.init_index(choice_bottom, shape[0], 1)
        idx_top, u[:,-1],v[:,-1] = gridgen.cm_gridgen.init_index(choice_top, shape[0], 1)
        u,v = gridgen.cm_gridgen.init_tfi(u, v)
        grid = {'x':u, 'y':v}
        IO_util.write_hdf5(dir_out+filename_output_hdf5, grid)
    else:
        idx_left = np.load('idx_left.npy')
        idx_right = np.load('idx_right.npy')
        idx_bottom = np.load('idx_bottom.npy')
        idx_top = np.load('idx_top.npy')
        grid, vars_name = IO_util.read_hdf5(dir_out+filename_output_hdf5+'.h5')
        u = grid['x']
        v = grid['y']

    iloop = True
    while iloop:

        u,v,idx_left,idx_right,idx_bottom,idx_top,iconverge = gridgen.cm_gridgen.compute_grid(u,v,idx_left,idx_right,
                                                                                              idx_bottom,idx_top,
                                                                                              choice_left,choice_right,
Esempio n. 7
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)
Esempio n. 8
0
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')
from scipy import interpolate

if __name__ == '__main__':
    ##---params --##
    shape = (2, 100, 140)
    dir_in_old = '/usr/local/home/yl8bc/duannas/yl8bc/data/cone/run6_release/REST/'#'./InitBody/'
    filename_grid_old = 'grid.h5'
    filename_data_old = 'flowdata_00200000.h5'
    dir_in_new = '/usr/local/home/yl8bc/duannas/yl8bc/data/cone/'
    filename_grid_new = 'cone_grid_flat_part2.h5'
    ## out
    dir_out = '/usr/local/home/yl8bc/duannas/yl8bc/data/cone/run7_2d/REST/'
    #filename_out =
    ##---params end----##
    ## read data/grid 
    grid_old = IO_util.read_hdf5(dir_in_old+filename_grid_old)
    data_old = IO_util.read_hdf5(dir_in_old+filename_data_old)
    grid_new = IO_util.read_hdf5(dir_in_new+filename_grid_new)
   
    grid_old = {'x':grid_old['x'], 'z':grid_old['z']}
    
    ## get IC
    data_new = util_interp.structured_interp(grid_old, data_old, grid_new, robust=True, method='linear')
    data_new.update(grid_new)
    
    ## distribution 
    x0 = data_new['x'][0,0]
    xm = data_new['x'][-1,0]
    dist_old = data_new['x'][:,0].copy()
    dist_new = np.linspace(x0, xm, data_new['x'].shape[0])
def main():
    ###---parameters----###
    shape0 = (32, 256)  #(i,k)(this is only used in orthogonal gridgen)
    shape1 = (96, 256)
    shape_out = (16, 100, 140)  #(j,i,k)(this is FINAL SHAPE)
    xl = -30.e-4  # (xl,yl) is top-left point of whole domain
    yl = .12
    # skip options(skip gridgen)
    skip_shock = False
    skip_freestream = False
    # Files required to start interpolation
    dir_in = './InitBody/'
    filename_in_body = 'ConeSurfGeometry.dat'
    filename_in_shock = 'ConeShockGeometry.dat'
    dir_IC = '/usr/local/home/yl8bc/yl8bc/data/cone/run7_Col_2d/REST/'
    filename_in_grid_IC = 'grid.h5'
    filename_in_data_IC = 'flowdata_00050000.h5'

    # Files generated by the program
    dir_out = '/usr/local/home/yl8bc/duannas/yl8bc/data/cone/run11_GCL/REST/'
    filename_out_shock = 'cone_grid_flat_shock.h5'
    filename_out_freestream = 'cone_grid_flat_freestream.h5'
    filename_out_full = 'grid.h5'
    filename_out_IC = 'flowdata_00000000.h5'
    filename_out_gd = 'gridDerivative_f.h5'
    filename_out_mi = 'metric_identities_f.h5'
    ###---no parameters below---#

    if skip_shock:
        grid_tmp = IO_util.read_hdf5(dir_out + filename_out_shock)
        u_s = grid_tmp['x']
        v_s = grid_tmp['z']
    else:
        ## define wall
        body = np.loadtxt(dir_in + filename_in_body, skiprows=2)
        #poly = np.polyfit(body[21:35,0], body[21:35,1], 10)
        #body[21:35,1] = np.polyval(poly, body[21:35,0])
        ## define shock
        shock = np.loadtxt(dir_in + filename_in_shock, skiprows=2)
        ## compute shock part
        u_s, v_s = flat_shock.gridgen(shape0, body, shock,
                                      dir_out + filename_out_shock)

    ## compute full grid
    if skip_freestream:
        grid_tmp = IO_util.read_hdf5(dir_out + filename_out_freestream)
        u_f = grid_tmp['x']
        v_f = grid_tmp['z']
    else:
        u_f, v_f = flat_freestream.gridgen(shape1[0], xl, yl, u_s, v_s,
                                           dir_out + filename_out_freestream)

    ## combine grids
    u, v = flat_combined.gridgen(u_f, v_f, u_s, v_s, shape1[0] - 8, shape1[0])
    grid_out = {'x': u, 'z': v}

    ## IC
    grid_IC = IO_util.read_hdf5(dir_IC + filename_in_grid_IC)
    data_IC = IO_util.read_hdf5(dir_IC + filename_in_data_IC)
    data_out = IC_by_interp.ICgen(grid_IC, data_IC, grid_out)

    ## reshape in 2d
    grid_out = reshape.reshape_by_index(shape_out[1:], grid_out)
    data_out = reshape.reshape_by_index(shape_out[1:], data_out)

    ## redistribute
    slc_axis = np.s_[:, 0]
    dist_old = grid_out['x'][slc_axis].copy()
    pdist_new = dist.pdist(dist_old[0], dist_old[-1], dist_old.shape[0])
    dist_new = pdist_new.tanh(2.5, type='right')
    grid_out = reshape.redistribute(dist_new, dist_old, grid_out)
    data_out = reshape.redistribute(dist_new, dist_old, data_out)

    ## expand
    grid_out = reshape.expand_spanwise(shape_out[0],
                                       grid_out,
                                       dim_new=1,
                                       span_name='y')
    data_out = reshape.expand_spanwise(shape_out[0], data_out, dim_new=1)

    ## polar treatment
    grid_out['z'] = shift.Colonius_shift(grid_out['z'], 2)

    ## regulate
    slc_body = np.s_[-1, :, :]
    data_out['v'][:] = 0.
    data_out['T'][slc_body] = 400.

    ## inlet
    data_inlet = {
        key: data_out[key][0:1, :, :]
        for key in ['T', 'p', 'u', 'v', 'w']
    }

    # RANS
    data_inlet['p'][:] = 6878.1
    data_inlet['u'][:] = 1508.7
    data_inlet['v'][:] = 0.
    data_inlet['w'][:] = 0.
    data_inlet['T'][:] = 202.08

    ## ducros
    #    ducros = sensor.ducros(data_out['u'], data_out['v'], data_out['w'], grid_out, \
    #                           u_inf=1508., delta_in = 0.125)
    #    dist_old = grid_out['x'][:,0,0].copy()
    #    dist_new = dist.ptrans(dist_old).expo(.5, 50)
    #    grid_out = reshape.redistribute(dist_new, dist_old, grid_out, dim=0)
    #    data_out = reshape.redistribute(dist_new, dist_old, data_out, dim=0)

    ## metrICs
    grid_tmp, grid_derivative = m_gd.analytically_2d(grid_out,
                                                     bc_g=[0, 0, 0, 0, 0, 0],
                                                     bc_gd=[0, 0, 1, 1, 0, 1])
    #grid_tmp, grid_derivative = m_gd.native(grid_out, bc_g=[0,0,0,0,0,0], bc_gd=[1,1, 0,0, 0,1])

    mm, Ji = m_mm.compute_mesh_metrics(grid_derivative)
    I = m_mm.compute_metric_identities(mm, Ji)

    ## transpose
    grid_out = {
        key: np.swapaxes(value, 0, 1)
        for key, value in grid_out.items()
    }
    data_out = {
        key: np.swapaxes(value, 0, 1)
        for key, value in data_out.items()
    }
    data_inlet = {
        key: np.swapaxes(value, 0, 1)
        for key, value in data_inlet.items()
    }

    grid_derivative = np.swapaxes(grid_derivative, 2, 3)
    mm = np.swapaxes(mm, 2, 3)
    I = np.swapaxes(I, 1, 2)
    ducros = np.swapaxes(ducros, 0, 1)

    ## time
    IC_by_interp.add_time(data_out)

    ## out
    IO_util.write_hdf5(dir_out + filename_out_full, grid_out)
    IO_util.write_hdf5(dir_out + filename_out_IC, data_out)
    grid_derivative = m_gd.pack_grid_derivative(grid_derivative)
    IO_util.write_hdf5(dir_out + filename_out_gd, grid_derivative)
    I = m_mm.pack_metric_identities(I)
    IO_util.write_hdf5(dir_out + filename_out_mi, I)
    IO_util.write_hdf5(dir_out + 'inlet', data_inlet)
    data_out.update(grid_out)
    data_out.update(grid_derivative)
    data_out.update({'ducros': ducros})
    IO_util.write_hdf5(dir_out + 'vis', data_out)
Esempio n. 11
0
        #     idx_right1, u[-1,1:-1],v[-1,1:-1] = gridgen.cm_gridgen.choose_boundary(choice_right, unit_vector, dev, idx_right)
        #
        #
        #     unit_vector, dev = gridgen.cm_gridgen.evaluate_bottom_boundary(u, v)
        #     idx_bottom1, u[1:-1,0],v[1:-1,0] = gridgen.cm_gridgen.choose_boundary(choice_bottom, unit_vector, dev, idx_bottom)
        #
        #     unit_vector, dev = gridgen.cm_gridgen.evaluate_top_boundary(u, v)
        #     idx_top1, u[1:-1,-1],v[1:-1,-1] = gridgen.cm_gridgen.choose_boundary(choice_top, unit_vector, dev, idx_top)
        #     if np.all(idx_left==idx_left1) \
        #             and np.all(idx_right==idx_right1) \
        #             and np.all(idx_bottom==idx_bottom1)  \
        #             and np.all(idx_top==idx_top1) : iloop=False
        #     idx_right = idx_right1
        #     idx_left = idx_left1
        #     idx_bottom = idx_bottom1
        #     idx_top = idx_top1

        u,v,idx_left,idx_right,idx_bottom,idx_top,iconverge = gridgen.cm_gridgen.compute_grid(u,v,idx_left,idx_right,
                                                                                              idx_bottom,idx_top,
                                                                                              choice_left,choice_right,
                                                                                              choice_bottom,choice_top, 1e-10, 0.5, 100)
        # print dev
        # iconverge=1
        #print left_angle
        grid = {'x':u, 'y':v}
        IO_util.write_hdf5('TEST', grid)
        if iconverge==1:
            print 'Converged!'
            iloop=False

Esempio n. 12
0
from util import util_cyl, IO_util

## params
dir_in = '../'  # directory in
filename_in_grid = 'grid.h5'
filename_in_data = 'flowdata_00000000.h5'
dir_out = './'  # directory out
filename_out_grid = 'grid.h5'
filename_out_data = 'flowdata_00000000.h5'
if_cart_to_cyl = True  # if converting cartesian to cylidrical? set True/False
## end params

## read files
grid = IO_util.read_hdf5(dir_in + filename_in_grid)
data = IO_util.read_hdf5(dir_in + filename_in_data)

## convert
if if_cart_to_cyl:
    x, y, z = util_cyl.coord_cart_to_cyl(grid['x'], grid['y'], grid['z'])
    u, v, w = util_cyl.vel_cart_to_cyl(data['u'], data['v'], data['w'], x, y,
                                       z)
else:
    x, y, z = util_cyl.coord_cyl_to_cart(grid['x'], grid['y'], grid['z'])
    u, v, w = util_cyl.vel_cyl_to_cart(data['u'], data['v'], data['w'],
                                       grid['x'], grid['y'], grid['z'])

##out
grid['x'] = x
grid['y'] = y
grid['z'] = z
data['u'] = u
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)
Esempio n. 14
0
def main():
    ###---parameters----###
    shape0 = (32, 256)  #(i,k)
    shape1 = (96, 256)
    shape_out = (16, 100, 140)  #(j,i,k)
    xl = -30.e-4
    yl = .12
    # skip options
    skip_shock = True  #False
    skip_freestream = True  #False
    # Files required to start interpolation
    dir_in = './InitBody/'
    filename_in_body = 'ConeSurfGeometry.dat'
    filename_in_shock = 'ConeShockGeometry.dat'
    dir_IC = '/usr/local/home/yl8bc/yl8bc/data/cone/run9/REST/'
    filename_in_grid_IC = 'grid.h5'
    filename_in_data_IC = 'flowdata_00100000.h5'

    # Files generated by the program
    dir_out = '/usr/local/home/yl8bc/duannas/yl8bc/data/cone/run7_2d_Lele/REST/'
    filename_out_shock = 'cone_grid_flat_shock.h5'
    filename_out_freestream = 'cone_grid_flat_freestream.h5'
    filename_out_full = 'grid.h5'
    filename_out_IC = 'flowdata_00000000.h5'
    filename_out_gd = 'gridDerivative_f.h5'
    ###---no parameters below---#

    if skip_shock:
        grid_tmp = IO_util.read_hdf5(dir_out + filename_out_shock)
        u_s = grid_tmp['x']
        v_s = grid_tmp['z']
    else:
        ## define wall
        body = np.loadtxt(dir_in + filename_in_body, skiprows=2)
        ## define shock
        shock = np.loadtxt(dir_in + filename_in_shock, skiprows=2)
        ## compute shock part
        u_s, v_s = flat_shock.gridgen(shape0, body, shock,
                                      dir_out + filename_out_shock)

    ## compute full grid
    if skip_freestream:
        grid_tmp = IO_util.read_hdf5(dir_out + filename_out_freestream)
        u_f = grid_tmp['x']
        v_f = grid_tmp['z']
    else:
        u_f, v_f = flat_freestream.gridgen(shape1[0], xl, yl, u_s, v_s,
                                           dir_out + filename_out_freestream)

    ## combine grids
    u, v = flat_combined.gridgen(u_f, v_f, u_s, v_s, shape1[0] - 8, shape1[0])
    grid_out = {'x': u, 'z': v}

    ## IC
    grid_IC = IO_util.read_hdf5(dir_IC + filename_in_grid_IC)
    data_IC = IO_util.read_hdf5(dir_IC + filename_in_data_IC)
    data_out = IC_by_interp.ICgen(grid_IC, data_IC, grid_out)

    ## reshape
    grid_out = reshape.reshape_by_index(shape_out[1:], grid_out)
    data_out = reshape.reshape_by_index(shape_out[1:], data_out)

    ## redistribute
    slc_axis = np.s_[:, 0]
    dist_old = grid_out['x'][slc_axis].copy()
    pdist_new = dist.pdist(dist_old[0], dist_old[-1], dist_old.shape[0])
    dist_new = pdist_new.tanh(1.5, type='right')
    grid_out = reshape.redistribute(dist_new, dist_old, grid_out)
    data_out = reshape.redistribute(dist_new, dist_old, data_out)

    ## expand
    grid_out = reshape.expand_spanwise(shape_out[0], grid_out, span_name='y')
    data_out = reshape.expand_spanwise(shape_out[0], data_out)

    ## polar treatment
    #grid_out['z'] = shift.Colonius_shift(grid_out['z'], 2)

    ## regulate
    slc_body = np.s_[:, -1, :]
    data_out['v'][:] = 0.
    data_out['T'][slc_body] = 400.

    ## time
    IC_by_interp.add_time(data_out)

    ## inlet
    data_inlet = {
        key: data_out[key][:, 0:1, :]
        for key in ['T', 'p', 'u', 'v', 'w']
    }

    # RANS
    data_inlet['p'][:] = 6878.1
    data_inlet['u'][:] = 1508.7  #570.
    data_inlet['v'][:] = 0.
    data_inlet['w'][:] = 0.
    data_inlet['T'][:] = 202.08

    ## metrICs
    grid_tmp, grid_derivative = m_gd.analytically_2d(grid_out,
                                                     bc_g=[0, 0, 0, 0, 1, 0],
                                                     bc_gd=[0, 0, 1, 1, 0, 1])

    ## out
    IO_util.write_hdf5(dir_out + filename_out_full, grid_out)
    IO_util.write_hdf5(dir_out + 'ghost', grid_tmp)
    IO_util.write_hdf5(dir_out + filename_out_IC, data_out)
    grid_derivative = m_gd.pack_grid_derivative(grid_derivative)
    IO_util.write_hdf5(dir_out + filename_out_gd, grid_derivative)
    IO_util.write_hdf5(dir_out + 'inlet', data_inlet)
    data_out.update(grid_tmp)
    data_out.update(grid_derivative)
    IO_util.write_hdf5(dir_out + 'vis', data_out)
from util import IO_util, util_interp
import numpy as np

if __name__ == '__main__':
    ##---params --##
    shape = (512, 128)
    dir_in = './InitBody/'
    filename_delta = 'BL.dat'
    ##
    dir_out = '../../data/grids/'
    filename_in_grid = 'cone_grid_parabolic_part2.h5'
    filename_out = 'cone_para_part2'
    ##---params end----##
    
    ## Input
    grid_in, names = IO_util.read_hdf5(dir_out+filename_in_grid)
    delta = np.loadtxt(dir_in+filename_delta)
    
    ## assess delta
    dist = np.linspace( grid_in['z'][0,0], grid_in['z'][0,-1], shape[1] )
    for i in range(shape[0]):
        grid_in['z'][i,:] = np.interp( 
    

    ## output
    IO_util.write_hdf5(dir_out+filename_out, grid_new)

    
    
Esempio n. 16
0
def main():
    ###params###

    mrange = range(1, 99, 1)
    mmax = len(mrange)
    nmax = 75

    dir_in = '/usr/local/home/yl8bc/data_local/cone/run3_Col_native/REST/'
    filename_in_grid = 'grid.h5'
    filename_in_data = 'flowdata_00024000.h5'
    ## files output:
    dir_out = '/usr/local/home/yl8bc/yl8bc/data/cone/FLUENT/'
    filename_out_profiles = 'profiles_dns_GCL'
    filename_out_integrals = 'integrals_dns_GCL'
    ##--below no param is defined--##
    tstart = time.time()
    keys_change = {
        'X': 'x',
        'Y': 'z',
        'X Velocity': 'uave',
        'Y Velocity': 'wave',
        'Pressure': 'pave',
        'Density': 'rhoave',
        'Temperature': 'tave'
    }
    grid_keys = ['x', 'z']

    ## read grid and data
    grid = IO_util.read_hdf5(dir_in + filename_in_grid)
    data = IO_util.read_hdf5(dir_in + filename_in_data)
    print('Data read. Time elapsed: %f secs' % (time.time() - tstart))

    ## slice
    data.update(grid)
    data.pop('time')
    sdata = util_data.structured_data(data, ['y', 'x', 'z'])
    sdata = sdata.slice_data(0, 0)

    ## wall normal profiles
    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 = util_flow.get_rho(profiles_out['p'][n, :],
                                profiles_out['T'][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_profiles, profiles_out)
    IO_util.write_hdf5(dir_out + filename_out_integrals, int_out)
    #x[:] = stretch_tanh(x, 2., type='left')
    return

if __name__ == '__main__':
    ###---parameters----###
    # Files required to start interpolation
    # "filename_fluent": old file that contains Fluent data in .dat format
    shape = (32, 100, 140)
    dir_in = '../../data/grids/'
    filename_in = 'cone_grid_flat_part2.h5'
    # Files generated by the program
    dir_out = '/usr/local/home/yl8bc/duannas/yl8bc/data/cone/run3_polar/REST/' 
    filename_out = 'grid'

    ## stack those grids
    grid_in, names = IO_util.read_hdf5(dir_in+filename_in)
    
    ## 
    x0 = grid_in['x'][0,0]
    xm = grid_in['x'][-1,0]
    dist_bot = grid_in['x'][:,0].copy()
    distribution = np.linspace(x0, xm, grid_in['x'].shape[0])
    #distribution =  grid_in['x'][:,0]
    #stretch_func(distribution)
    
    ## interp by distribution
    for key,var in grid_in.iteritems():
        for n in range(0, grid_in['x'].shape[1]):
            grid_in[key][:,n] = np.interp( distribution, dist_bot, var[:,n])
    
    ## intep to new shape
Esempio n. 18
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)

    ##  read grid atg walls
    grid, gridname = IO_util.read_hdf5(dir_in + filename_grid,
                                       vars_name=['x', 'z'])
    x = grid['x'][:, 0]
    z = np.mean(grid['z'][ibe:ien, :] / delta[ibe:ien, np.newaxis], axis=0)

    ##  plots
    fig, axe = plt.subplots(1, 1)
    axe.plot(x, prms_tauw_vs_x)
    util_plot.labels(axe, 'x/m', r'$p_{rms}/\tau_{w}$')
    util_plot.title(axe, r'$p_{rms}/\tau_{w}$ along k = %d' % index_k_vs_x)
    fig.savefig(dir_out + 'prms_tauw_vs_x.png')
    fig, axe = plt.subplots(1, 1)
    axe.plot(z, prms_tauw_vs_z)
    util_plot.labels(axe, r'$z/\delta$', r'$p_{rms}/\tau_{w}$')
    util_plot.title(axe,
                    r'$p_{rms}/\tau_{w}$ in window i = %d~%d' % (ibe, ien))
    fig.savefig(dir_out + 'prms_tauw_vs_z.png')