Пример #1
0
 def calculate_ml_new(dt, fake, T, p, RH, v, particle_T, r_cr, n, vdry, cell_idx, kappa, qv, rtol_x):
     result = 0
     growing = 0
     decreasing = 0
     for drop in cell_idx:
         x_old = x(v[drop])
         r_old = radius(v[drop])
         rd = radius(volume=vdry[drop])
         if enable_drop_temperatures:
             particle_T_old = particle_T[drop]
             dr_dt_old = dr_dt_FF(r_old, T, p, qv, kappa, rd, particle_T_old)
             args = (x_old, dt, T, p, qv, kappa, rd, particle_T_old)
         else:
             dr_dt_old = dr_dt_MM(r_old, T, p, RH, kappa, rd)
             args = (x_old, dt, T, p, RH, kappa, rd, 0)
         dx_old = dt * dx_dt(x_old, dr_dt_old)
         if dx_old < 0:
             dx_old = np.maximum(dx_old, x(vdry[drop]) - x_old)
         a = x_old
         interval = dx_old
         x_new = bisec(minfun, a, interval, args, rtol_x)
         v_new = volume(x_new)
         if not fake:
             if enable_drop_temperatures:
                 T_i_new = particle_T_old + dt * dT_i_dt_FF(r_old, T, p, particle_T_old, dr_dt_old)
                 particle_T[drop] = T_i_new
             # if v_new > 4/3 * np.pi * (r_cr[drop])**3: # TODO: difference if r<r_cr, filter out noise
             if abs((v_new-v[drop])/v_new) > .5:
                 if v_new - v[drop] > 0:
                     growing += 1
                 else:
                     decreasing += 1
             v[drop] = v_new
         result += n[drop] * v_new * const.rho_w
     return result, (growing > 0 and decreasing > 0 )
Пример #2
0
 def _minfun_FF(x_new, x_old, dt, T, p, qv, kappa, rd, T_i):
     r_new = radius(volume(x_new))
     dr_dt = dr_dt_FF(r_new, T, p, qv, kappa, rd, T_i)
     return x_old - x_new + dt * dx_dt(x_new, dr_dt)
Пример #3
0
        def step_impl(v, particle_temperatures, n, vdry, cell_idx, kappa, thd,
                      qv, dthd_dt_pred, dqv_dt_pred, m_d_mean, rhod_mean,
                      rtol_x, dt, n_substeps, fake):
            using_drop_temperatures = len(particle_temperatures) > 0

            dt /= n_substeps
            n_sd_in_cell = len(cell_idx)

            ml_old = 0
            for i in range(n_sd_in_cell):
                ml_old += n[cell_idx[i]] * v[cell_idx[i]] * const.rho_w

            for t in range(n_substeps):
                thd += dt * dthd_dt_pred / 2  # TODO: test showing that it makes sense
                qv += dt * dqv_dt_pred / 2
                T, p, RH = temperature_pressure_RH(rhod_mean, thd, qv)

                ml_new = 0
                for i in range(n_sd_in_cell):
                    x_old = x(v[cell_idx[i]])
                    if using_drop_temperatures:
                        T_i_old = particle_temperatures[cell_idx[i]]

                    r_old = radius(v[cell_idx[i]])
                    rd = radius(volume=vdry[cell_idx[i]])
                    dr_dt_old = (dr_dt_MM(r_old, T, p, RH, kappa, rd)
                                 if not using_drop_temperatures else dr_dt_FF(
                                     r_old, T, p, qv, kappa, rd, T_i_old))
                    dx_old = dt * dx_dt(x_old, dr_dt_old)

                    if dx_old < 0:
                        dx_old = np.maximum(dx_old,
                                            x(vdry[cell_idx[i]]) - x_old)

                    a = x_old
                    interval = dx_old
                    if not using_drop_temperatures:
                        args_MM = (x_old, dt, T, p, RH, kappa, rd)
                        x_new = bisec(_minfun_MM, a, interval, args_MM, rtol_x,
                                      n_substeps)
                    else:
                        args_FF = (x_old, dt, T, p, qv, kappa, rd, T_i_old)
                        x_new = bisec(_minfun_FF, a, interval, args_FF, rtol_x,
                                      n_substeps)

                    v_new = volume(x_new)

                    if not fake:
                        if using_drop_temperatures:
                            T_i_new = T_i_old + dt * dT_i_dt_FF(
                                r_old, T, p, T_i_old, dr_dt_old)
                            particle_temperatures[cell_idx[i]] = T_i_new
                        v[cell_idx[i]] = v_new
                    ml_new += n[cell_idx[i]] * v_new * const.rho_w

                dml_dt = (ml_new - ml_old) / dt
                dqv_dt_corr = -dml_dt / m_d_mean
                dthd_dt_corr = dthd_dt(rhod=rhod_mean,
                                       thd=thd,
                                       T=T,
                                       dqv_dt=dqv_dt_pred + dqv_dt_corr)
                thd += dt * (dthd_dt_pred / 2 + dthd_dt_corr)
                qv += dt * (dqv_dt_pred / 2 + dqv_dt_corr)
                ml_old = ml_new

            return qv, thd
Пример #4
0
 def dr_dt_FF(r, T, p, qv, kp, rd, T_i):
     return dr_dt_FF(r, T, p, qv, kp, rd, T_i)