Пример #1
0
def alpha_constrain_err(err, d0, d1, d2, d3, valid=True, debug=False):
    N = len(d0)
    zeros = np.zeros(N)

    d0 = np.min([d0, zeros], axis=0)
    del_0 = np.abs(d0*100)

    d1 = np.max([d1, zeros], axis=0)
    del_1 = np.abs(d1*1000)

    d2 = np.min([d2, zeros], axis=0)
    del_2 = np.abs(d2*5000)

    d3 = np.max([d3, zeros], axis=0)
    del_3 = np.abs(d3*500000000)

    tot = np.sum(del_0) + np.sum(del_1) + np.sum(del_2) + np.sum(del_3)
    if tot == 0 and not valid:
#        if not Twu91_check_params(params):
        del_0 = 1e5*np.ones(N)

    if debug:
        tot = np.sum(err) + tot
        print(tot, err, del_0, del_1, del_2, del_3)

    err += del_0
    err += del_1
    err += del_2
    err += del_3
    return err
Пример #2
0
def regular_solution_gammas_binaries_jac(xs,
                                         Vs,
                                         SPs,
                                         Ts,
                                         lambda12,
                                         lambda21,
                                         jac=None):
    if lambda12 < MIN_LAMBDA_REGULAR_SOLUTION:
        lambda12 = MIN_LAMBDA_REGULAR_SOLUTION
    if lambda21 < MIN_LAMBDA_REGULAR_SOLUTION:
        lambda21 = MIN_LAMBDA_REGULAR_SOLUTION
    if lambda12 > MAX_LAMBDA_REGULAR_SOLUTION:
        lambda12 = MAX_LAMBDA_REGULAR_SOLUTION
    if lambda21 > MAX_LAMBDA_REGULAR_SOLUTION:
        lambda21 = MAX_LAMBDA_REGULAR_SOLUTION
    pts = len(xs) // 2  # Always even

    if jac is None:
        allocate_size = (pts * 2)
        jac = np.zeros((allocate_size, 2))

    l01, l10 = lambda12, lambda21
    SP0, SP1 = SPs
    V0, V1 = Vs

    x2 = SP0 * SP1
    c99 = (SP0 - SP1)
    c100 = (l01 * x2 + l10 * x2 + c99 * c99)
    c101 = V0 * V1 * V1
    c102 = V0 * V0 * V1

    for i in range(pts):
        i2 = i * 2
        x0 = xs[i2]
        x1 = 1.0 - x0
        T = Ts[i]

        c0 = (V0 * x0 + V1 * x1)

        x3 = R_inv / (T * c0 * c0)
        x4 = x3 * c100
        x5 = c101 * x1 * x1
        x6 = x2 * x3
        x7 = x5 * x6 * trunc_exp(x4 * x5)
        x8 = c102 * x0 * x0
        x9 = x6 * x8 * trunc_exp(x4 * x8)

        jac[i2][0] = x7
        jac[i2][1] = x7
        jac[i2 + 1][0] = x9
        jac[i2 + 1][1] = x9
    return jac
Пример #3
0
def test_diff():
    from fluids.numerics import diff

    test_arrs = [
        np.ones(10),
        np.zeros(10),
        np.arange(1, 10),
        np.arange(1, 10) * 25.1241251, (np.arange(1, 10)**1.2),
        (10.1 + np.arange(1, 10)**20), (10.1 + np.linspace(-100, -10, 9)),
        (np.logspace(-10, -100, 19)**1.241), (np.logspace(10, 100, 15)**1.241)
    ]
    for test_arr in test_arrs:
        arr = test_arr.tolist()
        for n in range(5):
            diff_np = np.diff(arr, n=n)
            diff_py = diff(arr, n=n)
            assert_allclose(diff_np, diff_py)

    assert tuple(diff([1, 2, 3], n=0)) == tuple([1, 2, 3])
    with pytest.raises(Exception):
        diff([1, 2, 3], n=-1)