Skip to content

Commit

Permalink
Merge branch 'nov20' of github.com:bjodah/chempy into nov20
Browse files Browse the repository at this point in the history
  • Loading branch information
bjodah committed Jan 15, 2025
2 parents 68bf7b0 + 5acc04b commit f109677
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions chempy/kinetics/rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ def heaviside(x, z):
elif hasattr(backend, 'clip'): # e.g. numpy
def heaviside(x, z):
assert z == 0
lx = backend.log(backend.maximum(x, tiny))
xclp = be.clip(lx, lo, hi)
lx = backend.log(backend.maximum(backend.array(x), tiny))
xclp = backend.clip(lx, lo, hi)
x = (xclp - lo)/(hi - lo)
y = (3 - 2*x)*x*x
return y
else:
Expand Down
4 changes: 2 additions & 2 deletions chempy/kinetics/tests/test__rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def test_Log10TPolyMassAction__units():
p = MassAction(Constant(kunit)*10**ShiftedTPoly([273.15*u.K, .7, .02/u.K, .003/u.K**2, .0004/u.K**3]))
r = Reaction({'A': 2, 'B': 1}, {'C': 1}, p, {'B': 1})
res = p({'A': 11*u.molar, 'B': 13*u.molar, 'temperature': 298.15*u.K}, reaction=r)
ref = 10**(.7 + .02*25 + 0.003 * 25**2 + 0.0004 * 25**3)
assert abs(res - ref*13*11**2*Mps) < 1e-15
ref = 10**(.7 + .02*25 + 0.003 * 25**2 + 0.0004 * 25**3)*13*11**2*Mps
assert abs((res - ref)/ref) < 1e-15


def test_TPolyInLog10MassAction():
Expand Down
4 changes: 2 additions & 2 deletions chempy/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_to_unitless():
sy.exp(Ea_over_RT_uncert)

T_K_sym = np.array(sy.Symbol('T_K', real=True), dtype=object) * u.K
to_unitless(T_K_sym/(298*u.K))
assert to_unitless(T_K_sym/(298*u.K)).tolist() == [sy.Symbol('T_K', real=True)]
rescale(simplified(Ea/dc.molar_gas_constant)/T_K_sym, 1)
Ea_over_R_uncert = UncertainQuantity(Ea, unit_of(Ea), 0.1*Ea)/dc.molar_gas_constant
to_unitless(Ea_over_R_uncert/(298*u.K))
Expand All @@ -223,7 +223,7 @@ def test_UncertainQuantity():
a = UncertainQuantity([1, 2], u.m, [.1, .2])
assert a[1] == [2.]*u.m
assert (-a)[0] == [-1.]*u.m
assert (-a).uncertainty[0] == [0.1]*u.m
assert allclose((-a).uncertainty[0], [0.1]*u.m)
assert (-a)[0] == (a*-1)[0]
assert (-a).uncertainty[0] == (a*-1).uncertainty[0]
assert allclose(a, [1, 2]*u.m)
Expand Down

0 comments on commit f109677

Please sign in to comment.