Exemplo n.º 1
0
        def get_t_err(main_folder, collision_type):
            n = len(conductivities)
            T_mse = np.zeros(n)
            T_L2 = np.zeros(n)

            time_spot = None

            for g in range(n):
                folder = os.path.join(
                    main_folder,
                    f"{collision_type}_ux_{ux}_k_{conductivities[g]}_sigma_{Sigma02}_size_{lattice_size}lu"
                )

                oldest = find_oldest_iteration(folder)
                time_spot = int(oldest)
                filename_vtk = f'{collision_type}_ux_{ux}_k_{conductivities[g]}_sigma_{Sigma02}_size_{lattice_size}lu_VTK_P00_{oldest}.vti'

                filepath_vtk = os.path.join(folder, filename_vtk)
                vti_reader = VTIFile(filepath_vtk)
                T_num = vti_reader.get("T")
                T_num_slice = T_num[:, :, 1]

                ySIZE, xSIZE = T_num_slice.shape
                assert ySIZE == xSIZE == lattice_size

                dump_file_path = os.path.join(
                    main_folder, f'dumps',
                    f'ux_{ux}_k_{conductivities[g]}_sigma_{Sigma02}_size_{lattice_size}_time_spot_{oldest}.npy'
                )

                gha = GaussianHillAnal(C0,
                                       X0,
                                       Sigma02,
                                       float(conductivities[g]),
                                       Matrix([0, 0]),
                                       D=2)
                xx, yy, T_anal = prepare_anal_data_ADE_Gaussion_Hill_2D(
                    gha,
                    ux,
                    oldest,
                    lattice_size,
                    lattice_size,
                    dump_file_path,
                    shall_recalculate_results=False)

                T_err_field = T_anal - T_num_slice
                T_L2[g] = calc_L2(T_anal, T_num_slice)
                T_mse[g] = calc_mse(T_anal, T_num_slice)

                # print(f"T_mse={T_mse[g]:.2e} for grid {xSIZE} x {xSIZE} [lu]")
                print(f"T_L2={T_L2[g]:.2e} for k = {conductivities[g]}")

            return T_L2, time_spot
def calculate_error_norms(_case_folder):
    T_num_slice = read_data_from_LBM(_case_folder)
    ny, nx = T_num_slice.shape

    r0 = eff_cyl_diam[d] / 2.  # inner radius
    r2 = eff_pipe_diam[d] / 2.  # outer radius
    r1 = (r0 + r2) / 2.  # interface between layers

    pwp = PipeWithinPipeDirichlet(r0,
                                  r1,
                                  r2,
                                  conductivities[k],
                                  conductivities[k],
                                  T0=11,
                                  T2=10)

    x_grid = np.linspace(0, nx, nx, endpoint=False) + 0.5
    y_grid = np.linspace(0, ny, ny, endpoint=False) + 0.5
    xx, yy = np.meshgrid(x_grid, y_grid)

    T_anal = np.zeros((ny, nx))
    r_anal = np.zeros((ny, nx))

    cuttoff_r2 = eff_pipe_diam[d] / 2. - 2
    cuttoff_r0 = eff_cyl_diam[d] / 2. + 2

    for i in range(ny):
        for j in range(nx):
            r = get_r_from_xy(xx[i][j], yy[i][j], x0, y0)
            r_anal[i, j] = r
            T_anal[i, j] = pwp.get_temperature_r(r)
            if r < cuttoff_r0 or r > cuttoff_r2:
                T_anal[i, j] = np.nan

    not_nan_mask = ~np.isnan(T_anal)
    T_anal_masked = T_anal[not_nan_mask]
    T_num_slice_masked = T_num_slice[not_nan_mask]
    r_anal_masked = r_anal[not_nan_mask]

    # cntr_plot(T_anal, T_num_slice, xx, yy, conductivities[k], eff_pipe_diam[d])

    # u_anal_masked = np.array([max(u_anal_masked)])
    # uz_num_slice_masked = np.array([max(uz_num_slice_masked)])
    mse = calc_mse(T_anal_masked, T_num_slice_masked)
    L2 = calc_L2(T_anal_masked, T_num_slice_masked)
    return mse, L2
Exemplo n.º 3
0
def calculate_error_norms(_case_folder):
    uz_num_slice = read_data_from_LBM(_case_folder)
    ny, nx = uz_num_slice.shape

    gx = calc_gx_in_pipe(uc, rho, kin_viscs[k], D=effdiams[d])
    poiseuilleAnal = OnePhasePoiseuilleAnalInPipe(gx=gx,
                                                  nu=kin_viscs[k],
                                                  D=effdiams[d])

    x_grid = np.linspace(0, nx, nx, endpoint=False) + 0.5
    y_grid = np.linspace(0, ny, ny, endpoint=False) + 0.5
    xx, yy = np.meshgrid(x_grid, y_grid)

    u_anal = np.zeros((ny, nx))
    r_anal = np.zeros((ny, nx))
    r_cutoff = effdiams[d] / 2. - 1

    for i in range(ny):
        for j in range(nx):
            r = get_r_from_xy(xx[i][j], yy[i][j], x0, y0)
            r_anal[i, j] = r
            u_anal[i, j] = poiseuilleAnal.get_u_profile(r)
            if r > r_cutoff:
                u_anal[i, j] = np.nan

    not_nan_mask = ~np.isnan(u_anal)
    u_anal_masked = u_anal[not_nan_mask]
    uz_num_slice_masked = uz_num_slice[not_nan_mask]
    r_anal_masked = r_anal[not_nan_mask]

    # cntr_plot(u_anal, uz_num_slice, kin_viscs[k], effdiams[d], nx, xx, yy)
    #
    # u_anal_masked = np.array([max(u_anal_masked)])
    # uz_num_slice_masked = np.array([max(uz_num_slice_masked)])
    mse = calc_mse(u_anal_masked, uz_num_slice_masked)
    L2 = calc_L2(u_anal_masked, uz_num_slice_masked)
    return mse, L2
Exemplo n.º 4
0
        def get_t_err(main_folder, collision_type):
            n = len(str_conductivities)
            T_mse = np.zeros(n)
            T_L2 = np.zeros(n)

            for g in range(n):
                folder = os.path.join(
                    main_folder,
                    f"{collision_type}_ux_{ux:.2e}_k_{str_conductivities[g]}_iterations_{iterations[g]}_sigma_{Sigma02}_size_{lattice_size}lu"
                )

                oldest = find_oldest_iteration(folder)
                filename_vtk = f'{collision_type}_ux_{ux:.2e}_k_{str_conductivities[g]}_iterations_{iterations[g]}_sigma_{Sigma02}_size_{lattice_size}lu_VTK_P00_{oldest}.vti'

                filepath_vtk = os.path.join(folder, filename_vtk)
                vti_reader = VTIFile(filepath_vtk)
                T_num = vti_reader.get("T")
                T_num_slice = T_num[:, :, 1]

                ySIZE, xSIZE = T_num_slice.shape
                assert ySIZE == xSIZE == lattice_size

                dump_file_path = os.path.join(
                    main_folder, f'dumps',
                    f'ux_{ux}_k_{str_conductivities[g]}_iterations_{iterations[g]}_sigma_{Sigma02}_size_{lattice_size}_time_SI_{time_SI}.npy'
                )

                assert lattice_size == domain_size_SI
                gha = GaussianHillAnal2D(C0, X0, Sigma02, conductivities[g])
                xx, yy, T_anal = prepare_anal_data_ADE_Gaussion_Hill(
                    gha,
                    ux,
                    iterations[g],
                    lattice_size,
                    lattice_size,
                    dump_file_path,
                    shall_recalculate_results=False,
                    reference_level=10.)
                T_err_field = T_anal - T_num_slice

                # alternatively
                # gha2 = GaussianHillAnal2D(C0, X0, Sigma02, conductivity_SI)
                # ux_SI = conductivity_SI/conductivities[g]*ux
                # xx, yy, T_anal2 = prepare_anal_data_ADE_Gaussion_Hill(gha2, ux_SI, time_SI, lattice_size, lattice_size,
                #                                                      dump_file_path,
                #                                                      shall_recalculate_results=True,
                #                                                      reference_level=10.)
                # T_err_field2 = T_anal2 - T_num_slice
                # xx = peel_the_skin_v2(xx, int(0.25 * lattice_size), int(0.75 * lattice_size))
                # yy = peel_the_skin_v2(yy, int(0.25 * lattice_size), int(0.75 * lattice_size))
                # T_anal = peel_the_skin_v2(T_anal, int(0.25*lattice_size), int(0.75*lattice_size))
                # T_num_slice = peel_the_skin_v2(T_num_slice, int(0.25 * lattice_size), int(0.75 * lattice_size))
                # T_err_field = T_anal - T_num_slice

                T_L2[g] = calc_L2(T_anal, T_num_slice)
                T_mse[g] = calc_mse(T_anal, T_num_slice)

                # print(f"T_mse={T_mse[g]:.2e} for grid {xSIZE} x {xSIZE} [lu]")
                print(
                    f"{collision_type} T_L2={T_L2[g]:.5e} for k = {conductivities[g]}"
                )

                print(
                    "------------------------------------ PLOT err field------------------------------------"
                )
                fig_name = f'{plot_dir}/acoustic_scaling_GaussianHill_{collision_type}_ux={ux:.0e}_k_{str_conductivities[g]}_iterations_{iterations[g]}_sig={Sigma02}_time_SI={time_SI}_lattice={lattice_size}[lu]_err_field_contour.png'
                plot_err_field(T_err_field, xx, yy, fig_name)

            return T_L2
        ySIZE = ux_ibb_num_slice.shape[0]
        y_grid = np.linspace(0, ySIZE, ySIZE, endpoint=False) + 0.5

        ux_ibb_num_slice = delete_unphysical_data_from_wall_nodes(ux_ibb_num_slice)
        ux_bb_num_slice = delete_unphysical_data_from_wall_nodes(ux_bb_num_slice)
        y_grid = delete_unphysical_data_from_wall_nodes(y_grid)

        # -------- anal solution ---------------
        y_anal = np.arange(q, effdiam, 1)
        # y_anal = np.concatenate(([0], y_anal, [effdiam])) # unphysical wall nodes
        gx = calc_gx_between_plates(uc, mu, mu, rho, rho, effdiam / 2)
        poiseuilleAnal = OnePhasePoiseuilleAnalBetweenPlates(gx=gx, nu=float(kin_visc), H=effdiam)
        u_anal = np.array([poiseuilleAnal.get_u_profile(y_anal[i]) for i in range(len(y_anal))])

        ux_ibb_mse[d] = calc_mse(u_anal, ux_ibb_num_slice)
        ux_ibb_L2[d] = calc_L2(u_anal, ux_ibb_num_slice)
        ux_bb_mse[d] = calc_mse(u_anal, ux_bb_num_slice)
        ux_bb_L2[d] = calc_L2(u_anal, ux_bb_num_slice)

        print(f"ux_mse={ux_ibb_mse[d]:.2e} for v{kin_visc}_q{q}_effdiam_{effdiam}")
        print(f"ux_L2={ux_ibb_L2[d]:.2e} for v{kin_visc}_q{q}_effdiam_{effdiam}")

    print("------------------------------------ Convergence  PLOT ------------------------------------")
    if not os.path.exists('plots'):
        os.makedirs('plots')
    fig_name = f'plots/grid_convergence_Poiseuille_anal_vs_lbm_nu{eat_dots_for_texmaker(kin_visc)}_q{eat_dots_for_texmaker(q)}.png'

    params = {'legend.fontsize': 'xx-large',
              'figure.figsize': (14, 8),
              'axes.labelsize': 'xx-large',
Exemplo n.º 6
0
def get_t_err(main_folder, collision_type):
    case_name = f'{collision_type}_ux_{ux:.2e}_k_{conductivity:.2e}_iterations_{iterations}_sigma2_{Sigma02}_size_{lattice_size}lu'
    folder = os.path.join(main_folder, case_name)

    oldest = find_oldest_iteration(folder)
    # filename_vtk = f'sample_VTK_P00_{oldest}.vti'
    filename_vtk = f'{case_name}_VTK_P00_{oldest}.vti'

    filepath_vtk = os.path.join(folder, filename_vtk)
    vti_reader = VTIFile(filepath_vtk)
    T_num = vti_reader.get("T")

    ySIZE, xSIZE, zSIZE = T_num.shape
    assert ySIZE == xSIZE == zSIZE == lattice_size

    # dump_file_path = os.path.join(main_folder, f'dumps', f'sample.npy')

    assert lattice_size == domain_size_SI
    dump_file_path = os.path.join(
        main_folder, f'dumps',
        f'ux_{ux:.2e}_k_{conductivity:.2e}_iterations_{iterations}_sigma2_{Sigma02}_size_{lattice_size}lu.npy'
    )
    gha = GaussianHillAnal(C0,
                           X0,
                           Sigma02,
                           conductivity,
                           Matrix([0, 0, 0]),
                           D=3.)
    xx, yy, zz, T_anal = prepare_anal_data_ADE_Gaussion_Hill_3D(
        gha,
        ux,
        iterations,
        lattice_size,
        lattice_size,
        lattice_size,
        dump_file_path,
        shall_recalculate_results=False,
        reference_level=reference_level)

    # T_num = T_num[:, :, 127]
    # T_anal = T_anal[:, :, 0]
    T_err_field = T_anal - T_num
    T_L2 = calc_L2_per_element(T_anal, T_num)
    T_L2_sum = calc_L2(T_anal, T_num)
    T_mse_sum = calc_mse(T_anal, T_num)
    # print(f"T_mse={T_mse[g]:.2e} for grid {xSIZE} x {xSIZE} [lu]")
    # print(f"{collision_type} T_L2={T_L2[g]:.5e} for k = {conductivities[g]}")

    print(
        "------------------------------------ PLOT err field------------------------------------"
    )
    # half_size = int(lattice_size/2)
    # T_slice = T_err_field[:half_size, :half_size, :half_size]
    plot_err_field_vedo(xx,
                        yy,
                        zz,
                        T_err_field,
                        fig_name=f'{case_name}_err_field.vti')
    plot_err_field_vedo(xx,
                        yy,
                        zz,
                        T_anal,
                        fig_name=f'{case_name}_anal_field.vti')
    plot_err_field_vedo(xx,
                        yy,
                        zz,
                        T_num,
                        fig_name=f'{case_name}_num_field.vti')
    # plot_err_field(xx, yy, zz, T_err_field, fig_name)
    return T_L2
Exemplo n.º 7
0
        T_num = vti_reader.get("T")
        T_num_slice = T_num[:, :, 1]

        ySIZE = lattice_size
        xSIZE = lattice_size

        dump_file_path = os.path.join(main_folder, f'dumps',
                                      f'ux_{ux}_k_{k}_sigma_{Sigma02}_size_{lattice_size}_time_spot_{oldest}.npy')

        gha = GaussianHillAnal(C0, X0, Sigma02, float(k), Matrix([0, 0]), D=2)
        xx, yy, T_anal = prepare_anal_data_ADE_Gaussion_Hill_2D(gha, ux, oldest, ySIZE, xSIZE, dump_file_path,
                                                                shall_recalculate_results=False)

        T_err_field = T_anal - T_num_slice
        T_L2 = calc_L2(T_anal, T_num_slice)
        T_mse = calc_mse(T_anal, T_num_slice)

        ###################################################################################################################

        plot_dir = 'ADE_GaussianHill_2and3D_anal_vs_lbm'
        if not os.path.exists(plot_dir):
            os.makedirs(plot_dir)

        if shall_clip_to_2D:
            T_anal = T_anal[int(ySIZE / 2), :]  # half X slice
            T_num_slice = T_num_slice[int(ySIZE / 2), :]  # half X slice
            T_err_field = T_err_field[int(ySIZE / 2), :]

            x_grid = xx[0, :]
            print("---------- PLOTTING -------------")
            fig_name = os.path.join(
cuttoff_y2 = Heff - 1
cuttoff_y0 = 0 + 1
for i in range(ny):
    for j in range(nx):
        T_anal[i, j] = hcbp.get_T_profile(yy[i][j])
        if i < cuttoff_y0 or i > cuttoff_y2:
            T_anal[i, j] = np.nan


not_nan_mask = ~np.isnan(T_anal)
T_anal_masked = T_anal[not_nan_mask]
T_num_slice_masked = T_num_slice[not_nan_mask]
yy_masked = yy[not_nan_mask]

T_mse = calc_mse(T_anal_masked, T_num_slice_masked)
T_L2 = calc_L2(T_anal_masked, T_num_slice_masked)

# cntr_plot(T_anal, T_num_slice, xx, yy, conductivity, Heff, title=case_folder)

# # 2D clipy_grid
# yy_masked = yy_masked[:,  int(nx / 2)]
T_anal_slice = T_anal[:,  int(nx / 2)]
T_num_slice = T_num_slice[:, int(nx / 2)]
not_nan_mask = ~np.isnan(T_anal_slice)
T_anal_masked = T_anal_slice[not_nan_mask]
T_num_slice_masked = T_num_slice[not_nan_mask]
y_masked = y_grid[not_nan_mask]

slice_plot(T_anal_masked, T_num_slice_masked, y_masked, title=f'{case_folder}_q{q}')
        cuttoff_y0 = 0 + 1
        for i in range(ny):
            for j in range(nx):
                y = yy[i][j]
                T_anal[i, j] = hcbp.get_T_profile(y)
                if i < cuttoff_y0 or i > cuttoff_y2:
                    T_anal[i, j] = np.nan

        not_nan_mask = ~np.isnan(T_anal)
        T_anal_masked = T_anal[not_nan_mask]
        T_iabb_num_slice_masked = T_iabb_num_slice[not_nan_mask]
        T_abb_num_slice_masked = T_abb_num_slice[not_nan_mask]
        T_eq_num_slice_masked = T_eq_num_slice[not_nan_mask]
        yy_masked = yy[not_nan_mask]

        T_iabb_mse[d] = calc_mse(T_anal_masked, T_iabb_num_slice_masked)
        T_iabb_L2[d] = calc_L2(T_anal_masked, T_iabb_num_slice_masked)
        T_abb_mse[d] = calc_mse(T_anal_masked, T_abb_num_slice_masked)
        T_abb_L2[d] = calc_L2(T_anal_masked, T_abb_num_slice_masked)
        T_eq_mse[d] = calc_mse(T_anal_masked, T_eq_num_slice_masked)
        T_eq_L2[d] = calc_L2(T_anal_masked, T_eq_num_slice_masked)

        # cntr_plot(T_anal, T_num_slice, xx, yy, conductivity, effdiam, title=iabb_case_folder)

        # # 2D clipy_grid
        # yy_masked = yy_masked[:,  int(nx / 2)]
        T_anal_slice = T_anal[:, int(nx / 2)]
        T_iabb_num_slice = T_iabb_num_slice[:, int(nx / 2)]
        not_nan_mask = ~np.isnan(T_anal_slice)
        T_anal_masked = T_anal_slice[not_nan_mask]
        T_iabb_num_slice_masked = T_iabb_num_slice[not_nan_mask]
for i in range(ny):
    for j in range(nx):
        r = get_r_from_xy(xx[i][j], yy[i][j], x0, y0)
        r_anal[i, j] = r
        u_anal[i, j] = poiseuilleAnal.get_u_profile(r)
        if r > cuttoff:
            u_anal[i, j] = np.nan


not_nan_mask = ~np.isnan(u_anal)
u_anal_masked = u_anal[not_nan_mask]
uz_num_slice_masked = uz_num_slice[not_nan_mask]
r_anal_masked = r_anal[not_nan_mask]

uz_mse = calc_mse(u_anal_masked, uz_num_slice_masked)
uz_L2 = calc_L2(u_anal_masked, uz_num_slice_masked)

# print(f"T_mse={T_mse[g]:.2e} for grid {xSIZE} x {xSIZE} [lu]")
# print(f"T_L2={T_L2[g]:.2e} for grid {xSIZE} x {xSIZE} [lu]")


cntr_plot(u_anal, uz_num_slice, kin_visc, effdiam, nx, xx, yy)
# # 2D clip
# r_anal = r_anal[:, 63]
# u_anal = u_anal[:, 63]
# uz_num_slice = uz_num_slice[:, int(nx / 2)]
# slice_plot(u_anal, uz_num_slice, kin_visc, effdiam, r_anal)

print('bye')