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
Beispiel #2
0
    def test_vtk_parallel_reader_3D(self):
        filename = 'HotKarman3D_template_sizer_1_nu_0.03_k_0.003_VTK_P00_00600000.pvti'
        wd = os.getcwd()
        # wd = os.path.dirname(wd)  # go level up

        if 'circleci' in wd:
            wd = os.path.join(wd, 'tests')
        filepath = os.path.join(wd, 'sample_data_for_vtk_reader',
                                '3D_multiGPU', filename)

        vti_reader = VTIFile(filepath, parallel=True)
        T_num = vti_reader.get("T")
        [ux_num, uy_num, uz_num] = vti_reader.get("U", is_vector=True)

        expected_hashes = [
            '5849cd96453a0452c80e37d582fca19f',
            '20f827ffad4ad10aa50839797316a0eb',
            '3533e058238c125fcf00592c2269e3d4',
            '25436c02e5c33da5c8da71338248c423'
        ]

        zzs = [T_num, ux_num, uy_num, uz_num]

        hasher = hashlib.md5()
        for expected_hash, zz in zip(expected_hashes, zzs):
            hasher.update(zz.copy(order='C'))
            hash = hasher.hexdigest()
            assert expected_hash == hash
def get_t_mse(folder):
    n = len(gauges)
    T_mse = np.zeros(n)
    T_L2 = np.zeros(n)

    for g in range(n):
        filepath_vtk = os.path.join(
            folder, f'k_outer_{k_outer}_size_{lattices[g]}lu',
            f'k_outer_{k_outer}_size_{lattices[g]}lu_VTK_P00_00500000.vti')
        vti_reader = VTIFile(filepath_vtk)

        T_num = vti_reader.get("T")
        ySIZE, xSIZE = T_num.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
        if 'abb_scheme' in filepath_vtk:
            r0 -= abb_correction
            r2 += abb_correction

        r1 = gauges[g] * (20 / 2)  # interface between layers
        x0 = lattices[g] / 2  # center of the pipe
        y0 = lattices[g] / 2

        # ----------------------- compute anal solution ---------------------------

        pwp = PipeWithinPipeDirichlet(r0, r1, r2, k_inner, k_outer, T0=0, T2=1)

        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)

                # if r < r0 or r > r2:
                #     T_anal[i][j] = 0
                #     T_num[i][j] = 0

        # 2d clip
        T_anal = T_anal[:, int(xSIZE / 2)]
        T_num = T_num[:, int(xSIZE / 2)]

        T_L2[g] = np.sqrt(
            np.sum((T_anal - T_num) * (T_anal - T_num)) /
            np.sum(T_anal * T_anal))  # Eq. 4.57

        T_mse[g] = np.sum((T_anal - T_num) * (T_anal - T_num)) / len(T_anal)
        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
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
Beispiel #5
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 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 get_t_mse(folder, time, x_size):
    T_mse = np.zeros([len(time), len(x_size)])
    for i in range(len(x_size)):
        for t in range(len(time)):
            # read data

            filename_vtk = f'laplace_template_nx_{x_size[i]}_ny_{x_size[i] + 2}_VTK_P00_{time[t]}.vti'
            filepath_vtk = os.path.join(main_folder, folder, filename_vtk)
            vti_reader = VTIFile(filepath_vtk)
            T_num = vti_reader.get("T")
            U = vti_reader.get("U", is_vector=True)

            filename_txt = f'laplace_template_nx_{x_size[i]}_ny_{x_size[i] + 2}_TXT_P00_{time[t]}_T.txt'
            filepath_txt = os.path.join(main_folder, folder, filename_txt)
            T_num_txt = pd.read_csv(filepath_txt, delimiter=" ")

            # clip data
            T_num = np.delete(
                T_num, 0,
                axis=0)  # delete first row - extra bc (stops periodicity)

            n_rows, n_columns = T_num.shape
            T_num = np.delete(
                T_num, (n_rows - 1),
                axis=0)  # delete last row - extra bc (stops periodicity)

            # -------- analytical solution ---------------
            ySIZE, xSIZE = T_num.shape
            step = 1
            my_fun = -4 * x * (x - xSIZE) / (xSIZE * xSIZE)
            n_fourier = 25
            anal_input = InputForLaplace2DAnalytical(xSIZE, ySIZE, step,
                                                     my_fun, n_fourier)

            dump_fname = os.path.join(main_folder, f'n_fourier{n_fourier}',
                                      f'T_anal_x{xSIZE}y{ySIZE}.npy')

            if os.path.isfile(dump_fname):
                print(f'{dump_fname} found, loading results from disc')
                T_anal = np.load(dump_fname)
                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)
            else:
                print(f'{dump_fname} not found, starting calculations')
                xx, yy, T_anal = analytical_laplace_2d(anal_input)
                np.save(dump_fname, T_anal)

            T_mse[t, i] = np.sum(
                (T_anal - T_num) * (T_anal - T_num)) / len(T_anal)
            # print(f"T_mse={T_mse} for grid {x_size[i]} x {x_size[i]} [lu]")

    return T_mse
Beispiel #8
0
def read_data_from_LBM(case_folder, iteration_of_interest):
    # iteration_of_interest = find_oldest_iteration(case_folder)
    filename_vtk = get_vti_from_iteration(case_folder, iteration_of_interest, extension='.vti')
    filepath_vtk = os.path.join(case_folder, filename_vtk)
    vti_reader = VTIFile(filepath_vtk, parallel=False)
    fs_num = vti_reader.get("FractionSuspected")
    # [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]

    fs_num_slice = fs_num[int(fs_num.shape[0]/2), :]
    # y = np.linspace(start=0, stop=1, num=ny, endpoint=False)
    return fs_num_slice
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
Beispiel #10
0
    def test_vtk_reader_2D(self):
        # real_path = os.path.realpath(__file__)
        # dir_path = os.path.dirname(real_path)
        # print(f'dir_path{dir_path}')

        wd = os.getcwd()
        # print(f"wd{wd}")
        # wd = os.path.dirname(wd)  # go level up

        filename = 'laplace_benchmark_d2q9_VTK_P00_00050010.vti'
        if 'circleci' in wd:
            wd = os.path.join(wd, 'tests')

        filepath = os.path.join(wd, 'sample_data_for_vtk_reader', filename)

        print(f"filepath{filepath}")
        vti_reader = VTIFile(filepath)

        T = vti_reader.get("T")
        U = vti_reader.get("U", is_vector=True)

        # convert to pandas format
        data = T
        pdT = pd.DataFrame(
            data=data[1:, 1:],  # values
            index=data[1:, 0],  # 1st column as index
            columns=data[0, 1:])  # 1st row as the column names

        pdT2 = pd.DataFrame(data)

        assert T.size > 0
        assert U[0].size > 0
        assert U[1].size > 0
        assert U[2].size > 0
        assert pdT.size > 0
        assert pdT2.size > 0
        filepath = os.path.join(
            wd, 'sample_data_for_vtk_reader',
            'laplace_benchmark_d2q9_TXT_P00_00050010_T.txt')
        T_read_by_pd = pd.read_csv(filepath, delimiter=" ", header=None)
        np.testing.assert_allclose(pdT2 - T_read_by_pd,
                                   0,
                                   rtol=1e-14,
                                   atol=1e-14)
Beispiel #11
0
        def read_Tnum_data(nx):
            # --------------- prepare paths ---------------
            filename_vtk = f'laplace_template_nx_{nx}_ny_{nx + 2}_VTK_P00_00250000.vti'
            filepath_vtk = os.path.join(folder, filename_vtk)
            vti_reader = VTIFile(filepath_vtk)

            # filename_txt = f'laplace_template_nx_{nx}_ny_{nx + 2}_TXT_P00_00250000_T.txt'
            # filepath_txt = os.path.join(folder, filename_txt)
            # T_num_txt = pd.read_csv(filepath_txt, delimiter=" ",  header=None)

            T_num = vti_reader.get("T")
            # U = vti_reader.get("U", vector=True)

            # --------------- read vti ---------------
            T_num = np.delete(
                T_num, 0,
                axis=0)  # delete first row - extra bc (stops periodicity)
            n_rows, n_columns = T_num.shape
            T_num = np.delete(
                T_num, (n_rows - 1),
                axis=0)  # delete last row - extra bc (stops periodicity)

            return T_num
Beispiel #12
0
def read_data_from_LBM_for_cntr_plot(size):
    # filename_vtk = f'HotKarman3D_template_sizer_{sizer}_nu_0.03_k_0.003_VTK_P00_01000000.pvti'
    filename_vtk = f'HotKarman3D_template_sizer_{size}_Re{Re}_Pr{Pr}_VTK_P00_00980000.pvti'
    filepath_pvti = os.path.join(main_folder,
                                 f'keepU_sizer_{size}_Re{Re}_Pr{Pr}',
                                 filename_vtk)

    vti_reader = VTIFile(filepath_pvti, parallel=True)

    T_num = vti_reader.get("T")
    [ux_num, uy_num, uz_num] = vti_reader.get("U", is_vector=True)
    ny, nx, nz = T_num.shape

    ux_num_slice = ux_num[:, :, 1]
    T_num_slice = T_num[:, :, 1]

    x_grid = np.linspace(start=0, stop=nx, num=nx, endpoint=False)
    y_grid = np.linspace(start=0, stop=ny, num=ny, endpoint=False)
    z_grid = np.linspace(start=0, stop=nz, num=nz, endpoint=False)

    xx, yy = np.meshgrid(x_grid, y_grid)

    return T_num_slice, ux_num_slice, xx, yy
Beispiel #13
0
from DataIO.VTIFile import VTIFile
import os
import pandas as pd

wd = os.getcwd()
wd = os.path.dirname(wd)  # go level up

filename = 'laplace_benchmark_d2q9_VTK_P00_00050010.vti'
filepath = os.path.join(wd, 'tests', 'sample_data_for_vtk_reader', filename)
vti_reader = VTIFile(filepath)

T = vti_reader.get("T")
(Ux, Uy, Uz) = vti_reader.get("U", is_vector=True)

# convert to pandas format
data = T
pdT = pd.DataFrame(
    data=data[1:, 1:],  # values
    index=data[1:, 0],  # 1st column as index
    columns=data[0, 1:])  # 1st row as the column names

pdT2 = pd.DataFrame(data)

print('bye')
Beispiel #14
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
gauge = 8
# bc_scheme = 'abb_scheme'
bc_scheme = 'eq_scheme'
home = pwd.getpwuid(os.getuid()).pw_dir

# filename_vtk = f'ruraWrurze_cht_VTK_P00_00500000.vti'
# main_folder = os.path.join(home, 'DATA_FOR_PLOTS', 'ruraWrurzeBenchmark_const_k', bc_scheme, f'ruraWrurze_cht_{int(gauge * lattice_size)}lu')

k_outer = 0.01  # 0.001
filename_vtk = f'k_outer_{k_outer}_size_{int(gauge * lattice_size)}lu_VTK_P00_00500000.vti'
main_folder = os.path.join(
    home, 'DATA_FOR_PLOTS', 'batch_ruraWrurze_variable_k', bc_scheme,
    f'k_outer_{k_outer}_size_{int(gauge * lattice_size)}lu')

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

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

ySIZE, xSIZE = T_num.shape
assert ySIZE == xSIZE == int(gauge * lattice_size)

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

# abb_correction = 0.5
# if bc_scheme =='abb_scheme':
#     r0 += abb_correction
#     r2 -= abb_correction
wd = os.path.dirname(wd)  # go level up

lattice_size = 32
filename_vtk = f'laplace_template_nx_{lattice_size}_ny_{lattice_size + 2}_VTK_P00_00250000.vti'

home = pwd.getpwuid(os.getuid()).pw_dir
main_folder = os.path.join(home, 'DATA_FOR_PLOTS', 'LaplaceBenchmark')
folder = os.path.join(main_folder, 'eq_sin_scheme_laplace_template')
# folder = os.path.join(main_folder, 'eq_x2_scheme_laplace_template')

# folder = os.path.join(main_folder, 'abb_sin_scheme_laplace_template')
# folder = os.path.join(main_folder, 'abb_x2_laplace_template_corr05')

filepath_vtk = os.path.join(folder, filename_vtk)

vti_reader = VTIFile(filepath_vtk)
T_num = vti_reader.get("T")
U = vti_reader.get("U", is_vector=True)

# ---------------------- clip buffer bc  --------------------
T_num = np.delete(
    T_num, 0,
    axis=0)  # obligatory delete first row - wall bc (stops periodicity)

n_rows, n_columns = T_num.shape
T_num = np.delete(T_num, (n_rows - 1),
                  axis=0)  # delete last row - extra heater bc

# ---------------------- calculate solution --------------------
xx, yy, T_anal = prepare_anal_data_new(*T_num.shape,
                                       folder,
Beispiel #17
0
 def test_vtk_reader_raise_file_not_found(self):
     filename = 'ghost_file.vti'
     with self.assertRaises(FileNotFoundError) as context:
         vti_reader = VTIFile(filename)
import matplotlib.pyplot as plt
import numpy as np
import os
from DataIO.VTIFile import VTIFile


wd = os.getcwd()
wd = os.path.dirname(wd)  # go level up

filename = 'HotKarman3D_template_sizer_1_nu_0.03_k_0.003_VTK_P00_00600000.pvti'
filepath = os.path.join(wd, 'tests', 'sample_data_for_vtk_reader', '3D_multiGPU', filename)


vti_reader = VTIFile(filepath, parallel=True)
T_num = vti_reader.get("T")

ny, nx, nz = T_num.shape

# U = vti_reader.get("U", vector=True)

# convert to pandas format
# data = T_num
# pdT = pd.DataFrame(data=data[1:, 1:],  # values
#                    index=data[1:, 0],  # 1st column as index
#                    columns=data[0, 1:])  # 1st row as the column names
#
# pdT2 = pd.DataFrame(data)


print("---------- PLOTTING -------------")
x_grid = np.linspace(start=0, stop=nx, num=nx, endpoint=False)
Beispiel #19
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
Beispiel #20
0
# readme:
# sizer 1 = LB mesh: 1000x150x3 -- sample 150 y points from toolbox
# sizer 2 = LB mesh: 2000x300x6 -- sample 300 y points from toolbox
# sizer 4 = LB mesh: 4000x600x12 -- sample 600 y points from toolbox

# filename_vtk = f'HotKarman3D_template_sizer_{sizer}_nu_0.03_k_0.003_VTK_P00_00600000.pvti'
# filepath_pvti = os.path.join(main_folder, f'lbm_template_sizer_{sizer}_nu_0.03_k_0.003', filename_vtk)

Re = 10
Pr = 10
# filename_vtk = f'HotKarman3D_template_sizer_{sizer}_nu_0.03_k_0.003_VTK_P00_01000000.pvti'
filename_vtk = f'HotKarman3D_template_sizer_{sizer}_Re{Re}_Pr{Pr}_VTK_P00_00980000.pvti'
filepath_pvti = os.path.join(main_folder, f'keepU_sizer_{sizer}_Re{Re}_Pr{Pr}',
                             filename_vtk)

vti_reader = VTIFile(filepath_pvti, parallel=True)

T_num = vti_reader.get("T")
[ux_num, uy_num, uz_num] = vti_reader.get("U", is_vector=True)
ny, nx, nz = T_num.shape

ux_num_slice = ux_num[:, :, 1]
T_num_slice = T_num[:, :, 1]

# Read data from toolbox
filepath_csv = os.path.join(
    main_folder, 'from_toolbox',
    f'Temperature_{int(150*sizer)}_clmax_{clmax}_Re_{Re}_Pr_{Pr}.csv')
T_toolbox = np.loadtxt(filepath_csv, delimiter=',', skiprows=1)

filepath_csv = os.path.join(
    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