Beispiel #1
0
def test_CDSD_calc_vs_tab(verbose=True, warnings=True, *args, **kwargs):
    """ Test 1: compare calculated PartFunc to the tabulated one """

    from radis.misc.config import getDatabankEntries

    iso = 1
    database = "CDSD-HITEMP-PC"

    # Compare tab to hardcoded
    parfunc = getDatabankEntries(database)["parfunc"]
    Qf = PartFuncCO2_CDSDtab(iso, parfunc)
    assert np.isclose(Qf.at(300), 291.0447781984652, rtol=0.001)
    assert np.isclose(Qf.at(3000), 114689.88454184022, rtol=0.001)

    if verbose:
        printm("Tested CDSD tabulated is correct: OK")

    # Compare tab to calculated
    energies = getDatabankEntries(database)["levels"]
    levelsfmt = getDatabankEntries(database)["levelsfmt"]
    Qfc = PartFuncCO2_CDSDcalc(energies[iso],
                               levelsfmt=levelsfmt,
                               isotope=iso,
                               use_cached=True)
    assert np.isclose(Qf.at(300), Qfc.at(300), rtol=0.001)
    assert np.isclose(Qf.at(3000), Qfc.at(3000), rtol=0.001)

    if verbose:
        printm("Tested CDSD Q_calc vs Q_tab give same output: OK")

    return True
Beispiel #2
0
def test_CDSD_calc_vs_ref(warnings=True, verbose=True, *args, **kwargs):
    """Test partition functions calculated with CDSD energy levels against
    hardcoded values"""

    from radis.misc.config import getDatabankEntries

    iso = 1

    energies = getDatabankEntries("CDSD-HITEMP-PC")["levels"]
    levelsfmt = getDatabankEntries("CDSD-HITEMP-PC")["levelsfmt"]
    Qf = PartFuncCO2_CDSDcalc(
        energy_levels=energies[iso],
        isotope=iso,
        use_cached=True,
        levelsfmt=levelsfmt,
    )
    assert np.isclose(Qf.at(300), 291.0447781984652, rtol=0.001)
    assert np.isclose(Qf.at(3000), 114689.88454184022, rtol=0.001)
    assert np.isclose(Qf.at_noneq(300, 300), 291.0447781984652, rtol=0.001)
    assert np.isclose(Qf.at_noneq(3000, 3000), 114689.88454184022, rtol=0.001)
    assert np.isclose(
        Qf.at_noneq(3000,
                    3000,
                    overpopulation={"(0,1)": 3},
                    returnQvibQrot=True)[0],
        120053.34252537244,
        rtol=0.001,
    )

    if verbose:
        printm("Tested Q_CDSD values are correct : OK")
Beispiel #3
0
def test_CDSD_calc_vs_ref(warnings=True, verbose=True, *args, **kwargs):
    ''' Test partition functions calculated with CDSD energy levels against 
    hardcoded values '''

    from radis.misc.config import getDatabankEntries

    iso = 1

    try:
        energies = getDatabankEntries('CDSD-HITEMP-PC')['levels']
        levelsfmt = getDatabankEntries('CDSD-HITEMP-PC')['levelsfmt']
        Qf = PartFuncCO2_CDSDcalc(energy_levels=energies[iso],
                                  isotope=iso,
                                  use_cached=True,
                                  levelsfmt=levelsfmt)
        assert np.isclose(Qf.at(300), 291.0447781984652, rtol=0.001)
        assert np.isclose(Qf.at(3000), 114689.88454184022, rtol=0.001)
        assert np.isclose(Qf.at_noneq(300, 300), 291.0447781984652, rtol=0.001)
        assert np.isclose(Qf.at_noneq(3000, 3000),
                          114689.88454184022,
                          rtol=0.001)
        assert np.isclose(Qf.at_noneq(3000,
                                      3000,
                                      overpopulation={'(0,1)': 3},
                                      returnQvibQrot=True)[0],
                          120053.34252537244,
                          rtol=0.001)

        if verbose:
            printm('Tested Q_CDSD values are correct : OK')

        return True

    except DatabankNotFound as err:
        assert IgnoreMissingDatabase(err, __file__, warnings)
Beispiel #4
0
def test_reduced_CDSD_calc_noneq(verbose=True, warnings=True, *args, **kwargs):
    """ Compare calculated partition function at equilibrium and nonequilibrium
    using the CDSD-format """

    from radis.misc.config import getDatabankEntries

    iso = 1
    database = "HITEMP-CO2-HAMIL-TEST"

    # Compare tab to calculated
    energies = getDatabankEntries(database)["levels"]
    levelsfmt = getDatabankEntries(database)["levelsfmt"]
    Qfc = PartFuncCO2_CDSDcalc(
        energies[iso],
        levelsfmt=levelsfmt,
        isotope=iso,
        use_cached=True,
        verbose=verbose,
    )
    assert np.isclose(Qfc.at(300),
                      Qfc.at_noneq_3Tvib((300, 300, 300), 300),
                      rtol=0.001)

    if verbose:
        printm(
            "Tested CDSD Q_calc at equilibrium and nonequilibrium give same output: OK"
        )
Beispiel #5
0
def test_CDSD_calc_vs_tab(verbose=True, warnings=True, *args, **kwargs):
    ''' Test 1: compare calculated PartFunc to the tabulated one '''

    from radis.misc.config import getDatabankEntries

    try:

        iso = 1
        database = 'CDSD-HITEMP-PC'
        
        # Compare tab to hardcoded
        parfunc = getDatabankEntries(database)['parfunc']
        Qf = PartFuncCO2_CDSDtab(iso, parfunc)
        assert np.isclose(Qf.at(300), 291.0447781984652, rtol=0.001)
        assert np.isclose(Qf.at(3000), 114689.88454184022, rtol=0.001)

        if verbose:
            printm('Tested CDSD tabulated is correct: OK')

        # Compare tab to calculated
        energies = getDatabankEntries(database)['levels']
        levelsfmt = getDatabankEntries(database)['levelsfmt']
        Qfc = PartFuncCO2_CDSDcalc(energies[iso], levelsfmt=levelsfmt, isotope=iso, use_cached=True)
        assert np.isclose(Qf.at(300), Qfc.at(300), rtol=0.001)
        assert np.isclose(Qf.at(3000), Qfc.at(3000), rtol=0.001)

        if verbose:
            printm('Tested CDSD Q_calc vs Q_tab give same output: OK')

        return True

    except DatabankNotFound as err:
        assert IgnoreMissingDatabase(err, __file__, warnings)
Beispiel #6
0
def test_recompute_Q_from_QvibQrot_CDSD_PC(verbose=True,
                                           warnings=True,
                                           *args,
                                           **kwargs):
    ''' 
    Calculate vibrational and rotational partition functions:
        
    - in CDSD with (p,c) convention for vibrational levels 
    - under nonequilibrium
    
    Recompute total partition function, and compare

    Test if partition function can be recomputed correctly from vibrational
    populations and rotational partition function (note that we are in a coupled
    case so partition function is not simply the product of Qvib, Qrot) 
    '''

    from radis.misc.config import getDatabankEntries

    iso = 1

    try:
        energies = getDatabankEntries('CDSD-HITEMP-PC')['levels']
        levelsfmt = getDatabankEntries('CDSD-HITEMP-PC')['levelsfmt']

        Tvib = 1500
        Trot = 300

        Qf = PartFuncCO2_CDSDcalc(energies[iso],
                                  isotope=iso,
                                  use_cached=True,
                                  levelsfmt=levelsfmt)
        Q = Qf.at_noneq(Tvib, Trot)
        _, Qvib, dfQrot = Qf.at_noneq(Tvib, Trot, returnQvibQrot=True)
        if verbose:
            printm('Q', Q)
        if verbose:
            printm('Qvib', Qvib)

        # 1) Test Q vs Q recomputed from Qrot, Qvib

        # Recompute Qtot
        df = dfQrot
        Q2 = ((df.gvib * exp(-df.Evib * hc_k / Tvib)) * df.Qrot).sum()
        # Todo: non Boltzmann case

        assert np.isclose(Q, Q2)

        if verbose:
            printm('Tested Q vs recomputed from (Qvib, Qrot) are the same: OK')

        return True

    except DatabankNotFound as err:
        assert IgnoreMissingDatabase(err, __file__, warnings)
Beispiel #7
0
def test_reduced_CDSD_calc_noneq(verbose=True, warnings=True, *args, **kwargs):
    """Compare calculated partition function at equilibrium and nonequilibrium
    using the CDSD-format

    Examples
    --------

        assert Qfc.at(300) != Qfc.at_noneq_3Tvib((300, 300, 300), 300)

    After redefining Evib so that Evib + Erot = E:

        assert np.isclose(Qfc.at(300), Qfc.at_noneq(300, 300), rtol=0.001)
        assert np.isclose(Qfc.at(300), Qfc.at_noneq_3Tvib((300, 300, 300), 300), rtol=0.001)
    """

    from radis.misc.config import getDatabankEntries
    from radis.test.utils import define_Evib_as_sum_of_Evibi

    iso = 1
    database = "HITEMP-CO2-HAMIL-TEST"

    # Compare tab to calculated
    energies = getDatabankEntries(database)["levels"]
    levelsfmt = getDatabankEntries(database)["levelsfmt"]
    Qfc = PartFuncCO2_CDSDcalc(
        energies[iso],
        levelsfmt=levelsfmt,
        isotope=iso,
        use_cached=True,
        verbose=verbose,
    )

    # Note that partition functions are not equal because some of the energy
    # goes in coupling terms in the Hamiltonian formulation
    assert Qfc.at(300) != Qfc.at_noneq_3Tvib((300, 300, 300), 300)

    # Below we redefine Evib so that Evib + Erot = E
    define_Evib_as_sum_of_Evibi(Qfc.df)

    # New Test:
    assert np.isclose(Qfc.at(300), Qfc.at_noneq(300, 300), rtol=0.001)
    assert np.isclose(Qfc.at(300),
                      Qfc.at_noneq_3Tvib((300, 300, 300), 300),
                      rtol=0.001)
Beispiel #8
0
def test_reduced_CDSD_calc_vs_tab(verbose=True,
                                  warnings=True,
                                  *args,
                                  **kwargs):
    """Test 1: compare calculated PartFunc to the tabulated one

    Version where we use the reduced set of CO2 levels (< 3000 cm-1)"""
    from radis.misc.config import getDatabankEntries

    iso = 1
    database = "HITEMP-CO2-HAMIL-TEST"

    # Compare tab to hardcoded
    parfunc = getDatabankEntries(database)["parfunc"]
    Qf = PartFuncCO2_CDSDtab(iso, parfunc)
    assert np.isclose(Qf.at(300), 291.0447781984652, rtol=0.001)
    assert np.isclose(Qf.at(3000), 114689.88454184022, rtol=0.001)

    if verbose:
        printm("Tested CDSD tabulated is correct: OK")

    # Compare tab to calculated
    energies = getDatabankEntries(database)["levels"]
    levelsfmt = getDatabankEntries(database)["levelsfmt"]
    Qfc = PartFuncCO2_CDSDcalc(
        energies[iso],
        levelsfmt=levelsfmt,
        isotope=iso,
        use_cached=True,
        verbose=verbose,
    )
    assert np.isclose(
        Qf.at(300), Qfc.at(300), rtol=0.01
    )  # reduced rtol to accommodate for the reduced set of levels in the test set
    # assert np.isclose(Qf.at(3000), Qfc.at(3000), rtol=0.001)  # of course doesnt work with the reduced set of levels in the test set

    if verbose:
        printm("Tested CDSD Q_calc vs Q_tab give same output: OK")