Exemplo n.º 1
0
loc = 0.0
scale = 1.0e-2
kgwt = 332.0e-25
accom_coeff = np.ones((num_speci, 1))  # particle accommodation coefficient
therm_sp = (np.array((0, 0, 0, 218, 0))).reshape(num_speci, 1)
Cw = 301.0e13
y_dens = np.array((870, 1133, 1033, 1000, 1770)).reshape(num_speci, 1)
Psat = (np.array((110 * 1e15, 526 * 1e20, 242 / 1e18, 778 * 1e15,
                  242 / 1e18))).reshape(num_speci, 1)
core_diss = 3.0

[
    y, N_perbin, x, Varr, Vbou, rad0, Vol0, rbou, new_partr, MV, num_sb,
    nuc_comp
] = pp_intro(y, num_speci, spec_list, Pybel_objects, TEMP, H2Oi, mfp,
             accom_coeff, y_mw, surfT, DStar_org, RH, num_sb, lowersize,
             uppersize, pconc, tmax, nuc_comp, voli, volP, testf, std, loc,
             scale, therm_sp, Cw, y_dens, Psat, core_diss, kgwt)
print('pp_intro called and returned fine, now checking returned values')

if int(y[5]) != 0 or int(y[8] * 1e-6) != 717 or int(y[9] * 1e-6) != 252 or int(
        y[13] * 1e-7) != 179 or int(y[14] * 1e-6) != 476 or int(
            y[18] * 1e-13) != 178:
    print(
        'issue with y, possibly due to init_water_partit.py or Size_distributions.py'
    )
if int(N_perbin[0]) != 934 or int(N_perbin[1]) != 65:
    print('issue with N_perbin possibly due to Size_distributions')
if int(x[0] * 1e4) != 237 or int(x[1] * 1e4) != 744:
    print('issue with x possibly due to Size_distributions')
if int(Varr[0] * 1e7) != 564 or int(Varr[1] * 1e5) != 172:
    print('issue with Varr possibly due to Size_distributions')
Exemplo n.º 2
0
def run(testf):

    # inputs: ----------------------------------------------------------------------------
    # testf - test flag, 1 for test mode (called by test_front.py), 2 for test mode
    # (called by test_PyCHAM.py), 0 for normal mode
    # ------------------------------------------------------------------------------------

    if testf == 2:
        print('"Run Model" button works fine')
        return ()
    if testf == 1:
        print('calling user_input.py')
    # module to ask, receive and return required inputs
    [
        fname, num_sb, lowersize, uppersize, end_sim_time, resfname, TEMP,
        PInit, RH, lat, lon, start_sim_time, act_flux_path, save_step, Cw,
        ChamR, nucv1, nucv2, nucv3, nuc_comp, new_partr, inflectDp, pwl_xpre,
        pwl_xpro, inflectk, xmlname, init_conc, Comp0, Rader, vol_Comp, volP,
        pconc, std, mean_rad, core_diss, light_stat, light_time, kgwt, testm,
        dydt_trak, DayOfYear, space_mode, Ct, Compt, injectt, seed_name,
        const_comp, const_infl, Cinfl, act_comp, act_user, seed_mw,
        umansysprop_update, core_dens, p_char, e_field, const_infl_t,
        chem_scheme_markers, int_tol, photo_par_file, dil_fac, pconct,
        accom_coeff_ind, accom_coeff_user, update_step, tempt, coag_on
    ] = ui.run(0, testf)

    if testm == 1:
        print('PyCHAM calls front fine, now returning to PyCHAM.py')
        print(
            'Please select the "Plot Results" button to ensure this works fine'
        )
        return ()

    if testf == 1:
        print('user_input.py called and returned fine')
        print('calling eqn_parser.extract_mechanism')

    # obtain gas-phase reaction info
    [
        rindx, pindx, rstoi, pstoi, reac_coef, spec_list, Pybel_objects,
        num_eqn, num_speci, RO2_indices, nreac, nprod, prodn, reacn,
        spec_namelist, Jlen, rindx_aq, pindx_aq, rstoi_aq, pstoi_aq,
        reac_coef_aq, nreac_aq, nprod_aq, prodn_aq, reacn_aq
    ] = eqn_parser.extract_mechanism(fname, xmlname, PInit, testf, RH,
                                     start_sim_time, lat, lon, act_flux_path,
                                     DayOfYear, chem_scheme_markers,
                                     photo_par_file)

    if testf == 1:
        print('eqn_parser.extract_mechanism called and returned fine')
        print('calling init_conc_func')
    # set up initial gas-phase concentration array
    [
        y, H2Oi, y_mw, num_speci, Cfactor, y_indx_plot, corei, dydt_vst,
        spec_namelist, inj_indx, const_compi, const_infli, core_diss,
        Psat_water, nuci
    ] = init_conc_func(num_speci, Comp0, init_conc, TEMP[0], RH, reac_coef,
                       fname, PInit, start_sim_time, lat, lon, Pybel_objects,
                       testf, pconc, act_flux_path, dydt_trak, end_sim_time,
                       save_step, rindx, pindx, num_eqn, nreac, nprod,
                       DayOfYear, spec_namelist, Compt, seed_name, const_comp,
                       const_infl, seed_mw, core_diss, nuc_comp)

    if testf == 1:
        print('init_conc_func called and returned fine')
        print('calling kimt_prep')
    # set up partitioning variables
    [DStar_org, mfp, accom_coeff, therm_sp, surfT, Cw,
     act_coeff] = kimt_prep(y_mw, TEMP[0], num_speci, testf, Cw, act_comp,
                            act_user, accom_coeff_ind, accom_coeff_user,
                            spec_namelist, num_sb)

    # volatility (molecules/cc (air)) and density (rho, kg/m3) of components
    if testf == 1:
        print('kimt_prep called and returned fine')
        print('calling volat_calc.py')

    [Psat, y_dens,
     Psat_Pa] = volat_calc(spec_list, Pybel_objects, TEMP[0], H2Oi, num_speci,
                           Psat_water, vol_Comp, volP, testf, corei, pconc,
                           umansysprop_update, core_dens, spec_namelist, 0,
                           nuci, nuc_comp)

    if testf == 1:
        print('volat_calc called and returned fine')
        print('calling wall_prep')

    if testf == 1:
        print('wall_prep called and returned fine')
        print('calling pp_intro')

    # set up particle phase part
    # check whether there are particles at the start of simulation
    if pconct[0, 0] == 0.0:
        pconc_now = pconc[:, 0]
    else:
        pconc_now = np.zeros((1))

    [
        y, N_perbin, x, Varr, Vbou, rad0, Vol0, rbou, MV, num_sb, nuc_comp,
        rbou00, upper_bin_rad_amp
    ] = pp_intro(y, num_speci, Pybel_objects, TEMP[0], H2Oi, mfp, accom_coeff,
                 y_mw, surfT, DStar_org, RH, num_sb, lowersize, uppersize,
                 pconc_now, nuc_comp, testf, std[0, 0], mean_rad[0, 0],
                 therm_sp, Cw, y_dens, Psat, core_diss, kgwt, space_mode,
                 corei, spec_namelist, act_coeff)

    t1 = time.clock()  # get wall clock time before call to solver
    if testf == 1:
        print('pp_intro called and returned fine')
        print('calling ode_gen')

    # call on ode function
    [t_out, y_mat,
     Nresult_dry, Nresult_wet, x2, dydt_vst, Cfactor_vst] = ode_gen(
         y, num_speci, num_eqn, rindx, pindx, rstoi, pstoi, H2Oi, TEMP,
         RO2_indices, num_sb, Psat, mfp, accom_coeff, surfT, y_dens, N_perbin,
         DStar_org, y_mw, x, core_diss, Varr, Vbou, RH, rad0, Vol0,
         end_sim_time, pconc, save_step, rbou, therm_sp, Cw, light_time,
         light_stat, nreac, nprod, prodn, reacn, new_partr, MV, nucv1, nucv2,
         nucv3, inflectDp, pwl_xpre, pwl_xpro, inflectk, nuc_comp, ChamR,
         Rader, PInit, testf, kgwt, dydt_vst, start_sim_time, lat, lon,
         act_flux_path, DayOfYear, Ct, injectt, inj_indx, corei, const_compi,
         const_comp, const_infli, Cinfl, act_coeff, p_char, e_field,
         const_infl_t, int_tol, photo_par_file, Jlen, dil_fac, pconct,
         lowersize, uppersize, mean_rad, std, update_step, Pybel_objects,
         tempt, Cfactor, coag_on, rindx_aq, pindx_aq, rstoi_aq, pstoi_aq,
         nreac_aq, nprod_aq, prodn_aq, reacn_aq)

    t2 = time.clock()  # get wall clock time after call to solver
    time_taken = t2 - t1  # computer time taken for entire simulation (s)
    if testf == 0:  # in normal mode
        print(str('time taken= ' + str(time_taken)))

        # make new pickle dump to store the indices and names of interesting gas-phase
        # components along with initial pickle variables
        list_vars = [fname, resfname, y_indx_plot, Comp0]
    if testf == 1:
        print('ode_gen called and returned fine')
        print('dumping variables in pickle file')
        # dummy list of variables to dump
        list_vars = ['fnametest', 'resfnametest', 0, 0]
        with open('test_var_store.pkl', 'wb') as f:
            pickle.dump(list_vars, f)

    if testf == 00:
        with open('PyCHAM/var_store.pkl', 'wb') as f:
            pickle.dump(list_vars, f)

    if testf == 1:
        print('dumped successfully')
    # save data
    output_by_sim = saving(fname, y_mat, t_out, Nresult_dry, Nresult_wet, x2,
                           num_sb, y_mw, num_speci, resfname, rbou, Cfactor,
                           MV, testf, dydt_vst, dydt_trak, spec_namelist,
                           rbou00, upper_bin_rad_amp, Cfactor_vst, time_taken,
                           seed_name)
    if testf == 1:
        print('saving called and returned successfully')
    return ()
Exemplo n.º 3
0
def run(testf):

    # inputs:
    # testf - test flag, 1 for test mode (called by test_front.py), 2 for test mode
    # (called by test_PyCHAM.py), 0 for normal mode

    if testf == 2:
        print('"Run Model" button works fine')
        return ()
    if testf == 1:
        print('calling user_input.py')
    # module to ask, receive and return required inputs
    [
        fname, num_sb, lowersize, uppersize, end_sim_time, resfname, tstep_len,
        tmax, TEMP, PInit, RH, lat, lon, start_sim_time, save_step, Cw, ChamR,
        nucv1, nucv2, nucv3, nuc_comp, inflectDp, pwl_xpre, pwl_xpro, inflectk,
        xmlname, init_conc, Comp0, Rader, voli, volP, pconc, std, loc, scale,
        core_diss, light_stat, light_time, kgwt, testm
    ] = ui.run(0, testf)

    if testm == 1:
        print('PyCHAM calls front fine, now returning to PyCHAM.py')
        print(
            'Please select the "Plot Results" button to ensure this works fine'
        )
        return ()

    if testf == 1:
        print('user_input.py called and returned fine')
        print('calling eqn_parser.extract_mechanism')

    # obtain gas-phase reaction info
    [
        rindx, pindx, rstoi, pstoi, reac_coef, spec_list, Pybel_objects,
        num_eqn, num_speci, RO2_indices, nreac, nprod, prodn, reacn, M_val,
        N2_val, O2_val, init_SMIL, spec_namelist
    ] = eqn_parser.extract_mechanism(fname, xmlname, TEMP, PInit, Comp0, testf)

    if testf == 1:
        print('eqn_parser.extract_mechanism called and returned fine')
        print('calling init_conc_func')
    # set up initial gas-phase concentration array
    [y, H2Oi, Psat_water, y_mw, num_speci, Cfactor, y_indx_plot,
     corei] = init_conc_func(num_speci, init_SMIL, spec_list, init_conc, TEMP,
                             RH, M_val, N2_val, O2_val, reac_coef, fname,
                             PInit, start_sim_time, lat, lon, Pybel_objects,
                             testf, pconc)

    if testf == 1:
        print('init_conc_func called and returned fine')
        print('calling kimt_prep')
    # set up partitioning variables
    [DStar_org, mfp, accom_coeff, therm_sp, surfT, Cw,
     kgwt] = kimt_prep(y_mw, TEMP, num_speci, testf, Cw, kgwt)

    # volatility (molecules/cc (air)) and density (rho, kg/m3) of components
    if testf == 1:
        print('kimt_prep called and returned fine')
        print('calling volat_calc.py')
    [Psat, y_dens,
     Psat_Pa] = volat_calc(spec_list, Pybel_objects, TEMP, H2Oi, num_speci,
                           Psat_water, voli, volP, testf, corei)

    if testf == 1:
        print('volat_calc called and returned fine')
        print('calling wall_prep')

    if testf == 1:
        print('wall_prep called and returned fine')
        print('calling pp_intro')
    # set up particle phase part
    [
        y, N_perbin, x, Varr, Vbou, rad0, Vol0, rbou, new_partr, MV, num_sb,
        nuc_comp
    ] = pp_intro(y, num_speci, spec_list, Pybel_objects, TEMP, H2Oi, mfp,
                 accom_coeff, y_mw, surfT, DStar_org, RH, num_sb, lowersize,
                 uppersize, pconc, tmax, nuc_comp, voli, volP, testf, std, loc,
                 scale, therm_sp, Cw, y_dens, Psat, core_diss, kgwt)

    t1 = time.clock()  # get wall clock time before call to solver
    if testf == 1:
        print('pp_intro called and returned fine')
        print('calling ode_gen')

    # call on ode function
    [t_out, y_mat, Nresult,
     x2] = ode_gen(tstep_len, y, num_speci, num_eqn, rindx, pindx, rstoi,
                   pstoi, H2Oi, TEMP, RO2_indices, num_sb, Psat, mfp,
                   accom_coeff, surfT, y_dens, N_perbin, DStar_org, y_mw, x,
                   core_diss, Varr, Vbou, RH, rad0, Vol0, end_sim_time, pconc,
                   save_step, rbou, therm_sp, Cw, light_time, light_stat,
                   nreac, nprod, prodn, reacn, new_partr, MV, nucv1, nucv2,
                   nucv3, inflectDp, pwl_xpre, pwl_xpro, inflectk, nuc_comp,
                   ChamR, Rader, PInit, testf, kgwt)

    t2 = time.clock()  # get wall clock time after call to solver
    if testf == 0:  # in normal mode
        print('time taken=')
        print(t2 - t1)

        # make new pickle dump to store the indices and names of interesting gas-phase
        # components along with initial pickle variables
        list_vars = [fname, resfname, y_indx_plot, Comp0]
    if testf == 1:
        print('ode_gen called and returned fine')
        print('dumping variables in pickle file')
        # dummy list of variables to dump
        list_vars = ['fnametest', 'resfnametest', 0, 0]
        with open('test_var_store.pkl', 'wb') as f:
            pickle.dump(list_vars, f)

    if testf == 00:
        with open('PyCHAM/var_store.pkl', 'wb') as f:
            pickle.dump(list_vars, f)

    if testf == 1:
        print('dumped successfully')
    # save data
    output_by_sim = saving(fname, y_mat, t_out, Nresult, x2, num_sb, y_mw,
                           num_speci, resfname, rbou, Cfactor, MV, testf,
                           spec_namelist)
    if testf == 1:
        print('saving called and returned successfully')
    return ()
Exemplo n.º 4
0
def middle():

    # get required inputs
    [
        sav_nam, sch_name, chem_sch_mrk, xml_name, update_stp, tot_time, comp0,
        y0, temp, tempt, RH, Pnow, wall_on, Cw, kw, siz_str, num_sb, pmode,
        pconc, pconct, lowsize, uppsize, space_mode, std, mean_rad, save_step,
        const_comp, Compt, injectt, Ct, seed_name, seed_mw, core_diss,
        core_dens, seedVr, light_stat, light_time, daytime, lat, lon, af_path,
        dayOfYear, photo_path, tf, light_ad, con_infl_nam, const_infl_t,
        con_infl_C, dydt_trak, dens_comp, dens, vol_comp, volP, act_comp,
        act_user, accom_comp, accom_coeff_user, uman_up, int_tol, new_partr,
        nucv1, nucv2, nucv3, nuc_comp, nuc_ad, coag_on, inflectDp, pwl_xpre,
        pwl_xpro, inflectk, ChamR, Rader, p_char, e_field, dil_fac,
        partit_cutoff
    ] = ui.share(0)

    # parse the chemical scheme equation file to convert equations
    # into usable code
    [
        rindx_g, pindx_g, rstoi_g, pstoi_g, nreac_g, nprod_g, jac_stoi_g,
        njac_g, jac_den_indx_g, jac_indx_g, y_arr_g, y_rind_g, uni_y_rind_g,
        y_pind_g, uni_y_pind_g, reac_col_g, prod_col_g, rstoi_flat_g,
        pstoi_flat_g, rr_arr_g, rr_arr_p_g, rowvals, colptrs, jac_wall_indx,
        jac_part_indx, comp_num, RO2_indx, comp_list, Pybel_objects, eqn_num,
        comp_namelist, Jlen, rindx_aq, rstoi_aq, pindx_aq, pstoi_aq,
        reac_coef_aq, nreac_aq, nprod_aq, jac_stoi_aq, jac_den_indx_aq,
        njac_aq, jac_indx_aq, y_arr_aq, y_rind_aq, uni_y_rind_aq, y_pind_aq,
        uni_y_pind_aq, reac_col_aq, prod_col_aq, rstoi_flat_aq, pstoi_flat_aq,
        rr_arr_aq, rr_arr_p_aq
    ] = eqn_pars.extr_mech(sch_name, chem_sch_mrk, xml_name, photo_path,
                           con_infl_nam, int_tol, wall_on, (num_sb + wall_on),
                           const_comp)

    # set initial concentrations (molecules/cc)
    [
        y, H2Oi, y_mw, num_comp, Cfactor, indx_plot, corei, dydt_vst,
        comp_namelist, inj_indx, core_diss, Psat_water, nuci, nrec_steps, seedi
    ] = init_conc.init_conc(comp_num, comp0, y0, temp[0], RH, Pnow,
                            Pybel_objects, 0, pconc, dydt_trak, tot_time,
                            save_step, rindx_g, pindx_g, eqn_num[0], nreac_g,
                            nprod_g, comp_namelist, Compt, seed_name, seed_mw,
                            core_diss, nuc_comp)

    # dump new pickle file ready for plotting script to use
    list_vars = [sav_nam, sch_name, indx_plot, comp0]
    input_by_sim = str(os.getcwd() + '/PyCHAM/pickle.pkl')
    with open(input_by_sim, 'wb') as f:  # the file to be used for pickling
        pickle.dump(list_vars, f)  # pickle
        f.close()  # close

    # get component properties
    [Psat, y_dens, Psat_Pa
     ] = prop_calc.prop_calc(comp_list, Pybel_objects, temp[0], H2Oi, num_comp,
                             Psat_water, vol_comp, volP, 0, corei, pconc,
                             uman_up, core_dens, comp_namelist, 0, nuci,
                             nuc_comp, num_sb, dens_comp, dens, seed_name)

    # prepare for the calcuation of partitioning variables
    [mfp, accom_coeff, therm_sp, surfT, Cw, act_coeff, R_gas, NA,
     coll_dia] = partit_var_prep.prep(y_mw, temp[0], num_comp, 0, Cw, act_comp,
                                      act_user, accom_comp, accom_coeff_user,
                                      comp_namelist, num_sb, num_sb, Pnow)
    count = 0

    # prepare particle phase and wall
    [
        y, N_perbin, x, Varr, Vbou, rad0, Vol0, rbou, MV, num_sb, nuc_comp,
        rbou00, upper_bin_rad_amp, np_sum
    ] = pp_intro.pp_intro(y, num_comp, Pybel_objects, temp[0], H2Oi, mfp,
                          accom_coeff, y_mw, surfT, RH, siz_str, num_sb,
                          lowsize, uppsize, pmode, pconc, pconct, nuc_comp, 0,
                          std, mean_rad, therm_sp, Cw, y_dens, Psat, core_diss,
                          kw, space_mode, seedVr, comp_namelist, act_coeff,
                          wall_on, partit_cutoff, Pnow, coll_dia, seedi)

    print('Calling integration routine, starting timer')
    st_time = time.time()

    # solve problem
    [trec, yrec, dydt_vst, Cfactor_vst,
     Nres_dry, Nres_wet, x2, rbou_rec] = ode_updater.ode_updater(
         update_stp, tot_time, save_step, y, rindx_g, pindx_g, rstoi_g,
         pstoi_g, nreac_g, nprod_g, jac_stoi_g, njac_g, jac_den_indx_g,
         jac_indx_g, RO2_indx, H2Oi, temp, tempt, Pnow, light_stat, light_time,
         daytime, lat, lon, af_path, dayOfYear, photo_path, Jlen, con_infl_C,
         nrec_steps, dydt_vst, siz_str, num_sb, num_comp, seedi, seed_name,
         seedVr, core_diss, Psat, mfp, therm_sp, accom_coeff, y_mw, surfT,
         R_gas, NA, y_dens, x, Varr, act_coeff, Cw, kw, Cfactor, tf, light_ad,
         y_arr_g, y_rind_g, uni_y_rind_g, y_pind_g, uni_y_pind_g, reac_col_g,
         prod_col_g, rstoi_flat_g, pstoi_flat_g, rr_arr_g, rr_arr_p_g, rowvals,
         colptrs, wall_on, jac_wall_indx, jac_part_indx, Vbou, N_perbin, Vol0,
         rad0, np_sum, new_partr, nucv1, nucv2, nucv3, nuc_comp, nuc_ad, RH,
         coag_on, inflectDp, pwl_xpre, pwl_xpro, inflectk, ChamR, Rader,
         p_char, e_field, injectt, inj_indx, Ct, pmode, pconc, pconct,
         mean_rad, lowsize, uppsize, std, rbou, const_infl_t, MV, rindx_aq,
         pindx_aq, rstoi_aq, pstoi_aq, nreac_aq, nprod_aq, jac_stoi_aq,
         njac_aq, jac_den_indx_aq, jac_indx_aq, y_arr_aq, y_rind_aq,
         uni_y_rind_aq, y_pind_aq, uni_y_pind_aq, reac_col_aq, prod_col_aq,
         rstoi_flat_aq, pstoi_flat_aq, rr_arr_aq, rr_arr_p_aq, eqn_num,
         partit_cutoff, coll_dia, corei)

    time_taken = time.time() - st_time
    print(
        'Simulation complete, wall clock time elapsed since first call to solver: ',
        time_taken, ' s')

    print('Saving results')
    # save results
    save.saving(sch_name, yrec, Nres_dry, Nres_wet, trec, sav_nam, dydt_vst,
                num_comp, Cfactor_vst, 0, num_sb, comp_namelist, dydt_trak,
                y_mw, MV, time_taken, seed_name, x2, rbou_rec, wall_on,
                space_mode, rbou00, upper_bin_rad_amp)
    print('Saved results')

    return ()
Exemplo n.º 5
0
def middle():  # define function

    # inputs: -----------------------------------------------------
    # ---------------------------------------------------------------

    # get required inputs
    [
        sav_nam, sch_name, chem_sch_mrk, xml_name, update_stp, tot_time, comp0,
        y0, temp, tempt, RH, RHt, Pnow, wall_on, Cw, kw, siz_str, num_sb,
        pmode, pconc, pconct, lowsize, uppsize, space_mode, std, mean_rad,
        save_step, const_comp, Compt, injectt, Ct, seed_name, seed_mw,
        core_diss, seed_dens, seedx, light_stat, light_time, daytime, lat, lon,
        af_path, dayOfYear, photo_path, tf, light_ad, con_infl_nam,
        const_infl_t, con_infl_C, dydt_trak, dens_comp, dens, vol_comp, volP,
        act_comp, act_user, accom_comp, accom_coeff_user, uman_up, int_tol,
        new_partr, nucv1, nucv2, nucv3, nuc_comp, nuc_ad, coag_on, inflectDp,
        pwl_xpre, pwl_xpro, inflectk, ChamR, Rader, p_char, e_field, dil_fac,
        partit_cutoff, ser_H2O, inname, wat_hist, drh_str, erh_str, pcont,
        Vwat_inc, seed_eq_wat, z_prt_coeff, tf_UVC, testf, chamSA, chamV
    ] = ui.share()

    # parse the chemical scheme equation file to convert equations
    # into usable code
    [
        rindx_g, pindx_g, rstoi_g, pstoi_g, nreac_g, nprod_g, jac_stoi_g,
        njac_g, jac_den_indx_g, jac_indx_g, y_arr_g, y_rind_g, uni_y_rind_g,
        y_pind_g, uni_y_pind_g, reac_col_g, prod_col_g, rstoi_flat_g,
        pstoi_flat_g, rr_arr_g, rr_arr_p_g, rowvals, colptrs, jac_wall_indx,
        jac_part_indx, jac_extr_indx, comp_num, RO2_indx, RO_indx, HOMRO2_indx,
        rel_SMILES, Pybel_objects, eqn_num, comp_namelist, Jlen, rindx_aq,
        rstoi_aq, pindx_aq, pstoi_aq, reac_coef_aq, nreac_aq, nprod_aq,
        jac_stoi_aq, jac_den_indx_aq, njac_aq, jac_indx_aq, y_arr_aq,
        y_rind_aq, uni_y_rind_aq, y_pind_aq, uni_y_pind_aq, reac_col_aq,
        prod_col_aq, rstoi_flat_aq, pstoi_flat_aq, rr_arr_aq, rr_arr_p_aq,
        comp_xmlname, comp_smil, erf, err_mess, con_C_indx
    ] = eqn_pars.extr_mech(sch_name, chem_sch_mrk, xml_name, photo_path,
                           con_infl_nam, int_tol, wall_on, (num_sb + wall_on),
                           const_comp, drh_str, erh_str, dil_fac, sav_nam,
                           pcont)

    # if needed then run operations to produce variable checker plot
    # from the simulate tab
    if (testf >= 4):
        import var_checker
        [err_mess,
         erf] = var_checker.var_checker(testf, light_stat, light_time, daytime,
                                        lat, lon, temp, tempt, tot_time,
                                        af_path, dayOfYear, photo_path, Jlen,
                                        tf, tf_UVC, update_stp, err_mess, erf)

    # if error raised, then tell GUI to display and to stop program
    if (erf == 1):
        yield err_mess

    # set initial concentrations (# molecules/cm3)
    [
        y, H2Oi, y_mw, num_comp, Cfactor, indx_plot, corei, dydt_vst,
        comp_namelist, inj_indx, core_diss, Psat_water, nuci, nrec_steps,
        seedi, erf, err_mess, NOi, HO2i, NO3i
    ] = init_conc.init_conc(comp_num, comp0, y0, temp[0], RH, Pnow,
                            Pybel_objects, 0, pconc, dydt_trak, tot_time,
                            save_step, rindx_g, pindx_g, eqn_num[0], nreac_g,
                            nprod_g, comp_namelist, Compt, seed_name, seed_mw,
                            core_diss, nuc_comp, comp_xmlname, comp_smil,
                            rel_SMILES, RO2_indx, HOMRO2_indx, rstoi_g,
                            pstoi_g)

    # if error raised, then tell GUI to display and to stop programme
    if (erf == 1):
        yield err_mess

    # get component properties
    [Psat, y_dens, Psat_Pa, Psat_Pa_rec,
     OC] = prop_calc.prop_calc(rel_SMILES, Pybel_objects, temp[0], H2Oi,
                               num_comp, Psat_water, vol_comp, volP, 0, corei,
                               pconc, uman_up, seed_dens, comp_namelist, 0,
                               nuci, nuc_comp, num_sb, dens_comp, dens,
                               seed_name, y_mw)

    # prepare for the calculation of partitioning variables
    [
        mfp, accom_coeff, therm_sp, surfT, Cw, act_coeff, R_gas, NA, diff_vol,
        Dstar_org, err_mess
    ] = partit_var_prep.prep(y_mw, temp[0], num_comp, testf, Cw, act_comp,
                             act_user, accom_comp, accom_coeff_user,
                             comp_namelist, num_sb, num_sb, Pnow,
                             Pybel_objects, comp_smil)

    if (err_mess != ''):  # if error raised or in testing mode then stop
        yield err_mess

    # prepare particle phase and wall
    [
        y, N_perbin, x, Varr, Vbou, rad0, Vol0, rbou, MV, num_sb, nuc_comp,
        rbou00, ub_rad_amp, np_sum, C_p2w
    ] = pp_intro.pp_intro(y, num_comp, Pybel_objects, temp[0], H2Oi, mfp,
                          accom_coeff, y_mw, surfT, siz_str, num_sb, lowsize,
                          uppsize, pmode, pconc, pconct, nuc_comp, 0, std,
                          mean_rad, therm_sp, y_dens, Psat, core_diss, kw,
                          space_mode, seedx, comp_namelist, act_coeff, wall_on,
                          partit_cutoff, Pnow, seedi, pcont, seed_mw, R_gas,
                          Vwat_inc, seed_eq_wat)

    # estimate total inputs of emitted components (ug/m3)
    [tot_in_res, Compti, cont_inf_reci, cont_inf_i,
     tot_in_res_indx] = tot_in.tot_in(y0, Cfactor, comp0, comp_namelist, y_mw,
                                      con_infl_nam, const_infl_t, tot_time,
                                      con_infl_C, Compt)

    # solve problem
    for prog in ode_updater.ode_updater(
            update_stp, tot_time, save_step, y, rindx_g, pindx_g, rstoi_g,
            pstoi_g, nreac_g, nprod_g, jac_stoi_g, njac_g, jac_den_indx_g,
            jac_indx_g, RO2_indx, RO_indx, H2Oi, temp, tempt, Pnow, light_stat,
            light_time, daytime, lat, lon, af_path, dayOfYear, photo_path,
            Jlen, con_infl_C, nrec_steps, dydt_vst, siz_str, num_sb, num_comp,
            seedi, seed_name, seedx, core_diss, Psat, mfp, therm_sp,
            accom_coeff, y_mw, surfT, R_gas, NA, y_dens, x, Varr, act_coeff,
            Cw, kw, Cfactor, tf, light_ad, y_arr_g, y_rind_g, uni_y_rind_g,
            y_pind_g, uni_y_pind_g, reac_col_g, prod_col_g, rstoi_flat_g,
            pstoi_flat_g, rr_arr_g, rr_arr_p_g, rowvals, colptrs, wall_on,
            jac_wall_indx, jac_part_indx, jac_extr_indx, Vbou, N_perbin, Vol0,
            rad0, np_sum, new_partr, nucv1, nucv2, nucv3, nuci, nuc_comp,
            nuc_ad, RH, RHt, coag_on, inflectDp, pwl_xpre, pwl_xpro, inflectk,
            ChamR, Rader, p_char, e_field, injectt, inj_indx, Ct, pmode, pconc,
            pconct, mean_rad, lowsize, uppsize, std, rbou, const_infl_t, MV,
            rindx_aq, pindx_aq, rstoi_aq, pstoi_aq, nreac_aq, nprod_aq,
            jac_stoi_aq, njac_aq, jac_den_indx_aq, jac_indx_aq, y_arr_aq,
            y_rind_aq, uni_y_rind_aq, y_pind_aq, uni_y_pind_aq, reac_col_aq,
            prod_col_aq, rstoi_flat_aq, pstoi_flat_aq, rr_arr_aq, rr_arr_p_aq,
            eqn_num, partit_cutoff, diff_vol, Dstar_org, corei, ser_H2O, C_p2w,
            sch_name, sav_nam, comp_namelist, dydt_trak, space_mode, rbou00,
            ub_rad_amp, indx_plot, comp0, inname, rel_SMILES, Psat_Pa_rec,
            Psat_Pa, OC, wat_hist, Pybel_objects, pcont, dil_fac, NOi, HO2i,
            NO3i, z_prt_coeff, con_C_indx, seed_eq_wat, Vwat_inc, tot_in_res,
            Compti, cont_inf_reci, cont_inf_i, tot_in_res_indx, tf_UVC, chamSA,
            chamV):

        yield prog  # update progress bar

    return ()
Exemplo n.º 6
0
def middle():  # define function

    # inputs: -----------------------------------------------------
    # ---------------------------------------------------------------

    # get required inputs

    [
        sav_nam, sch_name, chem_sch_mrk, xml_name, update_stp, tot_time, comp0,
        y0, temp, tempt, RH, RHt, Pnow, wall_on, Cw, kw, siz_str, num_sb,
        pmode, pconc, pconct, lowsize, uppsize, space_mode, std, mean_rad,
        save_step, const_comp, Compt, injectt, Ct, seed_name, seed_mw,
        core_diss, core_dens, seedVr, light_stat, light_time, daytime, lat,
        lon, af_path, dayOfYear, photo_path, tf, light_ad, con_infl_nam,
        const_infl_t, con_infl_C, dydt_trak, dens_comp, dens, vol_comp, volP,
        act_comp, act_user, accom_comp, accom_coeff_user, uman_up, int_tol,
        new_partr, nucv1, nucv2, nucv3, nuc_comp, nuc_ad, coag_on, inflectDp,
        pwl_xpre, pwl_xpro, inflectk, ChamR, Rader, p_char, e_field, dil_fac,
        partit_cutoff, ser_H2O, inname, wat_hist, drh_str, erh_str
    ] = ui.share()

    # parse the chemical scheme equation file to convert equations
    # into usable code
    [
        rindx_g, pindx_g, rstoi_g, pstoi_g, nreac_g, nprod_g, jac_stoi_g,
        njac_g, jac_den_indx_g, jac_indx_g, y_arr_g, y_rind_g, uni_y_rind_g,
        y_pind_g, uni_y_pind_g, reac_col_g, prod_col_g, rstoi_flat_g,
        pstoi_flat_g, rr_arr_g, rr_arr_p_g, rowvals, colptrs, jac_wall_indx,
        jac_part_indx, comp_num, RO2_indx, rel_SMILES, Pybel_objects, eqn_num,
        comp_namelist, Jlen, rindx_aq, rstoi_aq, pindx_aq, pstoi_aq,
        reac_coef_aq, nreac_aq, nprod_aq, jac_stoi_aq, jac_den_indx_aq,
        njac_aq, jac_indx_aq, y_arr_aq, y_rind_aq, uni_y_rind_aq, y_pind_aq,
        uni_y_pind_aq, reac_col_aq, prod_col_aq, rstoi_flat_aq, pstoi_flat_aq,
        rr_arr_aq, rr_arr_p_aq, comp_xmlname, comp_smil
    ] = eqn_pars.extr_mech(sch_name, chem_sch_mrk, xml_name, photo_path,
                           con_infl_nam, int_tol, wall_on, (num_sb + wall_on),
                           const_comp, drh_str, erh_str)

    # set initial concentrations (molecules/cc)
    [
        y, H2Oi, y_mw, num_comp, Cfactor, indx_plot, corei, dydt_vst,
        comp_namelist, inj_indx, core_diss, Psat_water, nuci, nrec_steps, seedi
    ] = init_conc.init_conc(comp_num, comp0, y0, temp[0], RH, Pnow,
                            Pybel_objects, 0, pconc, dydt_trak, tot_time,
                            save_step, rindx_g, pindx_g, eqn_num[0], nreac_g,
                            nprod_g, comp_namelist, Compt, seed_name, seed_mw,
                            core_diss, nuc_comp, comp_xmlname, comp_smil,
                            rel_SMILES)

    # get component properties
    [Psat, y_dens, Psat_Pa, Psat_Pa_rec, OC
     ] = prop_calc.prop_calc(rel_SMILES, Pybel_objects, temp[0], H2Oi,
                             num_comp, Psat_water, vol_comp, volP, 0, corei,
                             pconc, uman_up, core_dens, comp_namelist, 0, nuci,
                             nuc_comp, num_sb, dens_comp, dens, seed_name)

    # prepare for the calcuation of partitioning variables
    [
        mfp, accom_coeff, therm_sp, surfT, Cw, act_coeff, R_gas, NA, diff_vol,
        Dstar_org
    ] = partit_var_prep.prep(y_mw, temp[0], num_comp, 0, Cw, act_comp,
                             act_user, accom_comp, accom_coeff_user,
                             comp_namelist, num_sb, num_sb, Pnow,
                             Pybel_objects, comp_smil)

    # prepare particle phase and wall
    [
        y, N_perbin, x, Varr, Vbou, rad0, Vol0, rbou, MV, num_sb, nuc_comp,
        rbou00, ub_rad_amp, np_sum, C_p2w
    ] = pp_intro.pp_intro(y, num_comp, Pybel_objects, temp[0], H2Oi, mfp,
                          accom_coeff, y_mw, surfT, siz_str, num_sb, lowsize,
                          uppsize, pmode, pconc, pconct, nuc_comp, 0, std,
                          mean_rad, therm_sp, y_dens, Psat, core_diss, kw,
                          space_mode, seedVr, comp_namelist, act_coeff,
                          wall_on, partit_cutoff, Pnow, seedi)

    # solve problem
    for prog in ode_updater.ode_updater(
            update_stp, tot_time, save_step, y, rindx_g, pindx_g, rstoi_g,
            pstoi_g, nreac_g, nprod_g, jac_stoi_g, njac_g, jac_den_indx_g,
            jac_indx_g, RO2_indx, H2Oi, temp, tempt, Pnow, light_stat,
            light_time, daytime, lat, lon, af_path, dayOfYear, photo_path,
            Jlen, con_infl_C, nrec_steps, dydt_vst, siz_str, num_sb, num_comp,
            seedi, seed_name, seedVr, core_diss, Psat, mfp, therm_sp,
            accom_coeff, y_mw, surfT, R_gas, NA, y_dens, x, Varr, act_coeff,
            Cw, kw, Cfactor, tf, light_ad, y_arr_g, y_rind_g, uni_y_rind_g,
            y_pind_g, uni_y_pind_g, reac_col_g, prod_col_g, rstoi_flat_g,
            pstoi_flat_g, rr_arr_g, rr_arr_p_g, rowvals, colptrs, wall_on,
            jac_wall_indx, jac_part_indx, Vbou, N_perbin, Vol0, rad0, np_sum,
            new_partr, nucv1, nucv2, nucv3, nuci, nuc_comp, nuc_ad, RH, RHt,
            coag_on, inflectDp, pwl_xpre, pwl_xpro, inflectk, ChamR, Rader,
            p_char, e_field, injectt, inj_indx, Ct, pmode, pconc, pconct,
            mean_rad, lowsize, uppsize, std, rbou, const_infl_t, MV, rindx_aq,
            pindx_aq, rstoi_aq, pstoi_aq, nreac_aq, nprod_aq, jac_stoi_aq,
            njac_aq, jac_den_indx_aq, jac_indx_aq, y_arr_aq, y_rind_aq,
            uni_y_rind_aq, y_pind_aq, uni_y_pind_aq, reac_col_aq, prod_col_aq,
            rstoi_flat_aq, pstoi_flat_aq, rr_arr_aq, rr_arr_p_aq, eqn_num,
            partit_cutoff, diff_vol, Dstar_org, corei, ser_H2O, C_p2w,
            sch_name, sav_nam, comp_namelist, dydt_trak, space_mode, rbou00,
            ub_rad_amp, indx_plot, comp0, inname, rel_SMILES, Psat_Pa_rec, OC,
            wat_hist, Pybel_objects):

        yield prog  # update progress bar

    return ()