예제 #1
0
def test_local_constant_method():
    # Test user defined method
    
    # Within valid T range
    obj = TDependentProperty(extrapolation='linear')
    constant = 100.
    T1 = T = 300.
    T2 = 310.
    dT = T2 - T1
    obj.add_method(constant)
    assert_close(obj.T_dependent_property(T), constant)
    for order in (1, 2, 3):
        assert_close(obj.T_dependent_property_derivative(T, order), 0.)
    assert_close(obj.T_dependent_property_integral(T1, T2), constant * dT)
    assert_close(obj.T_dependent_property_integral_over_T(T1, T2), constant * log(T2 / T1))
    
    # Extrapolate
    Tmin = 350.
    Tmax = 400.
    obj.add_method(constant, Tmin, Tmax)
    obj.extrapolation = 'constant'
    assert_close(obj.T_dependent_property(T), constant)
    for order in (1, 2, 3):
        assert_close(obj.T_dependent_property_derivative(T, order), 0., atol=1e-6)
    assert_close(obj.T_dependent_property_integral(T1, T2), constant * dT)
    assert_close(obj.T_dependent_property_integral_over_T(T1, T2), constant * log(T2 / T1))
    
    # Test extrapolation on both sides
    assert_close(obj.T_dependent_property_integral(Tmin - 50, Tmax + 50), constant * (100 + Tmax - Tmin))
    assert_close(obj.T_dependent_property_integral_over_T(Tmin - 50, Tmax + 50), constant * log((Tmax + 50) / (Tmin - 50)))
    
    # Do not allow extrapolation
    obj.extrapolation = None
    obj.add_method(constant, Tmin, Tmax)
    assert obj.T_dependent_property(T) is None
예제 #2
0
def test_local_method():
    # Test user defined method
    
    # Within valid T range
    obj = TDependentProperty(extrapolation='linear')
    T = 300.
    Tmin = 200.
    Tmax = 400.
    T1 = 300.
    T2 = 310.
    dT = T2 - T1
    f = lambda T: T*T / 1e6
    f_der = lambda T: T / 1e6
    f_der2 = lambda T: 1. / 1e6
    f_der3 = lambda T: 0. / 1e6
    f_int = lambda T1, T2: (T2*T2*T2 - T1*T1*T1) / 3. / 1e6
    f_int_over_T = lambda T1, T2: (T2*T2 - T1*T1) / 2. / 1e6
    obj.add_method(f, Tmin, Tmax, f_der, f_der2, f_der3, f_int, f_int_over_T)
    assert_close(obj.T_dependent_property(T), f(T))
    assert_close(obj.T_dependent_property_derivative(T, 1), f_der(T))
    assert_close(obj.T_dependent_property_derivative(T, 2), f_der2(T))
    assert_close(obj.T_dependent_property_derivative(T, 3), f_der3(T))
    assert_close(obj.T_dependent_property_integral(T1, T2), f_int(T1, T2))
    assert_close(obj.T_dependent_property_integral_over_T(T1, T2), f_int_over_T(T1, T2))
    
    # Extrapolate
    Tmin = 300. + 1e-3
    obj.add_method(f, Tmin, Tmax)
    # obj.RAISE_PROPERTY_CALCULATION_ERROR = True
    # obj.CASRN = 'CASRN'
    assert_close(obj.T_dependent_property(T), f(T))
    for order in (1, 2, 3):
        assert obj.T_dependent_property_derivative(T, order) is not None
    assert_close(obj.T_dependent_property_integral(T1, T2), f_int(T1, T2))
    assert_close(obj.T_dependent_property_integral_over_T(T1, T2), f_int_over_T(T1, T2))
    
    # Do not allow extrapolation
    obj.extrapolation = None
    obj.add_method(f, Tmin, Tmax)
    assert obj.T_dependent_property(T) is None
    assert obj.T_dependent_property_integral(T1, T2) is None
    assert obj.T_dependent_property_integral_over_T(T1, T2) is None
예제 #3
0
def test_derivative():
    obj = TDependentProperty(extrapolation='linear')
    Tmin = 300
    Tmax = 400
    f = lambda T: T*T*T
    f_der = lambda T: 3*T*T
    f_der2 = lambda T: 6*T
    f_der3 = lambda T: 6
    obj.add_method(f=f, f_der=f_der, f_der2=f_der2, f_der3=f_der3, Tmin=Tmin, Tmax=Tmax)
    
    
    T_in_range = (Tmin + Tmax) * 0.5
    for order, fun in zip([1,2,3], [f_der, f_der2, f_der3]):
        # Within valid T range
        assert_close(obj.T_dependent_property_derivative(T_in_range, order=order), fun(T_in_range))
    
    # Extrapolate left
    T = Tmin - 50
    obj.RAISE_PROPERTY_CALCULATION_ERROR = True
    assert_close(obj.T_dependent_property_derivative(T, order=1), f_der(Tmin))
    
    # Extrapolate right
    T = Tmax + 50
    assert_close(obj.T_dependent_property_derivative(T, order=1), f_der(Tmax))