Ejemplo n.º 1
0
def transport_equation_plot():
    '''Check the transport equation integrator'''

    w = 5
    tend = 5
    dx = 0.1
    length = 100
    phi = 1
    dt = 0.001
    lab = Column(length, dx, tend, dt, w)
    D = 5
    lab.add_species(phi,
                    'O2',
                    D,
                    0,
                    bc_top_value=1,
                    bc_top_type='dirichlet',
                    bc_bot_value=0,
                    bc_bot_type='dirichlet')
    lab.solve()
    x = np.linspace(0, lab.length, lab.length / lab.dx + 1)
    sol = 1 / 2 * (special.erfc(
        (x - lab.w * lab.tend) / 2 / np.sqrt(D * lab.tend)) +
                   np.exp(lab.w * x / D) * special.erfc(
                       (x + lab.w * lab.tend) / 2 / np.sqrt(D * lab.tend)))

    plt.figure()
    plt.plot(x, sol, 'k', label='Analytical solution')
    plt.scatter(lab.x[::10],
                lab.species['O2'].concentration[:, -1][::10],
                marker='x',
                label='Numerical')
    plt.xlim([x[0], x[-1]])
    ax = plt.gca()
    ax.ticklabel_format(useOffset=False)
    ax.grid(linestyle='-', linewidth=0.2)
    plt.legend()
    plt.tight_layout()
    plt.show()
Ejemplo n.º 2
0
def fun(k0):
    w, k_w_in, k_w_out, k_g_in, k_g_out = k0
    print(*k0)
    # try:
        ftc1 = Column(L, dx, tend, dt)

        ftc1.add_species(
            theta=((phi_g**(10 / 3)) / (phi**2)),
            name='SF6g',
            D=D_SF6g,
            init_C=0,
            bc_top=0,
            bc_top_type='constant',
            bc_bot=0,
            bc_bot_type='constant',
            w=-0.00)    #-0.055
        ftc1.add_species(
            theta=((phi_w**(10 / 3)) / (phi**2)),
            name='SF6w',
            D=D_SF6w,
            init_C=0,
            bc_top=0,
            bc_top_type='constant',
            bc_bot=0,
            bc_bot_type='constant',
            w=w)

        # SF6mp stands for SF6 gas in micro pores, it is immobile and only collects SF6;
        ftc1.add_species(
            theta=phi_p,
            name='SF6mp',
            D=1e-18,
            init_C=0,
            bc_top=0,
            bc_top_type='flux',
            bc_bot=0,
            bc_bot_type='flux')

        #((phi_g**(10/3))/(phi**2))*
        #((phi_w**(10/3))/(phi**2))*

        # # Constants
        ftc1.constants['k_w_in'] = k_w_in    #from FTR w
        ftc1.constants['k_w_out'] = k_w_out
        #0.4

        ftc1.constants['k_g_in'] = k_g_in
        ftc1.constants['k_g_out'] = k_g_out

        ftc1.constants['phi_w'] = phi_w
        ftc1.constants['phi_g'] = phi_g
        ftc1.constants['phi_p'] = phi_p

        # # Rates of diffusion into pores and out
        ftc1.rates['R_w_in'] = 'k_w_in * SF6w'
        ftc1.rates['R_w_out'] = 'k_w_out * SF6mp'

        ftc1.rates['R_g_in'] = 'k_g_in * SF6w'
        ftc1.rates['R_g_out'] = 'k_g_out * SF6g'

        # # dcdt
        ftc1.dcdt['SF6w'] = '-R_g_in + R_g_out * phi_g - R_w_in + R_w_out * phi_p'
        ftc1.dcdt['SF6g'] = 'R_g_in / phi_g - R_g_out'
        ftc1.dcdt['SF6mp'] = 'R_w_in / phi_p - R_w_out'

        for i in range(0, len(ftc1.time)):
            if (ftc1.time[i] > F1T_frz - 16 and ftc1.time[i] < T1T_thw - 16) or (
                    ftc1.time[i] > F2T_frz - 16 and
                    ftc1.time[i] < T2T_thw - 16) or (ftc1.time[i] > F3T_frz - 16):
                ftc1.change_boundary_conditions(
                    'SF6g', i, bc_top=0, bc_top_type='flux')
                ftc1.change_boundary_conditions(
                    'SF6w', i, bc_top=0, bc_top_type='flux')
            else:
                ftc1.change_boundary_conditions(
                    'SF6g', i, bc_top=0, bc_top_type='constant')
                ftc1.change_boundary_conditions(
                    'SF6w', i, bc_top=0, bc_top_type='constant')
            if any([ftc1.time[i] == T_inj for T_inj in Ti]):
                SF6_add = np.zeros(x.size)
                SF6_add[x > 0] = 0
                SF6_add[x > 18 - (h_inj / 2)] = Ci[Ti == ftc1.time[i]]
                SF6_add[x > 18 + (h_inj / 2)] = 0
                new_profile = ftc1.profiles['SF6w'] + SF6_add    #
                ftc1.change_concentration_profile('SF6w', i, new_profile)

            ftc1.integrate_one_timestep(i)

        time_idxs = find_indexes_of_intersections(ftc1.time, Tm)

        zm = 9
        M1D9 = (
            ftc1.SF6w.concentration[ftc1.x == zm, time_idxs] * phi_w[ftc1.x == zm] +
            ftc1.SF6g.concentration[ftc1.x == zm, time_idxs] * phi_g[ftc1.x == zm]
        ) / (
            phi_w[ftc1.x == zm] + phi_g[ftc1.x == zm])

        zm = 21
        M1D21 = (
            ftc1.SF6w.concentration[ftc1.x == zm, time_idxs] * phi_w[ftc1.x == zm] +
            ftc1.SF6g.concentration[ftc1.x == zm, time_idxs] * phi_g[ftc1.x == zm]
        ) / (
            phi_w[ftc1.x == zm] + phi_g[ftc1.x == zm])

        zm = 33
        M1D33 = (
            ftc1.SF6w.concentration[ftc1.x == zm, time_idxs] * phi_w[ftc1.x == zm] +
            ftc1.SF6g.concentration[ftc1.x == zm, time_idxs] * phi_g[ftc1.x == zm]
        ) / (
            phi_w[ftc1.x == zm] + phi_g[ftc1.x == zm])

        fx_time_idxs = find_indexes_of_intersections(ftc1.time, Tm_nz)
        F1 = ftc1.estimate_flux_at_top('SF6g')[fx_time_idxs]
        F2 = ftc1.estimate_flux_at_top('SF6w')[fx_time_idxs]
        F3 = ftc1.estimate_flux_at_top('SF6mp')[fx_time_idxs]
        fx_mod = F1 + F2 + F3
        fx_meas = dC1h * Vh1 / SA / 2

        err = rmse(M1D9, C1D9[:len(M1D9) - len(C1D9)]) + rmse(
            M1D21, C1D21[:len(M1D21) - len(C1D21)]) + rmse(
                M1D33, C1D33[:len(M1D33) - len(C1D33)]) + 100 * rmse(
                    fx_mod, fx_meas[:len(fx_mod)])
def fun(k0):
    w, k_w_in, k_w_out, k_g_in, k_g_out, phi_1, phi_2, phi_3 = k0
    print(*k0)
    try:
        tend = periods[0]
        # tend = 457
        dt = 0.01
        dx = 0.2    ## cm
        L = 40    ## cm
        x = np.linspace(0, L, L / dx + 1)

        t = np.linspace(0, tend, round(tend / dt) + 1)
        #phi = 0.8
        Chs = np.zeros(t.shape)    #
        Fx = np.zeros(t.shape)

        phi = (phi_1 - 0.91) * np.exp(-x / 10) + 0.91
        phi_w = phi * (0.875 / 0.97)
        phi_g = phi * ((0.97 - 0.875) / 0.97)
        phi_p = 1 - phi


        ftc1 = Column(L, dx, tend, dt)

        ftc1.add_species(
            theta=((phi_g) / (1-np.log(phi))),
            element='SF6g',
            D=D_SF6g,
            init_C=0,
            bc_top=0,
            bc_top_type='constant',
            bc_bot=0,
            bc_bot_type='constant',
            w=-0.00)    #-0.055
        ftc1.add_species(
            theta=((phi_w) / (1-np.log(phi))),
            element='SF6w',
            D=D_SF6w,
            init_C=0,
            bc_top=0,
            bc_top_type='constant',
            bc_bot=0,
            bc_bot_type='constant',
            w=w)

        # SF6mp stands for SF6 gas in micro pores, it is immobile and only collects SF6;
        ftc1.add_species(
            theta=phi_p,
            element='SF6mp',
            D=1e-18,
            init_C=0,
            bc_top=0,
            bc_top_type='flux',
            bc_bot=0,
            bc_bot_type='flux')

        # # Constants
        ftc1.constants['k_w_in'] = k_w_in    #from FTR w
        ftc1.constants['k_w_out'] = k_w_out
        #0.4

        ftc1.constants['k_g_in'] = k_g_in
        ftc1.constants['k_g_out'] = k_g_out

        ftc1.constants['phi_w'] = phi_w
        ftc1.constants['phi_g'] = phi_g
        ftc1.constants['phi_p'] = phi_p

        # # Rates of diffusion into pores and out
        ftc1.rates['R_w_in'] = 'k_w_in * SF6w'
        ftc1.rates['R_w_out'] = 'k_w_out * SF6mp'
        # ftc1.rates['R_w_in'] = '0'
        # ftc1.rates['R_w_out'] = '0'

        ftc1.rates['R_g_in'] = 'k_g_in * SF6w'
        ftc1.rates['R_g_out'] = 'k_g_out * SF6g'

        # # dcdt
        ftc1.dcdt[
            'SF6w'] = '-R_g_in + R_g_out * phi_g - R_w_in + R_w_out * phi_p'
        ftc1.dcdt['SF6g'] = 'R_g_in / phi_g - R_g_out'
        ftc1.dcdt['SF6mp'] = 'R_w_in / phi_p - R_w_out'

        Fx = np.zeros(t.size)

        for i in range(0, len(ftc1.time)):
            if (ftc1.time[i] > periods[0] and ftc1.time[i] < periods[1]) or (
                    ftc1.time[i] > periods[2] and ftc1.time[i] < periods[3]) or (
                        ftc1.time[i] > periods[4] and ftc1.time[i] < periods[5]):
                ftc1.change_boundary_conditions(
                    'SF6g', i, bc_top=0, bc_top_type='flux')
                ftc1.change_boundary_conditions(
                    'SF6w', i, bc_top=0, bc_top_type='flux')
                Fx[i] = 0
            else:
                ftc1.change_boundary_conditions(
                    'SF6g', i, bc_top=0, bc_top_type='constant')
                ftc1.change_boundary_conditions(
                    'SF6w', i, bc_top=0, bc_top_type='constant')
                F1 = ftc1.estimate_flux_at_top('SF6g', i)
                F2 = ftc1.estimate_flux_at_top('SF6w', i)
                F3 = ftc1.estimate_flux_at_top('SF6mp', i)
                Fx[i] = F1[i] + F2[i] + F3[i]
            if any([ftc1.time[i] == T_inj for T_inj in Ti_1]):
                SF6_add = np.zeros(x.size)
                SF6_add[x > 0] = 0
                SF6_add[x > 18 - (h_inj / 2)] = Ci[Ti_1 == ftc1.time[i]]
                SF6_add[x > 18 + (h_inj / 2)] = 0
                new_profile = ftc1.profiles['SF6w'] + SF6_add    #
                ftc1.change_concentration_profile('SF6w', i, new_profile)

            ftc1.integrate_one_timestep(i)

        Ti_2 = Ti - periods[0]
        tend = periods[2] - periods[0]
        dt = 0.01
        dx = 0.2    ## cm
        L = 40    ## cm
        x = np.linspace(0, L, L / dx + 1)
        t = np.linspace(0, tend, round(tend / dt) + 1)
        #phi = 0.8
        Chs = np.zeros(t.shape)    #
        Fx = np.zeros(t.shape)
        phi = (phi_2 - 0.91) * np.exp(-x / 10) + 0.91
        phi_w = phi * (0.875 / 0.97)
        phi_g = phi * ((0.97 - 0.875) / 0.97)
        phi_p = 1 - phi

        ftc2 = Column(L, dx, tend, dt)

        ftc2.add_species(
            theta=((phi_g) / (1-np.log(phi))),
            element='SF6g',
            D=D_SF6g,
            init_C=ftc1.profiles.SF6g,
            bc_top=0,
            bc_top_type='constant',
            bc_bot=0,
            bc_bot_type='constant',
            w=-0.00)    #-0.055
        ftc2.add_species(
            theta=((phi_w) / (1-np.log(phi))),
            element='SF6w',
            D=D_SF6w,
            init_C=ftc1.profiles.SF6w,
            bc_top=0,
            bc_top_type='constant',
            bc_bot=0,
            bc_bot_type='constant',
            w=w)

        # SF6mp stands for SF6 gas in micro pores, it is immobile and only collects SF6;
        ftc2.add_species(
            theta=phi_p,
            element='SF6mp',
            D=1e-18,
            init_C=ftc1.profiles.SF6mp,
            bc_top=0,
            bc_top_type='flux',
            bc_bot=0,
            bc_bot_type='flux')

        # # Constants
        ftc2.constants['k_w_in'] = k_w_in    #from FTR w
        ftc2.constants['k_w_out'] = k_w_out
        #0.4

        ftc2.constants['k_g_in'] = k_g_in
        ftc2.constants['k_g_out'] = k_g_out

        ftc2.constants['phi_w'] = phi_w
        ftc2.constants['phi_g'] = phi_g
        ftc2.constants['phi_p'] = phi_p

        # # Rates of diffusion into pores and out
        ftc2.rates['R_w_in'] = 'k_w_in * SF6w'
        ftc2.rates['R_w_out'] = 'k_w_out * SF6mp'
        # ftc2.rates['R_w_in'] = '0'
        # ftc2.rates['R_w_out'] = '0'

        ftc2.rates['R_g_in'] = 'k_g_in * SF6w'
        ftc2.rates['R_g_out'] = 'k_g_out * SF6g'

        # # dcdt
        ftc2.dcdt[
            'SF6w'] = '-R_g_in + R_g_out * phi_g - R_w_in + R_w_out * phi_p'
        ftc2.dcdt['SF6g'] = 'R_g_in / phi_g - R_g_out'
        ftc2.dcdt['SF6mp'] = 'R_w_in / phi_p - R_w_out'

        for i in range(0, len(ftc2.time)):
            if (ftc2.time[i] + periods[0] > periods[0]
                    and ftc2.time[i] + periods[0] < periods[1]) or (
                        ftc2.time[i] + periods[0] > periods[2]
                        and ftc2.time[i] + periods[0] < periods[3]) or (
                            ftc2.time[i] + periods[0] > periods[4]
                            and ftc2.time[i] + periods[0] < periods[5]):
                ftc2.change_boundary_conditions(
                    'SF6g', i, bc_top=0, bc_top_type='flux')
                ftc2.change_boundary_conditions(
                    'SF6w', i, bc_top=0, bc_top_type='flux')
                Fx[i] = 0
            else:
                ftc2.change_boundary_conditions(
                    'SF6g', i, bc_top=0, bc_top_type='constant')
                ftc2.change_boundary_conditions(
                    'SF6w', i, bc_top=0, bc_top_type='constant')
                F1 = ftc2.estimate_flux_at_top('SF6g', i)
                F2 = ftc2.estimate_flux_at_top('SF6w', i)
                F3 = ftc2.estimate_flux_at_top('SF6mp', i)
                Fx[i] = F1[i] + F2[i] + F3[i]
            if any([ftc2.time[i] == T_inj for T_inj in Ti_2]):
                SF6_add = np.zeros(x.size)
                SF6_add[x > 0] = 0
                SF6_add[x > 18 - (h_inj / 2)] = Ci[Ti_2 == ftc2.time[i]]
                SF6_add[x > 18 + (h_inj / 2)] = 0
                new_profile = ftc2.profiles['SF6w'] + SF6_add    #
                ftc2.change_concentration_profile('SF6w', i, new_profile)

            ftc2.integrate_one_timestep(i)

        Ti_3 = Ti - periods[2]
        tend = periods[4] - periods[2]
        dt = 0.01
        dx = 0.2    ## cm
        L = 40    ## cm
        x = np.linspace(0, L, L / dx + 1)
        t = np.linspace(0, tend, round(tend / dt) + 1)
        #phi = 0.8
        Chs = np.zeros(t.shape)    #
        Fx = np.zeros(t.shape)
        phi = (phi_3 - 0.91) * np.exp(-x / 10) + 0.91
        phi_w = phi * (0.875 / 0.97)
        phi_g = phi * ((0.97 - 0.875) / 0.97)
        phi_p = 1 - phi

        ftc3 = Column(L, dx, tend, dt)

        ftc3.add_species(
            theta=((phi_g) / (1-np.log(phi))),
            element='SF6g',
            D=D_SF6g,
            init_C=ftc2.profiles.SF6g,
            bc_top=0,
            bc_top_type='constant',
            bc_bot=0,
            bc_bot_type='constant',
            w=-0.00)    #-0.055
        ftc3.add_species(
            theta=((phi_w) / (1-np.log(phi))),
            element='SF6w',
            D=D_SF6w,
            init_C=ftc2.profiles.SF6w,
            bc_top=0,
            bc_top_type='constant',
            bc_bot=0,
            bc_bot_type='constant',
            w=w)

        # SF6mp stands for SF6 gas in micro pores, it is immobile and only collects SF6;
        ftc3.add_species(
            theta=phi_p,
            element='SF6mp',
            D=1e-18,
            init_C=ftc2.profiles.SF6mp,
            bc_top=0,
            bc_top_type='flux',
            bc_bot=0,
            bc_bot_type='flux')

        # # Constants
        ftc3.constants['k_w_in'] = k_w_in    #from FTR w
        ftc3.constants['k_w_out'] = k_w_out
        #0.4

        ftc3.constants['k_g_in'] = k_g_in
        ftc3.constants['k_g_out'] = k_g_out

        ftc3.constants['phi_w'] = phi_w
        ftc3.constants['phi_g'] = phi_g
        ftc3.constants['phi_p'] = phi_p

        # # Rates of diffusion into pores and out
        ftc3.rates['R_w_in'] = 'k_w_in * SF6w'
        ftc3.rates['R_w_out'] = 'k_w_out * SF6mp'
        # ftc3.rates['R_w_in'] = '0'
        # ftc3.rates['R_w_out'] = '0'

        ftc3.rates['R_g_in'] = 'k_g_in * SF6w'
        ftc3.rates['R_g_out'] = 'k_g_out * SF6g'

        # # dcdt
        ftc3.dcdt[
            'SF6w'] = '-R_g_in + R_g_out * phi_g - R_w_in + R_w_out * phi_p'
        ftc3.dcdt['SF6g'] = 'R_g_in / phi_g - R_g_out'
        ftc3.dcdt['SF6mp'] = 'R_w_in / phi_p - R_w_out'

        for i in range(0, len(ftc3.time)):
            if (ftc3.time[i] + periods[2] > periods[0]
                    and ftc3.time[i] + periods[2] < periods[1]) or (
                        ftc3.time[i] + periods[2] > periods[2]
                        and ftc3.time[i] + periods[2] < periods[3]) or (
                            ftc3.time[i] + periods[2] > periods[4]
                            and ftc3.time[i] + periods[2] < periods[5]):
                ftc3.change_boundary_conditions(
                    'SF6g', i, bc_top=0, bc_top_type='flux')
                ftc3.change_boundary_conditions(
                    'SF6w', i, bc_top=0, bc_top_type='flux')
                Fx[i] = 0
            else:
                ftc3.change_boundary_conditions(
                    'SF6g', i, bc_top=0, bc_top_type='constant')
                ftc3.change_boundary_conditions(
                    'SF6w', i, bc_top=0, bc_top_type='constant')
                F1 = ftc3.estimate_flux_at_top('SF6g', i)
                F2 = ftc3.estimate_flux_at_top('SF6w', i)
                F3 = ftc3.estimate_flux_at_top('SF6mp', i)
                Fx[i] = F1[i] + F2[i] + F3[i]
            if any([ftc3.time[i] == T_inj for T_inj in Ti_3]):
                SF6_add = np.zeros(x.size)
                SF6_add[x > 0] = 0
                SF6_add[x > 18 - (h_inj / 2)] = Ci[Ti_3 == ftc3.time[i]]
                SF6_add[x > 18 + (h_inj / 2)] = 0
                new_profile = ftc3.profiles['SF6w'] + SF6_add    #
                ftc3.change_concentration_profile('SF6w', i, new_profile)

            ftc3.integrate_one_timestep(i)

        zm = 9
        M1D9 = (ftc1.SF6w.concentration[ftc1.x == zm, :] * phi_w[ftc1.x == zm] +
                ftc1.SF6g.concentration[ftc1.x == zm, :] * phi_g[ftc1.x == zm]) / (
                    phi_w[ftc1.x == zm] + phi_g[ftc1.x == zm])

        M2D9 = (ftc2.SF6w.concentration[ftc2.x == zm, :] * phi_w[ftc2.x == zm] +
                ftc2.SF6g.concentration[ftc2.x == zm, :] * phi_g[ftc2.x == zm]) / (
                    phi_w[ftc2.x == zm] + phi_g[ftc2.x == zm])

        M3D9 = (ftc3.SF6w.concentration[ftc3.x == zm, :] * phi_w[ftc3.x == zm] +
                ftc3.SF6g.concentration[ftc3.x == zm, :] * phi_g[ftc3.x == zm]) / (
                    phi_w[ftc3.x == zm] + phi_g[ftc3.x == zm])

        MD9 = np.concatenate((M1D9[0], M2D9[0], M3D9[0]))

        zm = 21
        M1D21 = (ftc1.SF6w.concentration[ftc1.x == zm, :] * phi_w[ftc1.x == zm] +
                ftc1.SF6g.concentration[ftc1.x == zm, :] * phi_g[ftc1.x == zm]) / (
                    phi_w[ftc1.x == zm] + phi_g[ftc1.x == zm])

        M2D21 = (ftc2.SF6w.concentration[ftc2.x == zm, :] * phi_w[ftc2.x == zm] +
                ftc2.SF6g.concentration[ftc2.x == zm, :] * phi_g[ftc2.x == zm]) / (
                    phi_w[ftc2.x == zm] + phi_g[ftc2.x == zm])

        M3D21 = (ftc3.SF6w.concentration[ftc3.x == zm, :] * phi_w[ftc3.x == zm] +
                ftc3.SF6g.concentration[ftc3.x == zm, :] * phi_g[ftc3.x == zm]) / (
                    phi_w[ftc3.x == zm] + phi_g[ftc3.x == zm])

        MD21 = np.concatenate((M1D21[0], M2D21[0], M3D21[0]))

        zm = 33
        M1D33 = (ftc1.SF6w.concentration[ftc1.x == zm, :] * phi_w[ftc1.x == zm] +
                ftc1.SF6g.concentration[ftc1.x == zm, :] * phi_g[ftc1.x == zm]) / (
                    phi_w[ftc1.x == zm] + phi_g[ftc1.x == zm])

        M2D33 = (ftc2.SF6w.concentration[ftc2.x == zm, :] * phi_w[ftc2.x == zm] +
                ftc2.SF6g.concentration[ftc2.x == zm, :] * phi_g[ftc2.x == zm]) / (
                    phi_w[ftc2.x == zm] + phi_g[ftc2.x == zm])

        M3D33 = (ftc3.SF6w.concentration[ftc3.x == zm, :] * phi_w[ftc3.x == zm] +
                ftc3.SF6g.concentration[ftc3.x == zm, :] * phi_g[ftc3.x == zm]) / (
                    phi_w[ftc3.x == zm] + phi_g[ftc3.x == zm])

        MD33 = np.concatenate((M1D33[0], M2D33[0], M3D33[0]))

        MF1 = ftc1.estimate_flux_at_top('SF6g') + ftc1.estimate_flux_at_top(
            'SF6w') + ftc1.estimate_flux_at_top('SF6mp')
        MF2 = ftc2.estimate_flux_at_top('SF6g') + ftc2.estimate_flux_at_top(
            'SF6w') + ftc2.estimate_flux_at_top('SF6mp')
        MF3 = ftc3.estimate_flux_at_top('SF6g') + ftc3.estimate_flux_at_top(
            'SF6w') + ftc3.estimate_flux_at_top('SF6mp')

        MF = np.concatenate((MF1, MF2, MF3))

        MT = np.concatenate((ftc1.time, ftc2.time + ftc1.time[-1],
                            ftc3.time + ftc2.time[-1] + ftc1.time[-1]))

        idxs = find_indexes_of_intersections(MT, Tm, dt)
        idxs_f = find_indexes_of_intersections(MT, Tm[::2] + 1, dt)

        if np.isnan(MF).any() or np.isnan(MD9).any() or np.isnan(
                MD21).any() or np.isnan(MD33).any():
            err = 1e8
        else:
            err = norm_rmse(MD9[idxs], CD9_mean[:len(MD9[idxs])]) + norm_rmse(
                MD21[idxs], CD21_mean[:len(MD21[idxs])]) + norm_rmse(
                    MD33[idxs], CD33_mean[:len(MD33[idxs])]) + 10 * norm_rmse(
                        MF[idxs_f], Fx_mean[:len(MF[idxs_f])])

    except:
        err = 1e8
    print(":::::: {}".format(err))
    return err