Example #1
0
def debug(PATH, case_name):
    '''
    DEF:    monitor case.
    INPUT:  - case_name: name of the case, type=string
    OUTPUT: - ()
    '''
    case_path = get_case_path(PATH, case_name)
    print('extract config...')
    config = get_config(case_path)

    if config['double_flag'] == 0:
        print('=========================================')
        print('Single precision complie')
        print('=========================================')
        os.environ["PRECISION"] = ""
    else:
        print('=========================================')
        print('Double precision complie')
        print('=========================================')
        os.environ["PRECISION"] = "-DDOUBLE"

    os.chdir(os.path.join(case_path, 'src'))

    os.system('make -j6')
    #os.system('make -j2')
    os.system('mpirun -np ' + str(config['job_np']) + ' ./wireles_src')
Example #2
0
def make(PATH, case_name):
    '''
    DEF:    monitor case.
    INPUT:  - case_name: name of the case, type=string
    OUTPUT: - ()
    '''
    case_path = get_case_path(PATH, case_name)
    ############################################################################
    # EXTRACT CONFIG
    print('extract config...')
    config = get_config(case_path)

    if config['double_flag'] == 0:
        print('=========================================')
        print('Single precision complie')
        print('=========================================')
        os.environ["PRECISION"] = ""
    else:

        print('=========================================')
        print('Double precision complie')
        print('=========================================')
        os.environ["PRECISION"] = "-DDOUBLE"
    # Try to compile twice in case the first compiling falied due to dependency
    os.system('make -j6 -C ' + str(os.path.join(case_path, 'src')))
    #os.system('make -j2 -C ' + str(os.path.join(case_path, 'src')))
Example #3
0
def monitor1(PATH, case_name):
    '''
    DEF:    monitor1 case (slurm).
    INPUT:  - case_name: name of the case, type=string
    OUTPUT: - ()
    '''
    case_path = get_case_path(PATH, case_name)
    os.system('tail -f ' + str(os.path.join(case_path, 'slurm*')))
Example #4
0
def remove(PATH, case_name):
    '''
    DEF:    remove case.
    INPUT:  - case_name: name of the case, type=string
    OUTPUT: - ()
    '''
    case_path = get_case_path(PATH, case_name)
    os.system('rm -r ' + str(os.path.join(case_path)))
Example #5
0
def edit(PATH, case_name):
    '''
    DEF:    edit case.
    INPUT:  - case_name: name of the case, type=string
    OUTPUT: - ()
    '''
    case_path = get_case_path(PATH, case_name)
    os.system(EDITOR_NAME + ' ' +
              str(os.path.join(case_path, 'input', 'config')))
Example #6
0
def clean(PATH, case_name):
    '''
    DEF:    clean case.
    INPUT:  - case_name: name of the case, type=string
    OUTPUT: - ()
    '''
    case_path = get_case_path(PATH, case_name)
    os.system('rm -r ' + os.path.join(case_path, 'src ')  + \
    os.path.join(case_path, 'output ') + \
    os.path.join(case_path, 'init_data ') + \
    os.path.join(case_path, 'inflow_data ') + \
    os.path.join(case_path, 'slurm* ') + \
    os.path.join(case_path, 'log'))
Example #7
0
def post(PATH, case_name):
    '''
    DEF:    post-processing for wireles.
    INPUT:  - case_name
    OUTPUT: - ()
    '''
    case_path = fctlib.get_case_path(PATH, case_name)

    ############################################################################
    # INIT
    out_path = os.path.join(case_path, 'output')
    fctlib.test_and_mkdir(out_path)
    src_out_path = os.path.join(PATH['job'], case_name, 'src', 'output')
    src_inp_path = os.path.join(PATH['job'], case_name, 'src', 'input')

    ############################################################################
    # CONFIG
    print('extract config...')
    config = fctlib.get_config(case_path)

    ############################################################################
    # COMPUTE
    print('compute results...')
    space = get_space(config)
    time = get_time(config)
    if config['log_flag'] > 0:
        log = get_log(src_out_path, config)
    if config['ta_flag'] > 0:
        result_3d = get_result_3d(src_inp_path, src_out_path, config)
        result_pr = get_result_pr(result_3d, config)
    if config['ts_flag'] > 0:
        result_4d = get_result_4d(src_out_path, config)

    # print( 'u_half: ' + str(result_pr['u_avg_c'][config['nz']//2]) )

    ############################################################################
    # PLOT
    print('plot results...')
    if config['log_flag'] > 0:
        plot_log(time, log, config, out_path)

    if config['ta_flag'] > 0:

        ########################################################################
        # pr global

        plot_pr_uvw(space, result_pr, config, out_path)
        plot_pr_log(space, result_pr, config, out_path)
        plot_pr_phi(space, result_pr, config, out_path)
        plot_pr_st(space, result_pr, config, out_path)

        ########################################################################
        # avg

        plot_sl(space['x_'], space['y_'],
                result_3d['u_avg_c'][:, :, config['nz'] // 2], 'x', 'y',
                'u_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['u_avg_c'][:, config['ny'] // 2, :], 'x', 'z',
                'u_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_avg_c'][config['nx'] // 2, :, :], 'y', 'z',
                'u_avg', 1, out_path)

        plot_sl(space['x_'], space['y_'],
                result_3d['v_avg_c'][:, :, config['nz'] // 2], 'x', 'y',
                'v_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['v_avg_c'][:, config['ny'] // 2, :], 'x', 'z',
                'v_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['v_avg_c'][config['nx'] // 2, :, :], 'y', 'z',
                'v_avg', 1, out_path)

        plot_sl(space['x_'], space['y_'],
                result_3d['w_avg_c'][:, :, config['nz'] // 2], 'x', 'y',
                'w_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['w_avg_c'][:, config['ny'] // 2, :], 'x', 'z',
                'w_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['w_avg_c'][config['nx'] // 2, :, :], 'y', 'z',
                'w_avg', 1, out_path)

        ########################################################################
        # std

        plot_sl(space['x_'], space['y_'],
                result_3d['u_std_c'][:, :, config['nz'] // 2], 'x', 'y',
                'u_std', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['u_std_c'][:, config['ny'] // 2, :], 'x', 'z',
                'u_std', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_std_c'][config['nx'] // 2, :, :], 'y', 'z',
                'u_std', 1, out_path)

        plot_sl(space['x_'], space['y_'],
                result_3d['v_std_c'][:, :, config['nz'] // 2], 'x', 'y',
                'v_std', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['v_std_c'][:, config['ny'] // 2, :], 'x', 'z',
                'v_std', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['v_std_c'][config['nx'] // 2, :, :], 'y', 'z',
                'v_std', 1, out_path)

        plot_sl(space['x_'], space['y_'],
                result_3d['w_std_c'][:, :, config['nz'] // 2], 'x', 'y',
                'w_std', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['w_std_c'][:, config['ny'] // 2, :], 'x', 'z',
                'w_std', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['w_std_c'][config['nx'] // 2, :, :], 'y', 'z',
                'w_std', 1, out_path)
Example #8
0
def anime(PATH, case_name):
    '''
    DEF:    post-processing for wireles.
    INPUT:  - case_name
    OUTPUT: - Statistics field: stat.h5
            - Instantanous field: animation.h5 
    '''
    case_path = fctlib.get_case_path(PATH, case_name)

    ############################################################################
    # INIT
    out_path = os.path.join(case_path, 'output')
    in_path = os.path.join(case_path, 'input')
    fctlib.test_and_mkdir(out_path)
    src_out_path = os.path.join(PATH['job'], case_name, 'src', 'output')
    src_inp_path = os.path.join(PATH['job'], case_name, 'src', 'input')

    ############################################################################
    # CONFIG
    print('extract config...')
    config = fctlib.get_config(case_path)

    ############################################################################
    # COMPUTE
    print('compute results...')
    print('Flow Fields:')
    print('Flow Fields:')

    space = post.get_space(config)
    time = post.get_time(config)

    if config['ta_flag'] > 0:
        result_3d = post.get_result_3d(src_inp_path, src_out_path, config)

        f = h5py.File(out_path+'/'+case_name+'_ta.h5', 'w')
        grp = f.create_group("data")
        # print(result_3d['u_avg_c'].shape)
        dset = grp.create_dataset("u_avg", data=result_3d['u_avg_c'])
        dset = grp.create_dataset("v_avg", data=result_3d['v_avg_c'])
        dset = grp.create_dataset("w_avg", data=result_3d['w_avg_c'])
        dset = grp.create_dataset("u_std", data=result_3d['u_std_c'])
        dset = grp.create_dataset("v_std", data=result_3d['v_std_c'])
        dset = grp.create_dataset("w_std", data=result_3d['w_std_c'])

        x_grid_unmask = space['x']
        y_grid_unmask = space['y']
        z_grid_unmask = space['z_c']

        x = x_grid_unmask[config['ts_istart']-1:config['ts_iend']]
        y = y_grid_unmask[config['ts_jstart']-1:config['ts_jend']]
        z = z_grid_unmask[:config['ts_kend']-1]

        dset = grp.create_dataset("x", data=x)
        dset = grp.create_dataset("y", data=y)
        dset = grp.create_dataset("z", data=z)

    # gridToVTK(
    #     out_path+'/'+case_name,
    #     x,
    #     y,
    #     z,
    #     pointData={"u": result_3d['u_avg_c'],"v": result_3d['v_avg_c'],"w": result_3d['w_avg_c']}
    # )

        for key, value in config.items():
            grp.attrs[key]=value

        f.close()
        if config['turb_flag'] > 0:
            df = pd.read_csv(in_path+'/turb_loc.dat')
            df_power = pd.read_csv(src_out_path+'/ta_power.dat',header=None)
            df['power'] = df_power
            print(df['power'])
            print(np.sum(df_power.to_numpy()))
            df.to_csv(out_path+'/ta_power.csv',index=False)


    #         # Spatial coorindates (masked)


    #     XX,YY = np.meshgrid(x,y,indexing='ij')
    #     YY2,ZZ = np.meshgrid(y,z,indexing='ij')
    #     u = result_3d['u_avg_c']
    #     v = result_3d['v_avg_c']
    #     w = result_3d['w_avg_c']

    #     # result_pr = post.get_result_pr(result_3d, config)
    # if config['ts_flag'] > 0:
    #     result_4d = post.get_result_4d(src_out_path, config)

    # f = h5py.File(out_path+'/'+case_name+'_ts.h5', 'w')

    hub_k = int(config['turb_z']/config['dz'])+1
    print(hub_k)

    # u2 = u*u - np.mean(u,axis=0)*np.mean(u,axis=0)
    # v2 = v*v - np.mean(v,axis=0)*np.mean(v,axis=0)
    # w2 = w*w - np.mean(w,axis=0)*np.mean(w,axis=0)
    # uw = u*w - np.mean(u,axis=0)*np.mean(w,axis=0)
    
    # print(u.shape)
    # def rms_profile(x2):
    #     x2_mean = np.sqrt(np.mean(np.mean(np.mean(x2[:,:,:,:],axis=0),axis=0),axis=0))
    #     return x2_mean
    
    # def vel_profile(x):
    #     x_mean = np.mean(np.mean(np.mean(x[:,:,:,:],axis=0),axis=0),axis=0)
    #     return x_mean
    
    # u_profile = vel_profile(u)
    # v_profile = vel_profile(v)
    # w_profile = vel_profile(w)

    # u2_profile = rms_profile(u2)
    # v2_profile = rms_profile(v2)
    # w2_profile = rms_profile(w2)

    # print(u_profile[hub_k])
    # print(u2_profile[hub_k]/u_profile[hub_k])
    # # u_hori = np.sqrt(u**2 + v**2)
    # # velocity profile
    # figure(num=None, figsize=(12, 3), dpi=100, facecolor='w', edgecolor='k')
    # log_profle = 1.0/0.4*np.log((z/config['zo']))
    # # log_profle = 0.25/0.4*np.log((z/(config['zo'])))
    # plt.semilogx(z/config['lz'],u_profile,'o')
    # plt.semilogx(z/config['lz'],log_profle,'k--')
    # plt.subplot(141)
    # plt.plot(u_profile,z/config['lz'],label='sp')
    # plt.xlabel('$\overline{u}/u_*$')
    # plt.ylabel('$z/H$')
    # plt.legend()

    # plt.subplot(142)
    # plt.plot(u2_profile,z/config['lz'])
    # plt.xlabel('$\sigma_u/u_*$')
    # plt.ylabel('$z/H$')

    # plt.subplot(143)
    # plt.plot(v2_profile,z/config['lz'])
    # plt.xlabel('$\sigma_v/u_*$')
    # plt.ylabel('$z/H$')

    # plt.subplot(144)
    # plt.plot(w2_profile,z/config['lz'])
    # plt.xlabel('$\sigma_w/u_*$')
    # plt.ylabel('$z/H$')

    # plt.tight_layout()

    # plt.savefig('profile.png')
    # # np.save('u_sp',mean_profile)


    # # # Mean field at hub-height

    # figure(num=None, figsize=(12, 8), dpi=100, facecolor='w', edgecolor='k')
    # u_mean = np.mean(u,axis=0)
    # u2_mean = np.mean(u*u,axis=0) - u_mean*u_mean
    # u_mean_field = u_mean
    # # plt.plot(u_mean_field[156,:,20],'.')
    # # plt.ylim([0,-0.8])
    # # plt.plot(np.mean(np.mean(u2_mean,axis=0),axis=0))
    # # u_mean_field = (u_mean/5.2)-1
    # plt.imshow(u2_mean[:,:,hub_k].T,origin='lower',aspect=config['dy']/config['dx'])
    # plt.colorbar()
    # # plt.clim(0,0.2)
    # # plt.plot(u2_mean[:,14,20])
    # plt.savefig('field.png')
    # # print('Print mean field')
    # # np.save('u_mean.npy',u_mean)
    # # np.save('u2_mean.npy',u2_mean)

    if config['ts_flag'] > 0:
        result_4d = post.get_result_4d(src_out_path, config)

        u = result_4d['u_inst_c']
        v = result_4d['v_inst_c']
        w = result_4d['w_inst_c']

        fig, ax = plt.subplots(2,1)
        # i = 9
        def animate(i):    #     azimuths = np.radians(np.linspace(0, 360, 40))
        #     zeniths = np.linspace(0, 0.5, 30)
        #     theta,r = np.meshgrid(azimuths,zeniths,indexing='ij')
            values = u[i,:,:,hub_k]#np.random.random((azimuths.size, zeniths.size))
            im1 = ax[0].imshow(values.T,origin='lower',aspect=config['dy']/config['dx'])
            ax[0].set_xlabel('x')
            ax[0].set_ylabel('y')
            values = u[i,64,:,:]#np.random.random((azimuths.size, zeniths.size))
            im2 = ax[1].imshow(values.T,origin='lower',aspect=config['dz']/config['dy'])
            # im2 = ax[1].quiver(v[i,300,1::4,1::4].T,w[i,300,1::4,1::4].T,scale=10)
            # ax[1].scatter([63],[19],marker='+',color='r')
            ax[1].set_xlabel('y')
            ax[1].set_ylabel('z')
            print(i)
            # return


        # fig.colorbar(im1, ax=ax[0])
        # fig.colorbar(im2, ax=ax[1])
        # plt.savefig('force.png')
        anim = animation.FuncAnimation(fig, animate, frames=10)
        anim.save(out_path+'/animation.gif',writer='imagemagick', fps=10)
Example #9
0
def solve(PATH, case_name):
    case_path = get_case_path(PATH, case_name)
    os.system(' sbatch --partition=gpu --qos=gpu --gres=gpu:2' +
              os.path.join(case_path, 'src', case_name + '_src'))
Example #10
0
def post(PATH, case_name):
    '''
    DEF:    post-processing for wireles.
    INPUT:  - case_name
    OUTPUT: - ()
    '''
    case_path = fctlib.get_case_path(PATH, case_name)

    ############################################################################
    # INIT
    out_path = os.path.join(case_path, 'output')
    fctlib.test_and_mkdir(out_path)
    src_out_path = os.path.join(PATH['job'], case_name, 'src', 'output')
    src_inp_path = os.path.join(PATH['job'], case_name, 'src', 'input')

    ############################################################################
    # CONFIG
    print('extract config...')
    config = fctlib.get_config(case_path)

    ############################################################################
    # COMPUTE
    print('compute results...')
    space = get_space(config)
    time = get_time(config)
    if config['log_flag'] > 0:
        log = get_log(src_out_path, config)
    if config['ta_flag'] > 0:
        result_3d = get_result_3d(src_inp_path, src_out_path, config)
        result_pr = get_result_pr(result_3d, config)
    if config['ts_flag'] > 0:
        result_4d = get_result_4d(src_out_path, config)

    ############################################################################
    # PLOT
    print('plot results...')
    # if config['log_flag'] > 0:
    # plot_log(time, log, config, out_path)

    if config['ta_flag'] > 0:

        ########################################################################
        # pr global

        plot_pr_uvw(space, result_pr, config, out_path)
        # plot_pr_log(space, result_pr, config, out_path)
        # plot_pr_phi(space, result_pr, config, out_path)
        # plot_pr_st(space, result_pr, config, out_path)

        ########################################################################
        # avg
        hub_k = int(config['turb_z'] / config['dz']) - 1
        print(hub_k)
        plot_sl(space['x_'], space['y_'], result_3d['u_avg_c'][:, :, hub_k],
                'x', 'y', 'u_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['u_avg_c'][:, config['ny'] // 2 - 1, :], 'x', 'z',
                'u_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_avg_c'][config['nx'] // 2 - 1, :, :], 'y', 'z',
                'u_avg', 1, out_path)

        plot_sl(space['x_'], space['y_'], result_3d['v_avg_c'][:, :, hub_k],
                'x', 'y', 'v_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['v_avg_c'][:, config['ny'] // 2 - 1, :], 'x', 'z',
                'v_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['v_avg_c'][config['nx'] // 2 - 1, :, :], 'y', 'z',
                'v_avg', 1, out_path)

        plot_sl(space['x_'], space['y_'], result_3d['w_avg_c'][:, :, hub_k],
                'x', 'y', 'w_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['w_avg_c'][:, config['ny'] // 2 - 1, :], 'x', 'z',
                'w_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['w_avg_c'][config['nx'] // 2 - 1, :, :], 'y', 'z',
                'w_avg', 1, out_path)

        ########################################################################
        # std

        inflow_avg = 0.5 * (
            np.mean(np.mean(result_3d['u_avg_c'][30:50, :, hub_k], axis=0),
                    axis=0) +
            np.mean(np.mean(result_3d['u_avg_c'][30:50, :, hub_k + 1], axis=0),
                    axis=0))
        inflow_ti = 0.5 * (
            np.mean(np.mean(result_3d['u_std_c'][30:50, :, hub_k], axis=0),
                    axis=0) +
            np.mean(np.mean(result_3d['u_std_c'][30:50, :, hub_k + 1], axis=0),
                    axis=0)) / inflow_avg
        print(inflow_avg, inflow_ti)

        plot_sl(space['x_'], space['y_'], result_3d['u_std_c'][:, :, hub_k],
                'x', 'y', 'u_std', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['u_std_c'][:, config['ny'] // 2, :], 'x', 'z',
                'u_std', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_std_c'][config['nx'] // 2, :, :], 'y', 'z',
                'u_std', 1, out_path)

        plot_sl(space['x_'], space['y_'], result_3d['v_std_c'][:, :, hub_k],
                'x', 'y', 'v_std', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['v_std_c'][:, config['ny'] // 2, :], 'x', 'z',
                'v_std', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['v_std_c'][config['nx'] // 2, :, :], 'y', 'z',
                'v_std', 1, out_path)

        plot_sl(space['x_'], space['y_'], result_3d['w_std_c'][:, :, hub_k],
                'x', 'y', 'w_std', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['w_std_c'][:, config['ny'] // 2, :], 'x', 'z',
                'w_std', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['w_std_c'][config['nx'] // 2, :, :], 'y', 'z',
                'w_std', 1, out_path)
Example #11
0
def post(PATH, case_name):
    '''
    DEF:    post-processing for wireles.
    INPUT:  - case_name
    OUTPUT: - ()
    '''
    case_path = fctlib.get_case_path(PATH, case_name)

    ############################################################################
    # INIT
    out_path = os.path.join(case_path, 'output')
    fctlib.test_and_mkdir(out_path)
    src_out_path = os.path.join(PATH['job'], case_name, 'src', 'output')
    src_inp_path = os.path.join(PATH['job'], case_name, 'src', 'input')

    ############################################################################
    # CONFIG
    print('extract config...')
    config = fctlib.get_config(case_path)

    ############################################################################
    # COMPUTE
    print('compute results...')
    space = get_space(config)
    time = get_time(config)
    if config['log_flag'] > 0:
        log = get_log(src_out_path, config)
    if config['ta_flag'] > 0:
        result_3d = get_result_3d(src_inp_path, src_out_path, config)
        result_pr = get_result_pr(result_3d, config)
    if config['ts_flag'] > 0:
        result_4d = get_result_4d(src_out_path, config)

    ############################################################################
    # PLOT
    print('plot results...')
    if config['log_flag'] > 0:
        plot_log(time, log, config, out_path)

    if config['ta_flag'] > 0:

        ########################################################################
        # pr global
        ########################################################################

        plot_pr_uvw(space, result_pr, config, out_path)
        plot_pr_log(space, result_pr, config, out_path)
        plot_pr_phi(space, result_pr, config, out_path)
        plot_pr_st(space, result_pr, config, out_path)

        ########################################################################
        # pr local
        ########################################################################

        plot_pr(
            space['z_c'][:config['nz'] // 2],
            result_3d['u_avg_c'][config['nx'] // 2 - 1 + 6,
                                 config['ny'] // 2 - 1, :config['nz'] // 2],
            'z_u_avg6', out_path)
        plot_pr(
            space['z_c'][:config['nz'] // 2],
            result_3d['u_avg_c'][config['nx'] // 2 - 1 + 12,
                                 config['ny'] // 2 - 1, :config['nz'] // 2],
            'z_u_avg12', out_path)
        plot_pr(
            space['z_c'][:config['nz'] // 2],
            result_3d['u_avg_c'][config['nx'] // 2 - 1 + 18,
                                 config['ny'] // 2 - 1, :config['nz'] // 2],
            'z_u_avg18', out_path)
        plot_pr(
            space['z_c'][:config['nz'] // 2],
            result_3d['u_avg_c'][config['nx'] // 2 - 1 + 24,
                                 config['ny'] // 2 - 1, :config['nz'] // 2],
            'z_u_avg24', out_path)

        ########################################################################
        # avg
        ########################################################################

        turb_i1 = 32
        turb_i2 = 96

        plot_sl(space['x'], space['y'], result_3d['u_avg_c'][:, :, 5], 'x',
                'y', 'u_avg5', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['u_avg_c'][:, :, 8], 'x',
                'y', 'u_avg8', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['u_avg_c'][:, :, 9], 'x',
                'y', 'u_avg9', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['u_avg_c'][:, :, 10], 'x',
                'y', 'u_avg10', 2, out_path)
        plot_sl(space['x'], space['z_n'],
                result_3d['u_avg_c'][:, config['ny'] // 2 - 1, :], 'x', 'z',
                'u_avg', 1, out_path)
        plot_sl(space['y'], space['z_n'],
                result_3d['u_avg_c'][turb_i1 - 1, :, :], 'y', 'z', 'u_avg1', 1,
                out_path)
        plot_sl(space['y'], space['z_n'],
                result_3d['u_avg_c'][turb_i2 - 1, :, :], 'y', 'z', 'u_avg2', 1,
                out_path)

        plot_sl(space['x'], space['y'], result_3d['v_avg_c'][:, :, 5], 'x',
                'y', 'v_avg5', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['v_avg_c'][:, :, 8], 'x',
                'y', 'v_avg8', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['v_avg_c'][:, :, 9], 'x',
                'y', 'v_avg9', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['v_avg_c'][:, :, 10], 'x',
                'y', 'v_avg10', 2, out_path)
        plot_sl(space['x'], space['z_n'],
                result_3d['v_avg_c'][:, config['ny'] // 2 - 1, :], 'x', 'z',
                'v_avg', 1, out_path)
        plot_sl(space['y'], space['z_n'],
                result_3d['v_avg_c'][turb_i1 - 1, :, :], 'y', 'z', 'v_avg1', 1,
                out_path)
        plot_sl(space['y'], space['z_n'],
                result_3d['v_avg_c'][turb_i2 - 1, :, :], 'y', 'z', 'v_avg2', 1,
                out_path)

        plot_sl(space['x'], space['y'], result_3d['w_avg_c'][:, :, 5], 'x',
                'y', 'w_avg5', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['w_avg_c'][:, :, 8], 'x',
                'y', 'w_avg8', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['w_avg_c'][:, :, 9], 'x',
                'y', 'w_avg9', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['w_avg_c'][:, :, 10], 'x',
                'y', 'w_avg10', 2, out_path)
        plot_sl(space['x'], space['z_n'],
                result_3d['w_avg_c'][:, config['ny'] // 2 - 1, :], 'x', 'z',
                'w_avg', 1, out_path)
        plot_sl(space['y'], space['z_n'],
                result_3d['w_avg_c'][turb_i1 - 1, :, :], 'y', 'z', 'w_avg1', 1,
                out_path)
        plot_sl(space['y'], space['z_n'],
                result_3d['w_avg_c'][turb_i2 - 1, :, :], 'y', 'z', 'w_avg2', 1,
                out_path)

        ########################################################################
        # std
        ########################################################################
        plot_sl(space['x'], space['y'], result_3d['u_std_c'][:, :, 5], 'x',
                'y', 'u_std5', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['u_std_c'][:, :, 8], 'x',
                'y', 'u_std8', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['u_std_c'][:, :, 9], 'x',
                'y', 'u_std9', 2, out_path)
        plot_sl(space['x'], space['y'], result_3d['u_std_c'][:, :, 10], 'x',
                'y', 'u_std10', 2, out_path)
        plot_sl(space['x'], space['z_n'],
                result_3d['u_std_c'][:, config['ny'] // 2 - 1, :], 'x', 'z',
                'u_std', 1, out_path)
        plot_sl(space['y'], space['z_n'],
                result_3d['u_std_c'][turb_i1 - 1, :, :], 'y', 'z', 'u_std1', 1,
                out_path)
        plot_sl(space['y'], space['z_n'],
                result_3d['u_std_c'][turb_i2 - 1, :, :], 'y', 'z', 'u_std2', 1,
                out_path)

        plot_sl(space['x_'], space['y_'], result_3d['u_inst_c'][:, :, 5], 'x',
                'y', 'u_inst5', 1, out_path)
        plot_sl(space['x_'], space['y_'], result_3d['u_inst_c'][:, :, 8], 'x',
                'y', 'u_inst8', 1, out_path)
        plot_sl(space['x_'], space['y_'], result_3d['u_inst_c'][:, :, 9], 'x',
                'y', 'u_inst9', 1, out_path)
        plot_sl(space['x_'], space['y_'], result_3d['u_inst_c'][:, :, 10], 'x',
                'y', 'u_inst10', 1, out_path)
        plot_sl(space['x_'], space['z_n'],
                result_3d['u_inst_c'][:, config['ny'] // 2 - 1, :], 'x', 'z',
                'u_inst', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_inst_c'][turb_i1 - 1, :, :], 'y', 'z', 'u_inst1',
                1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_inst_c'][turb_i2 - 1, :, :], 'y', 'z', 'u_inst2',
                1, out_path)
Example #12
0
def post(PATH, case_name):
    '''
    DEF:    post-processing for wireles.
    INPUT:  - case_name
    OUTPUT: - ()
    '''
    case_path = fctlib.get_case_path(PATH, case_name)

    ############################################################################
    # INIT
    out_path = os.path.join(case_path, 'output')
    fctlib.test_and_mkdir(out_path)
    src_out_path = os.path.join(PATH['job'], case_name, 'src', 'output')
    src_inp_path = os.path.join(PATH['job'], case_name, 'src', 'input')

    ############################################################################
    # CONFIG
    print('extract config...')
    config = fctlib.get_config(case_path)
    space = get_space(config)
    time = get_time(config)

    ############################################################################
    # COMPUTE RESULTS
    print('compute results...')
    if config['log_flag'] > 0:
        log = get_log(src_out_path, config)
    if config['ta_flag'] > 0:
        result_3d = get_result_3d(src_inp_path, src_out_path, config)
        result_pr = get_result_pr(result_3d, config)
    if config['ts_flag'] > 0:
        result_4d = get_result_4d(src_out_path, config)
    if config['turb_flag'] > 0:
        turb = get_turb(src_out_path, config)

    ############################################################################
    # NORMALIZATION

    turb_k = int(config['turb_z'] / config['dz'])
    result_3d['u_avgInflow'] = np.mean(result_3d['u_avg_c'][6 - 1:10 -
                                                            1, :, :],
                                       axis=(0, 1))
    result_3d['u_stdInflow'] = np.mean(result_3d['u_std_c'][6 - 1:10 -
                                                            1, :, :],
                                       axis=(0, 1))
    U = result_3d['u_avgInflow'][turb_k]
    D = 2 * config['turb_r']

    print('----------------------------------')
    print('turb_z     : ' + str(config['turb_z']))
    print('turb_k     : ' + str(turb_k))
    print('z_c[turb_k]: ' + str(space['z_c'][turb_k]))
    print('----------------------------------')
    print('U: ' + str(U))
    print('D: ' + str(D))
    print('----------------------------------')

    space['x'] = (space['x'] - turb_i * config['dx']) / D
    space['y'] = (space['y'] - turb_j * config['dy']) / D
    space['x_'] = (space['x_'] - turb_i * config['dx']) / D
    space['y_'] = (space['y_'] - turb_j * config['dy']) / D
    space['z_c'] = space['z_c'] / D
    space['z_n'] = space['z_n'] / D

    ############################################################################
    # PLOT RESULTS
    print('plot results...')

    if config['log_flag'] > 0:
        plot_log(time, log, config, out_path)

    if config['turb_flag'] > 0:
        plot_turb(time, turb, config, out_path)

    if config['ta_flag'] > 0:

        ########################################################################
        # pr global
        ########################################################################

        plot_pr_uvw(space, result_pr, config, out_path)
        plot_pr_log(space, result_pr, config, out_path)
        plot_pr_phi(space, result_pr, config, out_path)
        plot_pr_st(space, result_pr, config, out_path)

        ########################################################################
        # pr local
        ########################################################################
        plot_pr(space['z_c'], result_3d['u_avg_c'][turb_i + 2 * 3, turb_j, :],
                'z', 'u_avg2', out_path)
        plot_pr(space['z_c'], result_3d['u_avg_c'][turb_i + 4 * 3, turb_j, :],
                'z', 'u_avg4', out_path)
        plot_pr(space['z_c'], result_3d['u_avg_c'][turb_i + 6 * 3, turb_j, :],
                'z', 'u_avg6', out_path)
        plot_pr(space['z_c'], result_3d['u_avg_c'][turb_i + 8 * 3, turb_j, :],
                'z', 'u_avg8', out_path)

        plot_pr(space['y'], result_3d['u_avg_c'][turb_i + 2 * 3, :, turb_k],
                'y', 'u_avg2', out_path)
        plot_pr(space['y'], result_3d['u_avg_c'][turb_i + 4 * 3, :, turb_k],
                'y', 'u_avg4', out_path)
        plot_pr(space['y'], result_3d['u_avg_c'][turb_i + 6 * 3, :, turb_k],
                'y', 'u_avg6', out_path)
        plot_pr(space['y'], result_3d['u_avg_c'][turb_i + 8 * 3, :, turb_k],
                'y', 'u_avg8', out_path)

        plot_pr(space['z_c'], result_3d['u_std_c'][turb_i + 2 * 3, turb_j, :],
                'z', 'u_std2', out_path)
        plot_pr(space['z_c'], result_3d['u_std_c'][turb_i + 4 * 3, turb_j, :],
                'z', 'u_std4', out_path)
        plot_pr(space['z_c'], result_3d['u_std_c'][turb_i + 6 * 3, turb_j, :],
                'z', 'u_std6', out_path)
        plot_pr(space['z_c'], result_3d['u_std_c'][turb_i + 8 * 3, turb_j, :],
                'z', 'u_std8', out_path)

        plot_pr(space['y'], result_3d['u_std_c'][turb_i + 2 * 3, :, turb_k],
                'y', 'u_std2', out_path)
        plot_pr(space['y'], result_3d['u_std_c'][turb_i + 4 * 3, :, turb_k],
                'y', 'u_std4', out_path)
        plot_pr(space['y'], result_3d['u_std_c'][turb_i + 6 * 3, :, turb_k],
                'y', 'u_std6', out_path)
        plot_pr(space['y'], result_3d['u_std_c'][turb_i + 8 * 3, :, turb_k],
                'y', 'u_std8', out_path)

        plot_pr(space['z_c'], result_3d['v_avg_c'][turb_i + 2 * 3, turb_j, :],
                'z', 'v_avg2', out_path)
        plot_pr(space['z_c'], result_3d['v_avg_c'][turb_i + 4 * 3, turb_j, :],
                'z', 'v_avg4', out_path)
        plot_pr(space['z_c'], result_3d['v_avg_c'][turb_i + 6 * 3, turb_j, :],
                'z', 'v_avg6', out_path)
        plot_pr(space['z_c'], result_3d['v_avg_c'][turb_i + 8 * 3, turb_j, :],
                'z', 'v_avg8', out_path)

        plot_pr(space['y'], result_3d['w_avg_c'][turb_i + 2 * 3, :, turb_k],
                'y', 'w_avg2', out_path)
        plot_pr(space['y'], result_3d['w_avg_c'][turb_i + 4 * 3, :, turb_k],
                'y', 'w_avg4', out_path)
        plot_pr(space['y'], result_3d['w_avg_c'][turb_i + 6 * 3, :, turb_k],
                'y', 'w_avg6', out_path)
        plot_pr(space['y'], result_3d['w_avg_c'][turb_i + 8 * 3, :, turb_k],
                'y', 'w_avg8', out_path)

        ########################################################################
        # sl
        ########################################################################

        plot_sl(space['x_'], space['y_'], result_3d['u_avg_c'][:, :, turb_k],
                'x', 'y', 'u_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'], result_3d['u_avg_c'][:, turb_j, :],
                'x', 'z', 'u_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'], result_3d['u_avg_c'][turb_i, :, :],
                'y', 'z', 'u_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_avg_c'][turb_i + 2 * 3, :, :], 'y', 'z', 'u_avg2',
                1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_avg_c'][turb_i + 4 * 3, :, :], 'y', 'z', 'u_avg4',
                1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_avg_c'][turb_i + 6 * 3, :, :], 'y', 'z', 'u_avg6',
                1, out_path)
        plot_sl(space['y_'], space['z_n'],
                result_3d['u_avg_c'][turb_i + 8 * 3, :, :], 'y', 'z', 'u_avg8',
                1, out_path)

        plot_sl(space['x_'], space['y_'], result_3d['v_avg_c'][:, :, turb_k],
                'x', 'y', 'v_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'], result_3d['v_avg_c'][:, turb_j, :],
                'x', 'z', 'v_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'], result_3d['v_avg_c'][turb_i, :, :],
                'y', 'z', 'v_avg', 1, out_path)

        plot_sl(space['x_'], space['y_'], result_3d['w_avg_c'][:, :, turb_k],
                'x', 'y', 'w_avg', 1, out_path)
        plot_sl(space['x_'], space['z_n'], result_3d['w_avg_c'][:, turb_j, :],
                'x', 'z', 'w_avg', 1, out_path)
        plot_sl(space['y_'], space['z_n'], result_3d['w_avg_c'][turb_i, :, :],
                'y', 'z', 'w_avg', 1, out_path)

        ########################################################################
        # save pr for vali
        ########################################################################
        out_data_path = os.path.join(out_path, 'data')
        fctlib.test_and_mkdir(out_data_path)

        save_pr(space['z_c'], result_3d['u_avgInflow'], 'z_u_avgInflow',
                out_data_path)
        save_pr(space['z_c'], result_3d['u_stdInflow'], 'z_u_stdInflow',
                out_data_path)

        save_pr(space['z_c'], result_3d['u_avg_c'][turb_i + 2 * 3, turb_j, :],
                'z_u_avg2', out_data_path)
        save_pr(space['z_c'], result_3d['u_avg_c'][turb_i + 4 * 3, turb_j, :],
                'z_u_avg4', out_data_path)
        save_pr(space['z_c'], result_3d['u_avg_c'][turb_i + 6 * 3, turb_j, :],
                'z_u_avg6', out_data_path)
        save_pr(space['z_c'], result_3d['u_avg_c'][turb_i + 8 * 3, turb_j, :],
                'z_u_avg8', out_data_path)

        save_pr(space['y'], result_3d['u_avg_c'][turb_i + 2 * 3, :, turb_k],
                'y_u_avg2', out_data_path)
        save_pr(space['y'], result_3d['u_avg_c'][turb_i + 4 * 3, :, turb_k],
                'y_u_avg4', out_data_path)
        save_pr(space['y'], result_3d['u_avg_c'][turb_i + 6 * 3, :, turb_k],
                'y_u_avg6', out_data_path)
        save_pr(space['y'], result_3d['u_avg_c'][turb_i + 8 * 3, :, turb_k],
                'y_u_avg8', out_data_path)

        save_pr(space['z_c'], result_3d['u_std_c'][turb_i + 2 * 3, turb_j, :],
                'z_u_std2', out_data_path)
        save_pr(space['z_c'], result_3d['u_std_c'][turb_i + 4 * 3, turb_j, :],
                'z_u_std4', out_data_path)
        save_pr(space['z_c'], result_3d['u_std_c'][turb_i + 6 * 3, turb_j, :],
                'z_u_std6', out_data_path)
        save_pr(space['z_c'], result_3d['u_std_c'][turb_i + 8 * 3, turb_j, :],
                'z_u_std8', out_data_path)

        save_pr(space['y'], result_3d['u_std_c'][turb_i + 2 * 3, :, turb_k],
                'y_u_std2', out_data_path)
        save_pr(space['y'], result_3d['u_std_c'][turb_i + 4 * 3, :, turb_k],
                'y_u_std4', out_data_path)
        save_pr(space['y'], result_3d['u_std_c'][turb_i + 6 * 3, :, turb_k],
                'y_u_std6', out_data_path)
        save_pr(space['y'], result_3d['u_std_c'][turb_i + 8 * 3, :, turb_k],
                'y_u_std8', out_data_path)

        save_pr(space['z_c'], result_3d['v_avg_c'][turb_i + 2 * 3, turb_j, :],
                'z_v_avg2', out_data_path)
        save_pr(space['z_c'], result_3d['v_avg_c'][turb_i + 4 * 3, turb_j, :],
                'z_v_avg4', out_data_path)
        save_pr(space['z_c'], result_3d['v_avg_c'][turb_i + 6 * 3, turb_j, :],
                'z_v_avg6', out_data_path)
        save_pr(space['z_c'], result_3d['v_avg_c'][turb_i + 8 * 3, turb_j, :],
                'z_v_avg8', out_data_path)

        save_pr(space['y'], result_3d['w_avg_c'][turb_i + 2 * 3, :, turb_k],
                'y_w_avg2', out_data_path)
        save_pr(space['y'], result_3d['w_avg_c'][turb_i + 4 * 3, :, turb_k],
                'y_w_avg4', out_data_path)
        save_pr(space['y'], result_3d['w_avg_c'][turb_i + 6 * 3, :, turb_k],
                'y_w_avg6', out_data_path)
        save_pr(space['y'], result_3d['w_avg_c'][turb_i + 8 * 3, :, turb_k],
                'y_w_avg8', out_data_path)
Example #13
0
def pre(PATH, case_name):
    '''
    DEF:    pre-processing for wireles.
    INPUT:  - case_name
    OUTPUT: - ()
    '''
    case_path = fctlib.get_case_path(PATH, case_name)

    ############################################################################
    # COPY SRC FOLDER
    os.system('cp -r ' + PATH['src'] + ' ' + case_path)

    ############################################################################
    # EXTRACT CONFIG
    print('extract config...')
    config = fctlib.get_config(case_path)
    space = fctlib.get_space(config)

    ############################################################################
    # WRITE CONFIG
    print('write dimen...')
    config_path_tmp = os.path.join(PATH['src'], 'dimen.cuf')
    config_path = os.path.join(case_path, 'src', 'dimen.cuf')
    config_param = config.copy()
    substitute_keys(config_param, config_path_tmp, config_path)

    ############################################################################
    # WRITE BASH
    print('write jobsub...')
    sbatch_path_tmp = os.path.join(PATH['src'], 'jobsub')
    sbatch_path = os.path.join(case_path, 'src', case_name + '_src')
    sbatch_param = {
        'case_name': case_name,
        'job_np': config['job_np'],
        'job_time': config['job_time']
    }
    substitute_keys(sbatch_param, sbatch_path_tmp, sbatch_path)

    ############################################################################
    # WRITE INIT
    print('write init...')

    if config['sim_flag'] == 0:

        if config['resub_flag'] == 0:
            u_init, v_init, w_init = compute_vel(config)
            u_init.tofile(os.path.join(case_path, 'src', 'input', 'u.bin'))
            v_init.tofile(os.path.join(case_path, 'src', 'input', 'v.bin'))
            w_init.tofile(os.path.join(case_path, 'src', 'input', 'w.bin'))

    if config['sim_flag'] == 1:

        if config['resub_flag'] == 0:

            interp_path = fctlib.get_case_path(PATH, config['interp_case'])
            u_init = post_interp(interp_path, case_path, config, 'u')
            v_init = post_interp(interp_path, case_path, config, 'v')
            w_init = post_interp(interp_path, case_path, config, 'w')
            u_init.tofile(os.path.join(case_path, 'src', 'input', 'u.bin'))
            v_init.tofile(os.path.join(case_path, 'src', 'input', 'v.bin'))
            w_init.tofile(os.path.join(case_path, 'src', 'input', 'w.bin'))

    if config['sim_flag'] == 2:

        if config['resub_flag'] == 0:

            warmup_path = fctlib.get_case_path(PATH, config['warmup_case'])
            os.makedirs(os.path.join(case_path, 'inflow_data'))
            os.system('cp ' + os.path.join(warmup_path, 'init_data/*') + ' ' +
                      os.path.join(case_path, 'src', 'input'))
            os.system('cp -r ' + os.path.join(warmup_path, 'init_data') + ' ' +
                      os.path.join(case_path))

    if config['sim_flag'] == 3:

        prec_path = fctlib.get_case_path(PATH, config['prec_case'])
        pwd = os.getcwd()
        if config['resub_flag'] == 0:
            os.system('cp ' + os.path.join(prec_path, 'init_data/*') + ' ' +
                      os.path.join(case_path, 'src', 'input'))
        # os.system('cp -r ' + os.path.join(prec_path, 'inflow_data') + ' ' + os.path.join(case_path))
        os.system('ln -snf ' + os.path.join(pwd, prec_path, 'inflow_data') +
                  ' ' + os.path.join(pwd, case_path, 'inflow_data'))

    if config['sim_flag'] == 4:

        prec_path = fctlib.get_case_path(PATH, config['prec_case'])
        inflow_path = os.path.join(prec_path, 'inflow_data_bis')
        pwd = os.getcwd()
        if config['resub_flag'] == 0:
            os.makedirs(os.path.join(case_path, 'inflow_data'))
            os.system('cp ' + os.path.join(prec_path, 'init_data/*') + ' ' +
                      os.path.join(case_path, 'src', 'input'))
        if not os.path.isdir(inflow_path):
            os.mkdir(inflow_path)
            for i in range(config['job_np']):
                post_prec(prec_path, config, 'u', i)
                post_prec(prec_path, config, 'v', i)
                post_prec(prec_path, config, 'w', i)
        os.system('ln -snf ' + os.path.join(pwd, inflow_path, '*') + ' ' +
                  os.path.join(pwd, case_path, 'inflow_data'))

    if config['turb_flag'] == 1:
        os.system('cp ' + os.path.join(case_path, 'input/*.dat') + ' ' +
                  os.path.join(case_path, 'src', 'input'))

    # write zo and zs. Must be here to allow for changes beween prec/main

    zo = compute_zo(config)
    zo.tofile(os.path.join(case_path, 'src', 'input', 'zo.bin'))

    print('----------------------------------')
    print(' SPACE PARAMS:')
    print(' nx x ny x nz    : ' + str(config['nx']) + ' x ' +
          str(config['ny']) + ' x ' + str(config['nz']))
    print(' z_i x l_z x l_r : ' + str(config['z_i']) + ' x ' +
          str(config['l_z']) + ' x ' + str(config['l_r']))
    print(' lx x ly x lz    : ' + str(config['lx']) + ' x ' +
          str(config['ly']) + ' x ' + str(config['lz']))
    print(' dx x dy x dz    : ' + str(config['dx']) + ' x ' +
          str(config['dy']) + ' x ' + str(config['dz']))
    print('----------------------------------')
    print(' TIME PARAMS:')
    print(' nsteps : ' + str(config['nsteps']))
    print(' dt     : ' + str(config['dt']))
    print(' t_tot  : ' + str(config['t_tot']))
    print(' dtr    : ' + str(config['dtr']))
    print('----------------------------------')