def read_data_from_LBM(case_folder):
    if solver == 'walberla':
        oldest = find_oldest_iteration(case_folder,
                                       extension='.vti')  # walberla
        filename_vtk = get_vti_from_iteration(
            case_folder, oldest, extension='.vti',
            prefix='simulation_step_')  # walberla
        filepath_vtk = os.path.join(case_folder, filename_vtk)
        vti_reader = VTIFile(filepath_vtk, parallel=False)  # walberla
    elif solver == 'TCLB':
        oldest = find_oldest_iteration(case_folder)  # TCLB
        filename_vtk = get_vti_from_iteration(case_folder,
                                              oldest,
                                              extension='.pvti')  # TCLB
        filepath_vtk = os.path.join(case_folder, filename_vtk)
        vti_reader = VTIFile(filepath_vtk, parallel=True)  # TCLB
    else:
        raise Exception("Choose solver [\'TCLB\' or \'walberla\'] ")

    T_num = vti_reader.get("T")
    T_num_slice = T_num[:, :, 1]
    #[ux_num, uy_num, uz_num] = vti_reader.get("U", is_vector=True)
    # ny, nx, nz = T_num.shape
    # uz_num_slice = uz_num[:, :, 1]
    # y = np.linspace(start=0, stop=1, num=ny, endpoint=False)
    return T_num_slice
def read_ux(folder):
    folder = strip_folder_name(folder)
    case_folder = os.path.join(main_folder, folder)
    oldest = find_oldest_iteration(case_folder)
    filename_vtk = get_vti_from_iteration(case_folder, oldest)
    filepath_vtk = os.path.join(case_folder, filename_vtk)
    vti_reader = VTIFile(filepath_vtk)

    (u_num_x, _, _) = vti_reader.get("U", is_vector=True)
    ux_slice = u_num_x[:, 1, 1]
    return ux_slice
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def read_data_from_LBM(case_folder):
    oldest = find_oldest_iteration(case_folder)
    filename_vtk = get_vti_from_iteration(case_folder, oldest, extension='.pvti')
    filepath_vtk = os.path.join(case_folder, filename_vtk)
    vti_reader = VTIFile(filepath_vtk, parallel=True)
    # match = re.search(r'Pr_?(\d{1,4})_', file, re.IGNORECASE)
    # Pr = float(match.group(1))
    T_num = vti_reader.get("T")

    name_for_plot = re.sub(r"VTK_P00_", '', filename_vtk)
    name_for_plot = re.sub(r".pvti", '', filename_vtk)
    return T_num, name_for_plot
def read_data_from_lbm(_case_folder):
    oldest = find_oldest_iteration(_case_folder)
    filename_vtk = get_vti_from_iteration(_case_folder, oldest, extension='.pvti')
    filepath_vtk = os.path.join(_case_folder, filename_vtk)
    vti_reader = VTIFile(filepath_vtk, parallel=True)
    T_num = vti_reader.get("T")
    T_num_slice = T_num[:, :, 1]

    # [ux_num, uy_num, uz_num] = vti_reader.get("U", is_vector=True)
    # ny, nx, nz = T_num.shape
    # uz_num_slice = uz_num[:, :, 1]
    # y = np.linspace(start=0, stop=1, num=ny, endpoint=False)
    return T_num_slice
Ejemplo n.º 6
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
Ejemplo n.º 7
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
    def get_t_err(folder, collision_type):
        n = len(gauges)
        T_mse = np.zeros(n)
        T_L2 = np.zeros(n)

        for g in range(n):
            main_folder = os.path.join(
                folder, 'DATA_FOR_PLOTS', 'batch_ruraWrurze_NeumannBC',
                f'{collision_type}_k_{k}_size_{lattices[g]}lu')

            oldest = find_oldest_iteration(main_folder)
            filename_vtk = f'{collision_type}_k_{k}_size_{lattices[g]}lu_VTK_P00_{oldest}.vti'

            filepath_vtk = os.path.join(main_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 == lattices[g]
            assert xSIZE % 1 == 0

            r0 = gauges[g] * (8 / 2)  # inner radius
            r2 = gauges[g] * (30 / 2)  # outer radius

            # abb_correction = 0.5
            # r0 += abb_correction

            x0 = lattices[g] / 2  # center of the pipe
            y0 = lattices[g] / 2

            # ----------------------- compute anal solution ---------------------------
            pwp = PipeWithinPipeNeumann(r0, r2, J0 / float(k), T2)

            x_grid = np.linspace(0, xSIZE, xSIZE, endpoint=False) + 0.5
            y_grid = np.linspace(0, ySIZE, ySIZE, endpoint=False) + 0.5
            xx, yy = np.meshgrid(x_grid, y_grid)
            T_anal = np.zeros((ySIZE, xSIZE))

            for i in range(ySIZE):
                # print(f"=== Doing i/ny: {i}/{ny}  ===")
                for j in range(xSIZE):
                    # print(f"Doing i/ny: {i}/{ny} \t j/nx: {j}/{nx}")
                    r = pwp.get_r_from_xy(xx[i][j], yy[i][j], x0, y0)
                    T_anal[i][j] = pwp.get_temperature_r(r)

            # nan_mask = np.argwhere(np.isnan(T_anal))
            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]

            T_mse[g] = np.sum(
                (T_anal_masked - T_num_slice_masked) *
                (T_anal_masked - T_num_slice_masked)) / len(T_anal_masked)
            T_L2[g] = np.sqrt(
                np.sum((T_anal_masked - T_num_slice_masked) *
                       (T_anal_masked - T_num_slice_masked)) /
                np.sum(T_anal_masked * T_anal_masked))  # Eq. 4.57

            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]")
        return T_L2
Ejemplo n.º 9
0
X0 = Matrix([lattice_size/2, lattice_size/2])
ux = 0
# ux_str = str(Ux).rstrip('0')
Sigma02 = 100
conductivities = ['0.01', '0.001', '1e-04', '1e-05']

home = pwd.getpwuid(os.getuid()).pw_dir
main_folder = os.path.join(home, 'DATA_FOR_PLOTS', 'batch_GaussianHill_advection')

shall_clip_to_2D = True

for CollisionType in ["CM", "CM_HIGHER"]:
    for k in conductivities:
        case_folder = os.path.join(main_folder, f"{CollisionType}_ux_{ux}_k_{k}_sigma_{Sigma02}_size_{lattice_size}lu")

        oldest = find_oldest_iteration(case_folder)
        filename_vtk = f'{CollisionType}_ux_{ux}_k_{k}_sigma_{Sigma02}_size_{lattice_size}lu_VTK_P00_{oldest}.vti'
        filepath_vtk = os.path.join(case_folder, filename_vtk)
        vti_reader = VTIFile(filepath_vtk)
        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)
# -------- numerical solution ---------------
wd = os.getcwd()
wd = os.path.dirname(wd)  # go level up

reference_lattice_size = 32
gauge = 4
lattice_size = int(gauge * reference_lattice_size)

CollisionType = 'CM_HIGHER'
k = f"0.1"
home = pwd.getpwuid(os.getuid()).pw_dir
# k_0.1666666_size_128lu


main_folder = os.path.join(home, 'DATA_FOR_PLOTS', 'batch_ruraWrurze_NeumannBC', f'{CollisionType}_k_{k}_size_{lattice_size}lu')
oldest = find_oldest_iteration(main_folder)
filename_vtk = f'{CollisionType}_k_{k}_size_{int(gauge * reference_lattice_size)}lu_VTK_P00_{oldest}.vti'

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

# ----------------------- calc dimensions -----------------------

ySIZE, xSIZE = T_num_slice.shape
assert ySIZE == xSIZE == int(gauge * reference_lattice_size)

r0 = gauge * (8 / 2)  # inner radius
r2 = gauge * (30 / 2)  # outer radius