From 7c496e648c7892b875897e7986c0b5bf249cc274 Mon Sep 17 00:00:00 2001 From: Ferran Brosa Planella Date: Thu, 4 Nov 2021 14:34:22 +0000 Subject: [PATCH 1/3] #1785 override sympy operators exp and atan --- pybamm/expression_tree/functions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pybamm/expression_tree/functions.py b/pybamm/expression_tree/functions.py index ebe2cfd356..59b05b5170 100644 --- a/pybamm/expression_tree/functions.py +++ b/pybamm/expression_tree/functions.py @@ -321,6 +321,10 @@ def _function_diff(self, children, idx): """See :meth:`pybamm.Function._function_diff()`.""" return 1 / (children[0] ** 2 + 1) + def _sympy_operator(self, child): + """Override :meth:`pybamm.Function._sympy_operator`""" + return sympy.atan(child) + def arctan(child): """Returns hyperbolic tan function of child.""" @@ -390,6 +394,10 @@ def _function_diff(self, children, idx): """See :meth:`pybamm.Function._function_diff()`.""" return Exponential(children[0]) + def _sympy_operator(self, child): + """Override :meth:`pybamm.Function._sympy_operator`""" + return sympy.exp(child) + def exp(child): """Returns exponential function of child.""" From ecd20ead891ae68615e949053fba17f2aad1fffa Mon Sep 17 00:00:00 2001 From: Ferran Brosa Planella Date: Fri, 5 Nov 2021 11:18:28 +0000 Subject: [PATCH 2/3] #1785 add tests --- tests/unit/test_expression_tree/test_functions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/test_expression_tree/test_functions.py b/tests/unit/test_expression_tree/test_functions.py index ffbe514f20..5c7f5bba95 100644 --- a/tests/unit/test_expression_tree/test_functions.py +++ b/tests/unit/test_expression_tree/test_functions.py @@ -140,6 +140,12 @@ def test_to_equation(self): # Test Arcsinh self.assertEqual(pybamm.Arcsinh(a).to_equation(), sympy.asinh(a)) + # Test Arctan + self.assertEqual(pybamm.Arctan(a).to_equation(), sympy.atan(a)) + + # Test Exponential + self.assertEqual(pybamm.Exponential(a).to_equation(), sympy.exp(a)) + # Test log self.assertEqual(pybamm.Log(54.0).to_equation(), sympy.log(54.0)) From e7d1005f2392b7c623fed341425395f6a49a70a5 Mon Sep 17 00:00:00 2001 From: Ferran Brosa Planella Date: Fri, 5 Nov 2021 11:18:49 +0000 Subject: [PATCH 3/3] #1785 update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73d03dc9f1..a60c8c50f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# [Unreleased](https://github.com/pybamm-team/PyBaMM/) + +## Bug fixes + +- Fixed `sympy` operators for `Arctan` and `Exponential` ([#1786](https://github.com/pybamm-team/PyBaMM/pull/1786)) + # [v21.10](https://github.com/pybamm-team/PyBaMM/tree/v21.9) - 2021-10-31 ## Features