def test_equilibrium_thermochemical_error_computes_correct_probability( datasets_db): """Integration test for equilibrium thermochemical error.""" datasets_db.insert(CU_MG_EQ_HMR_LIQUID) dbf = Database(CU_MG_TDB) phases = list(dbf.phases.keys()) # Test that errors update in response to changing parameters # no parameters eqdata = get_equilibrium_thermochemical_data(dbf, ['CU', 'MG'], phases, datasets_db) errors, weights = calc_prop_differences(eqdata[0], np.array([])) expected_vals = [-31626.6 * 0.5 * 0.5] assert np.all(np.isclose(errors, expected_vals)) # VV0017 (LIQUID, L0) eqdata = get_equilibrium_thermochemical_data( dbf, ['CU', 'MG'], phases, datasets_db, parameters={'VV0017': -31626.6}) # unchanged, should be the same as before errors, weights = calc_prop_differences(eqdata[0], np.array([-31626.6])) assert np.all(np.isclose(errors, [-31626.6 * 0.5 * 0.5])) # change to -40000 errors, weights = calc_prop_differences(eqdata[0], np.array([-40000], np.float_)) assert np.all(np.isclose(errors, [-40000 * 0.5 * 0.5]))
def test_equilibrium_thermochemcial_error_species(datasets_db): """Test species work for equilibrium thermochemical data.""" datasets_db.insert(LI_SN_LIQUID_EQ_DATA) dbf = Database(LI_SN_TDB) phases = list(dbf.phases.keys()) eqdata = get_equilibrium_thermochemical_data(dbf, ['LI', 'SN'], phases, datasets_db) # Thermo-Calc truth_values = np.array([0.0, -28133.588, -40049.995, 0.0]) # Approximate errors_approximate, weights = calc_prop_differences(eqdata[0], np.array([]), True) # Looser tolerances because the equilibrium is approximate, note that this is pdens dependent assert np.all(np.isclose(errors_approximate, truth_values, atol=1e-5, rtol=1e-3)) # Exact errors_exact, weights = calc_prop_differences(eqdata[0], np.array([]), False) assert np.all(np.isclose(errors_exact, truth_values, atol=1e-5))
def test_equilibrium_thermochemical_error_unsupported_property(datasets_db): """Test that an equilibrium property that is not explictly supported will work.""" # This test specifically tests Curie temperature datasets_db.insert(CR_NI_LIQUID_EQ_TC_DATA) EXPECTED_VALUES = np.array([374.6625, 0.0, 0.0]) # the TC should be 374.6625 in both cases, but "values" are [0 and 382.0214], so the differences should be flipped. dbf = Database(CR_NI_TDB) phases = list(dbf.phases.keys()) eqdata = get_equilibrium_thermochemical_data(dbf, ['CR', 'NI'], phases, datasets_db) errors_exact, weights = calc_prop_differences(eqdata[0], np.array([])) assert np.all(np.isclose(errors_exact, EXPECTED_VALUES, atol=1e-3))