示例#1
0
def test_Ma_1():
    """Check inversion for values near Ma = 1."""
    dMa = 0.0001
    Ma_fw = np.array([-dMa, 0., dMa]) + 1.
    for v in var_test_sup:
        Y_fw = cf.from_Ma( v, Ma_fw, ga)
        Ma_bk = cf.to_Ma( v, Y_fw, ga)
        if v in ['mcpTo_APo','A_Acrit']:
            Ma_bk[-1] = cf.to_Ma( v, Y_fw[-1], ga, True)
        err = Ma_fw-Ma_bk
        print(v, err)
        assert np.all(np.abs(err[~np.isnan(Ma_bk)])<1e-5)
示例#2
0
def test_inverse_sub():
    """Compare Ma lookup values to CUED Data Book, subsonic."""
    for v in var_test_sub:
        for _ in range(Nrep):
            X = cf.to_Ma(v, dat_sub[v], ga)
        err_sub = np.abs(X - dat_sub['Ma'])
        imax = np.argmax(err_sub)
        assert err_sub[imax] <= 0.01, \
            "{0}={1} =>  Ma={2} with error={3}".format(
                v, dat_sub[v][imax], X[imax], err_sub[imax])
示例#3
0
def test_Ma_0():
    """Check expected values for Ma = 0."""
    val0 = np.array([1., 1., 1., 0., 0., 0., np.nan, np.nan])
    Y0 = {var_test_sup[i]: val0[i] for i in range(len(var_test_sup))}
    for v in var_test_sup:
        print(v, Y0[v], cf.from_Ma( v, np.atleast_1d(0.), ga))
        assert np.isclose( cf.from_Ma( v, np.atleast_1d(0.), ga), Y0[v],
                           atol=1e-7, equal_nan=True)
        if np.isfinite(Y0[v]):
            assert np.isclose( cf.to_Ma( v, np.atleast_1d(Y0[v]), ga), 0.0,
                                atol=1e-7, equal_nan=True)
示例#4
0
    a.set_title('Benchmark evaluation of $\dot{m}\sqrt{c_pT_0}/Ap_0$')
    a.legend()
    a.set_xlim((1, 1e5))
    a.set_ylim((1e-7, 1e-2))
    a.set_xticks(tick_marks)
    f.tight_layout(pad=0.1)
    plt.savefig('bench_forward.png', dpi=250)

    speedup = np.array(dt_fort) / np.array(dt_native)
    print('Fortran speedup: ', 1. / speedup[(0, -1), ])

    # FORWARD EVALUATION
    print('Benchmarking inversion...')

    # Initialise lookup table
    cf.to_Ma('mcpTo_APo', 0.4, ga, use_lookup=True)

    # Loop over array sizes
    dt_native = []
    dt_fort = []
    dt_lookup = []
    for Ni in N:

        X = np.random.rand(Ni) * (Xmax - Xmin) + Xmin

        # Set up timers
        T_fort = timeit.Timer('cf.Ma_from_mcpTo_APo(X,ga)',
                              'from __main__ import X,ga,cf')
        T_native = timeit.Timer('cf.native.Ma_from_mcpTo_APo(X,ga)',
                                'from __main__ import X,ga,cf')
        T_lookup = timeit.Timer('cf.to_Ma("mcpTo_APo",X,ga,use_lookup=True)',