def test_GibbsEqConst__units(): R, T = dc.molar_gas_constant, 298.15 * du.K DH = -4e3 * du.J / du.mol DS = 16 * du.J / du.K / du.mol be = Backend() gee = GibbsEqConst([DH / R, DS / R]) res = gee.eq_const({'temperature': T}, backend=be) ref = be.exp(-(DH - T * DS) / (R * T)) assert allclose(res, ref)
def test_GibbsEquilibriumConstant__units(): R, T = dc.molar_gas_constant, 298.15*du.K DH = -4e3 * du.J/du.mol DS = 16 * du.J/du.K/du.mol be = Backend() gee = GibbsEquilibriumConstant([DH/R, DS/R]) res = gee({'temperature': T}, backend=be) ref = be.exp(-(DH - T*DS)/(R*T)) assert allclose(res, ref)
def test_GibbsEquilibriumConstant__nested(): class TExpr(Expr): argument_names = ('heat_capacity',) parameter_keys = ('energy',) def __call__(self, variables, backend=None): heat_capacity, = self.all_args(variables, backend=backend) energy, = self.all_params(variables, backend=backend) return energy/heat_capacity R = 8.314 * du.J/du.K/du.mol T = TExpr([10.0 * du.J/du.K]) dH, dS = -4e3 * du.J/du.mol, 16 * du.J/du.K/du.mol gee = GibbsEquilibriumConstant([dH/R, dS/R]) be = Backend() Tref = 298.15 * du.K ref = be.exp(-(dH - Tref*dS)/(R*Tref)) assert be.abs((gee({'energy': 2981.5 * du.J, 'temperature': T}, backend=be) - ref)/ref) < 1e-14
def test_GibbsEqConst__nested(): class TExpr(Expr): argument_names = ('heat_capacity',) parameter_keys = ('energy',) def __call__(self, variables, backend=None): heat_capacity, = self.all_args(variables, backend=backend) energy, = self.all_params(variables, backend=backend) return energy/heat_capacity R = 8.314 * du.J/du.K/du.mol T = TExpr([10.0 * du.J/du.K]) dH, dS = -4e3 * du.J/du.mol, 16 * du.J/du.K/du.mol gee = GibbsEqConst([dH/R, dS/R]) be = Backend() Tref = 298.15 * du.K ref = be.exp(-(dH - Tref*dS)/(R*Tref)) assert be.abs((gee.eq_const({'energy': 2981.5 * du.J, 'temperature': T}, backend=be) - ref)/ref) < 1e-14